Skip to content

Support TRUNCATE IF EXISTS, STRUCT-field COLLATE, and Delta time travel#89

Merged
lustefaniak merged 3 commits into
mainfrom
lukasz-truncate-if-exists
Jun 18, 2026
Merged

Support TRUNCATE IF EXISTS, STRUCT-field COLLATE, and Delta time travel#89
lustefaniak merged 3 commits into
mainfrom
lukasz-truncate-if-exists

Conversation

@lustefaniak

Copy link
Copy Markdown
Collaborator

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 optional IF EXISTS clause in TRUNCATE [TABLE] [IF EXISTS] <name> (Snowflake docs). Captured via a new if_exists flag on Statement::Truncate.
  • fix(databricks): accept COLLATE on STRING fields inside STRUCT — consume the per-field COLLATE <name> clause on string types nested in STRUCT<...> / 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 — support VERSION 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 new TableVersion variants. Fixes 1 real customer corpus file.

All 1186 unit tests pass; corpus comparison shows 0 regressions.

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).
@github-actions

Copy link
Copy Markdown

Corpus Parsing Report

Total: 191711 passed, 1920 failed (99.0% pass rate)

✨ No changes in test results

By Dialect

Dialect Passed Failed Total Pass Rate Delta
ansi 511 69 580 88.1% -
athena 37 1 38 97.4% -
bigquery 42324 113 42437 99.7% -
clickhouse 2723 129 2852 95.5% -
databricks 2965 184 3149 94.2% +3
doris 28 12 40 70.0% -
dremio 27 0 27 100.0% -
duckdb 1124 45 1169 96.2% -
exasol 54 7 61 88.5% -
fabric 6 0 6 100.0% -
generic 17 38 55 30.9% -
hive 35 10 45 77.8% -
materialize 6 14 20 30.0% -
mssql 2276 407 2683 84.8% -
mysql 151 37 188 80.3% -
oracle 1046 352 1398 74.8% -
postgres 1172 111 1283 91.3% -
presto 55 8 63 87.3% -
redshift 40503 65 40568 99.8% -
singlestore 141 9 150 94.0% -
snowflake 94739 138 94877 99.9% -
spark 90 20 110 81.8% -
sqlite 51 16 67 76.1% -
starrocks 29 4 33 87.9% -
teradata 23 20 43 53.5% -
trino 1413 77 1490 94.8% -
tsql 165 34 199 82.9% -

@lustefaniak lustefaniak enabled auto-merge (rebase) June 18, 2026 00:54
@lustefaniak lustefaniak merged commit 6b95571 into main Jun 18, 2026
3 checks passed
@lustefaniak lustefaniak deleted the lukasz-truncate-if-exists branch June 18, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants