fix(tsql): quote reserved-keyword aliases and translate niladic temporal expressions (CR-009)#15
Merged
Conversation
…ral expressions (CR-009) Two related TSQL transpilation issues: 1. Column/table aliases that collide with T-SQL reserved keywords (e.g. current_time, time, key, user) were emitted bare, causing MSSQL syntax error 156. Add Generator::write_alias which auto-promotes QuoteStyle::None to QuoteStyle::Bracket for TSQL/Fabric targets when the alias matches the reserved-keyword set in dialects::is_tsql_reserved. Apply at all alias emission sites (SelectItem, Subquery, TableFunction, TableRef, Unpivot, Pivot, PivotValue). 2. ANSI niladic temporal expressions (CURRENT_TIME, CURRENT_DATE, CURRENT_TIMESTAMP, LOCALTIMESTAMP) without parentheses parsed as bare column references, then passed through verbatim. Add a new TypedFunction::CurrentTime variant and a parser rewrite in parse_primary that materializes unquoted, unparenthesized occurrences as the matching TypedFunction. Generator emits TSQL-compatible CAST(GETDATE() AS TIME)/DATE) and GETDATE() forms, with appropriate variants for MySQL/Hive/Postgres. Adds tests/test_tsql_reserved.rs covering both fixes (12 cases).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements CR-009. Two related TSQL transpilation issues:
Fix 1 — Reserved-keyword alias quoting
Column / table aliases that collide with T-SQL reserved keywords (e.g.
current_time,time,key,user) were emitted bare, causing MSSQL syntax error 156. AddsGenerator::write_aliaswhich auto-promotesQuoteStyle::NonetoQuoteStyle::Bracketfor TSQL/Fabric targets when the alias matches the reserved-keyword set indialects::is_tsql_reserved. Applied at all alias emission sites (SelectItem, Subquery, TableFunction, TableRef, Unpivot, Pivot, PivotValue).Fix 2 — Bare niladic temporal expressions
ANSI
CURRENT_TIME/CURRENT_DATE/CURRENT_TIMESTAMP/LOCALTIMESTAMPwithout parentheses previously parsed as bare column references and passed through verbatim. Adds a newTypedFunction::CurrentTimevariant and aparse_primaryrewrite that materializes unquoted, unparenthesized occurrences as the matchingTypedFunction. Generator emits TSQL-compatibleCAST(GETDATE() AS TIME)/CAST(GETDATE() AS DATE)/GETDATE()and the right form for MySQL/Hive/Postgres.Tests
tests/test_tsql_reserved.rsJira
PSQ-2419