Add support for three-part column references#265
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. |
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!