Repository navigation
Conversation
This will allow providing a schema, e.g., SELECT schema.table.name
dey4ss
left a comment
There was a problem hiding this comment.
Thank you for your contribution! I have two small questions.
|
|
||
| column_name : IDENTIFIER { $$ = Expr::makeColumnRef($1); } | ||
| | IDENTIFIER '.' IDENTIFIER { $$ = Expr::makeColumnRef($1, $3); } | ||
| | IDENTIFIER '.' IDENTIFIER '.' IDENTIFIER { $$ = Expr::makeColumnRef($1, $3, $5); } |
There was a problem hiding this comment.
There already is a table_name definition. Can we just reuse it here, e.g., replace IDENTIFIER '.' IDENTIFIER {...} with table_name '.' IDENTIFIER {...} and use the already parsed schema and table name in the body?
There was a problem hiding this comment.
Oh, that is a good idea... Initially I tried this directly with table_name but it produced a conflict between table_name and column_name, but perhaps a new definition could be used in both places. Let me know if there a better way to do it... I'll update the PR in a bit.
| | IDENTIFIER '.' IDENTIFIER { $$ = Expr::makeColumnRef($1, $3); } | ||
| | IDENTIFIER '.' IDENTIFIER '.' IDENTIFIER { $$ = Expr::makeColumnRef($1, $3, $5); } | ||
| | '*' { $$ = Expr::makeStar(); } | ||
| | IDENTIFIER '.' '*' { $$ = Expr::makeStar($1); }; |
There was a problem hiding this comment.
For consistency: I guess this does also apply to SELECT <table_name>.*. Can you add it here as well (with a test)?
Added a more general qualified_name rule for schema-qualified references. This was also used to support schema-qualified star queries. Added a new three-part star select query test.
|
Thanks a lot for reviewing this -- just updated the PR with the changes. Let me know if I can tweak this more. |
…5605 (#5608) * chore(Data/SQLParser): port the open hyrise/sql-parser pull requests #5605 Ports hyrise/sql-parser#260 and hyrise/sql-parser#255 (interval types and field range literals; TIME and TIMESTAMP literals; CURRENT_DATE, CURRENT_TIME and CURRENT_TIMESTAMP), hyrise/sql-parser#265 (a three-part column reference fills the schema) and hyrise/sql-parser#248 (parenthesized query expressions in set operations, subqueries, IN, EXISTS and INSERT), adapted to the vendored grammar. Also: clauses and statements discarded by a parse error are released, CREATE INDEX keeps the schema of a qualified table, TOP keeps its row count with OFFSET alone or LIMIT ALL, the ColumnType operators are exported, and the parser objects are rebuilt when a header changes. * chore(Data): ASCII dashes in the SQLParser and Data test comments #5605 * fix(Data/SQLParser): set operations follow SQL precedence, and the interval range factory has its own name #5605 INTERSECT binds tighter than UNION and EXCEPT, which apply from left to right, and parentheses around a single SELECT change nothing; unparenthesized chains nested to the right, so EXCEPT chains and INTERSECT before UNION grouped unlike SQL. makeIntervalRangeLiteral takes the string value of a field range, which keeps makeIntervalLiteral(0, unit) unambiguous.
This adds support for three-part column references:
So something like
SELECT catalog.students.grade FROM students;will populate the schema field inExpr:The changes are fairly light:
IDENTIFIER '.' IDENTIFIER '.' IDENTIFIERExpr::makeColumnRef(char* schema, char* table, char* name)I have confirmed this passes the test suite and leak test on Linux 6.18.35-1-lts and test suite on macOS 26.5.1. I also see that the repo has the Bison output checked in so I did so as well for this PR, but please let me know if I should exclude it or need to run with the same version of Bison that was previously used to generate the files.
Thanks for this great library, it's very clean and easy to work with!