Repository navigation
Reject unquoted reserved keywords as table names - #2633
LucaCappelletti94 wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2633 +/- ##
==========================================
+ Coverage 81.28% 81.31% +0.03%
==========================================
Files 42 42
Lines 33920 33965 +45
Branches 33920 33965 +45
==========================================
+ Hits 27571 27619 +48
+ Misses 2785 2782 -3
Partials 3564 3564 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
dfa12e9 to
3365ebe
Compare
3365ebe to
27c1a46
Compare
| } else { | ||
| Keyword::NoKeyword | ||
| }; | ||
| if !self.dialect.is_table_factor(&peek_keyword, self) { |
There was a problem hiding this comment.
This calls is_table_factor before the keyword is consumed, while the trailing-comma caller in parse_table_with_joins calls it after next_token(). Snowflake's override peeks past the keyword for LIMIT <n> and TABLE(, so both arms are no-ops here. It still works because TABLE( is handled earlier and LIMIT is not in Snowflake's list. Worth either consuming and prev_token() like the comma site, or documenting the expected position on the trait, so the next lookahead override does not diverge.
There was a problem hiding this comment.
The keyword is now consumed before is_table_factor and restored with prev_token(), the same way as at the trailing comma site.
| #[test] | ||
| fn parse_count_wildcard() { | ||
| verified_only_select("SELECT COUNT(*) FROM Order WHERE id = 10"); | ||
| verified_only_select("SELECT COUNT(*) FROM orders WHERE id = 10"); |
There was a problem hiding this comment.
This rename shows the change goes beyond ON: Snowflake's whole table-factor list now applies at the table position, and Generic rejects the five words too. Both match the docs, but they should be called out as breaking in the description/changelog.
There was a problem hiding this comment.
Unfortunately breaking changes are so common that it is almost a given that all versions are breaking versions. I hope we'll reach stability at some point, which is also why I am adding the fuzzers to accelerate that process as much as possible.
SELECT * FROM t JOIN ONparses in every dialect, withONtaken as a table name, while PostgreSQL rejects it withsyntax error at or near "ON". This enforcesDialect::is_table_factorat the table name position and addsONtoRESERVED_FOR_TABLE_FACTOR, so unquoted INTO, LIMIT, HAVING, WHERE and ON stop being table names. Quoted forms still parse.Dialects whose documentation leaves one of these words unreserved keep accepting it.
That covers every keyword in ClickHouse and
LIMITin Databricks, Hive, MSSQL and Oracle. Snowflake's own list now applies to table names too, soparse_count_wildcardrenames itsOrdertable. I hope I have covered all of the dialects, as I am not too familiar with some.#2629 pins today's error for
SELECT * FROM users |> JOIN ON users.id = orders.user_id, and this changes it toExpected: table name, found: ON. Whichever of the two merges second updates that pin.