-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Superset-generated time range causes SQL error: ParserError("Expected end of statement, found: 00") #11
Comments
@jdstrand I took a look and I'm not able to reproduce the issue on my side. I added some logging to print out the query handed to the DB API layer. Here's what my Superset UI shows: Here are the queries its producing:
The trailing You can see it has single-quoted the datetimes in my case. I've tried a few variants including the custom, relative and "advanced" ranges. What am I missing? |
Reproducer from within Superset:
Modifying step 8 to use 'No filter' makes it work again. Using 'Last', 'Previous' or 'Advanced' all causes the error. I also mimicked your use of custom with 'Start Relative Date/Time: 1 days before' and 'End: Now' to have the equivalent hover over in superset and still see the same behavior. Updating step 6 to use 'Time Series Bar', 'Time Series Line', or 'Time Series Table' all results in the same error. Wondering if it has something to do with the data here is an updated query on real data:
Clicking Run and downloading the CSV:
If I start with step '5' above, I can still reproduce (Metrics is COUNT(action) and Dimension is actor). Presumably, this could be imported as a table in a bucket/namespace you own. |
I'll review this today. Thanks for the thorough instructions. |
I was able to reproduce this issue as @jdstrand describes above. The difference between the way he entered the chart builder is that he's coming in via the SQL Lab. The SQL Lab flow allows you to build a query that can then be used as a virtual table (via a sub-select). Here's a screenshot comparing the output SQL for both cases: I'm unsure what the difference is in how SQLAlchemy is involved—or if it's using a completely different way of generating queries if querying via the virtual table. Looking into that now. |
Even weirder, @jdstrand: If you create a Dataset from the SQL Lab query and go through the same flow, you arrive at this: So if it's coming from a Dataset at all—whether it's the abstract table or a specific select statement—it is able to quote the dates correctly. However, if you come in from the SQL Lab and don't attempt to persist the query into a Dataset record, it doesn't single-quote them. |
Superset has the ability to set a time range in its Chart Graph functionality. When set, the resulting SQL has a WHERE clause of this form:
This results in:
executing query: failed to create Flight record reader: arrow/flight: could not create flight reader: arrow/ipc: could not read schema from stream: arrow/ipc: could not read message schema: rpc error: code = InvalidArgument desc = Error while planning query: SQL error: ParserError("Expected end of statement, found: 00")
.A simple reproducer that generates an error without superset is:
We can make the error go away if we quote the date strings:
https://arrow.apache.org/datafusion/user-guide/sql/select.html#where-clause is pretty lean on details, but AIUI, it is using
sqlparser
which is ANSI SQL:2011. I tried to find the grammar for that but apparently it is behind a paywall. Postgres is mostly ANSI SQL:2016 compliant and section 8.5.1.3 of https://www.postgresql.org/docs/15/datatype-datetime.html speaks ofTIMESTAMP '2004-10-19 10:23:54'
being a valid SQL standard timestamp.As such, this is likely most correct (ie,
flightsql-dbapi
likely should generate this form ofWHERE
):The text was updated successfully, but these errors were encountered: