Repository navigation
SQLite: Accept fallback keywords as implicit column aliases - #2682
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 #2682 +/- ##
==========================================
+ Coverage 81.52% 81.53% +0.01%
==========================================
Files 42 42
Lines 34205 34226 +21
Branches 34205 34226 +21
==========================================
+ Hits 27885 27907 +22
Misses 2770 2770
+ Partials 3550 3549 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
sabir-akhadov-localstack
left a comment
There was a problem hiding this comment.
One non-blocking comment inline.
| Token::SingleQuotedString(_) | Token::DoubleQuotedString(_) | ||
| ), | ||
| }; | ||
| if self.dialect.supports_over_keyword_as_column_alias() && !next_is_window_name { |
There was a problem hiding this comment.
is_column_alias runs here with the parser still positioned on the candidate token, while parse_optional_alias_inner consumes it before calling the hook, so overrides that peek ahead (Snowflake's looks at the token after EXCEPT/RETURNING/LIMIT) see a different position at this site. The result is discarded unless supports_over_keyword_as_column_alias() is true, so nothing breaks today, but checking the flag before the lookahead would skip it for every other dialect and keep the position mismatch from biting a dialect that enables the flag later.
There was a problem hiding this comment.
The lookahead now runs only when supports_over_keyword_as_column_alias() is true, so other dialects never reach it.
dcceac3 to
fb7ed0a
Compare
SQLite lets most keywords serve as names: its grammar declares a
%fallback IDlist (https://sqlite.org/src/file?name=src/parse.y) and its keyword page describes the fallback (https://www.sqlite.org/lang_keywords.html). SoSELECT a view FROM torSELECT 1 offsetalias the column asvieworoffset, and SQLite 3.51.1 runs them. The SQLite dialect rejected 13 such keywords as implicit aliases:ANALYZE,CLUSTER,DISTRIBUTE,EXCLUDE,EXPLAIN,FETCH,LATERAL,MINUS,OFFSET,SORT,TOP,VIEWandWITH.In order to add support for these,
SQLiteDialectnow overridesis_column_aliasand only refuses the keywords that start the next clause (FROM,WHERE,GROUP,ORDER,LIMIT, the set operators,RETURNING,VALUES,INTO,SELECT). SQLite also only readsOVERas a keyword when(or a name follows (analyzeOverKeywordin https://sqlite.org/src/file?name=src/tokenize.c), soSELECT f() OVERaliases the result asOVER. A new dialect method,supports_over_keyword_as_column_alias, enables that for SQLite. Run against every keyword in this crate, asSELECT 1 <kw>andSELECT 1 <kw> FROM t, the SQLite dialect now matches SQLite on 26 more forms and accepts nothing new that SQLite rejects. Two common tests that relied onWITHandFETCHending a select list now skip SQLite.