Support TRUNCATE IF EXISTS, STRUCT-field COLLATE, and Delta time travel#89
Merged
Conversation
Snowflake accepts an optional IF EXISTS clause in TRUNCATE [TABLE] [IF EXISTS] <name> (https://docs.snowflake.com/en/sql-reference/sql/truncate-table). Parse and round-trip it via a new if_exists flag on Statement::Truncate; previously the clause errored with "Expected end of statement, found: EXISTS".
Databricks permits a per-field COLLATE clause on string types in column, field, or variable type definitions, including fields nested inside STRUCT and ARRAY<STRUCT<...>> (https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-collation). Consume the optional COLLATE name in the STRUCT field-definition parser; the collation carries no lineage so it is not retained in the AST. Fixes 2 corpus test failures (Databricks).
Support Delta Lake / Databricks time travel on table references: VERSION AS OF <version>, TIMESTAMP AS OF <expr>, and the @v<version> / @<yyyyMMddHHmmssSSS> shorthands, in both the pre-alias and post-alias positions (https://docs.databricks.com/aws/en/delta/history). The qualifier is captured on the AST via two new TableVersion variants (VersionAsOf, TimestampAsOf); the table name is unaffected so lineage is preserved. The @ shorthands canonicalize to the AS OF forms on display. Fixes 1 corpus test failure (Databricks).
Corpus Parsing ReportTotal: 191711 passed, 1920 failed (99.0% pass rate) ✨ No changes in test results By Dialect
|
grasskode
approved these changes
Jun 18, 2026
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.
Three independent dialect parser fixes (one per commit), each with tests and verified against the corpus (0 regressions).
fix(snowflake): support TRUNCATE IF EXISTS— accept the optionalIF EXISTSclause inTRUNCATE [TABLE] [IF EXISTS] <name>(Snowflake docs). Captured via a newif_existsflag onStatement::Truncate.fix(databricks): accept COLLATE on STRING fields inside STRUCT— consume the per-fieldCOLLATE <name>clause on string types nested inSTRUCT<...>/ARRAY<STRUCT<...>>(collation docs). Collation carries no lineage so it is consumed but not retained. Fixes 2 corpus files.fix(databricks): parse Delta Lake time-travel qualifiers— supportVERSION AS OF <version>,TIMESTAMP AS OF <expr>, and the@v<version>/@<yyyyMMddHHmmssSSS>shorthands in both pre-alias and post-alias positions (time travel docs). Captured on the AST via two newTableVersionvariants. Fixes 1 real customer corpus file.All 1186 unit tests pass; corpus comparison shows 0 regressions.