Hi, I am looking at the issue: <https://github.com...
# daft-dev
v
Hi, I am looking at the issue: https://github.com/Eventual-Inc/Daft/issues/4179 I want to know what is the exact requirement for this issue? Is it for fixing the "TABLE" only keyword? or fixing all the FROM KEYWORD case? Looks like if we can distinguish the "FROM" keyword generated by the tokenizer and look for next non-whitespace token that matches the keyword "table". We shall be able to prevent such a case, but I am not sure if this is any corner case that can bypass this check.
m
Great question! What we're looking for on this issue is better error messages. The current error message is just plain wrong 😅 It's misleading and doesn't actually say the real problem. If you're taking a crack at this issue (🙏 ), then ideally we'd like to make sure that every case of referencing a Python value that isn't defined in the SQL query should result in an error message saying that the query can't be executed because it's referencing a value that doesn't exist (and, of course, saying the name of the thing that is referenced but doesn't exist 🙃)
For this one, it may just be that the underlying error is due to how Daft parses the SQL statement. Or it may just be a special case with the name
table
. I'm not actually sure off the top of my head. But, if you're pushing a PR for this fix, then it would be good to have unit tests added that check various
FROM xyz
forms to make sure that it works for more than just the
FROM table
case.
👍 1
v
Sure, will take a look today. thanks for the detailed response
For this issue, I think it is a special case for the keyword "TABLE". even if the following code
Copy code
table = daft.read_json("/path/to/json")
result = daft.sql("SELECT * FROM table")
will result in an error message
daft.exceptions.InvalidSQLException: failed to parse sql: sql parser error: Expected: (, found: EOF
After a little bit investigation it shows that the problem is inside
/src/daft-sql/src/planner.rs
, Which failed inside the `sqlparser:parser:Parser.parse_statements`(its a third party library) So I think ideally the SELECT FROM xyz case should behave: 1. If the expression cannot pass the Parser, and it contains FROM KEYWORD, throw an error message "KEYWORD is a SQL keyword, not a valid table name" 2. If the expression can pass the Parser, and the table is not exist, just throw "Table not found table_name" Now (2) is already implemented and acted correctly. I think we only need to fix the (1) case. So I will fix (1) and add
FROM xyz
unit tests for the patch. LMK if I have anything wrong.
✅ 1
m
That sounds like a good plan! 🫡
v
Hi @Malcolm Greaves I have made a fix which will prevent all the FROM KEYWORD combination. But I when I run the unit test, I found that there is one unit test failed because it used
SELECT * FROM data
which DATA is also a keyword in sql. (image attached) Previously the test can pass , but after the fix since "data" is also a keyword token, it will fail the test Then I tried all "SELECT * FROM keyword" combination with the original version of daft sql. I found that there are a lot of keywords that will return "table not found" which means it passed the parser For example : "SELECT FROM SELECT" will result in
sql: SELECT * FROM SELECT error: Table not found: SELECT
A full list can be found here: https://pastebin.com/5rMv3Twq Also I note that this is different with PGSQL or MySQL. So I will only check if it match the following case, then throw the error message
Copy code
sql: SELECT * FROM END_EXEC = "END-EXEC" error: failed to parse sql: sql parser error: Expected: end of statement, found: =
sql: SELECT * FROM LATERAL error: failed to parse sql: sql parser error: Expected: identifier, found: EOF
sql: SELECT * FROM TABLE error: failed to parse sql: sql parser error: Expected: (, found: EOF
sql: SELECT * FROM UNNEST error: failed to parse sql: sql parser error: Expected: (, found: EOF
I will submit the PR recently