Skip to content

Add support for three-part column references - #265

Open
malensek wants to merge 4 commits into
hyrise:mainfrom
malensek:main
Open

malensek wants to merge 4 commits into
hyrise:mainfrom
malensek:main

Conversation

@malensek

Copy link
Copy Markdown

This adds support for three-part column references:

SELECT schema.table.column FROM table;

So something like SELECT catalog.students.grade FROM students; will populate the schema field in Expr:

expr->schema = "catalog";
expr->table = "students";
expr->name = "grade";

The changes are fairly light:

  • Added a grammar entry for IDENTIFIER '.' IDENTIFIER '.' IDENTIFIER
  • Added Expr::makeColumnRef(char* schema, char* table, char* name)
  • Added a test case covering this scenario

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!

@dey4ss dey4ss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I have two small questions.

Comment thread src/parser/bison_parser.y Outdated

column_name : IDENTIFIER { $$ = Expr::makeColumnRef($1); }
| IDENTIFIER '.' IDENTIFIER { $$ = Expr::makeColumnRef($1, $3); }
| IDENTIFIER '.' IDENTIFIER '.' IDENTIFIER { $$ = Expr::makeColumnRef($1, $3, $5); }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/parser/bison_parser.y Outdated
| IDENTIFIER '.' IDENTIFIER { $$ = Expr::makeColumnRef($1, $3); }
| IDENTIFIER '.' IDENTIFIER '.' IDENTIFIER { $$ = Expr::makeColumnRef($1, $3, $5); }
| '*' { $$ = Expr::makeStar(); }
| IDENTIFIER '.' '*' { $$ = Expr::makeStar($1); };

@dey4ss dey4ss Jun 15, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency: I guess this does also apply to SELECT <table_name>.*. Can you add it here as well (with a test)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

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.
@malensek

Copy link
Copy Markdown
Author

Thanks a lot for reviewing this -- just updated the PR with the changes. Let me know if I can tweak this more.

aleks-f added a commit to pocoproject/poco that referenced this pull request Oct 29, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants