Skip to content

Add support for three-part column references#265

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

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

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