Parse FOR TIMESTAMP AS OF and FOR VERSION AS OF table versions - #2486
Open
rexminnis wants to merge 2 commits into
Open
Parse FOR TIMESTAMP AS OF and FOR VERSION AS OF table versions#2486rexminnis wants to merge 2 commits into
rexminnis wants to merge 2 commits into
Conversation
Trino (the SQL engine that descends from Presto) follows the standard closely, and most of what it needs is already an opt-in hook: double-quoted identifiers only, FILTER on aggregates, GROUP BY expressions and grouping sets, lambdas, MATCH_RECOGNIZE, table versioning, parenthesized EXPLAIN options, named table-function arguments with =>, and COMMENT ON. The test corpus covers the constructs a Trino user writes daily. Not covered yet: the FOR prefix on TIMESTAMP/VERSION AS OF (time travel), ROW types with named fields, and inline WITH FUNCTION routines.
Trino spells time travel on Iceberg and Delta tables with a leading FOR: FOR TIMESTAMP AS OF <expr> and FOR VERSION AS OF <snapshot id | branch>. The parser already accepts the Databricks forms without FOR behind supports_table_versioning; these two variants join them behind a new supports_for_table_version hook that TrinoDialect opts into, with their own Display, so a statement round-trips in the spelling its engine accepts. Databricks keeps rejecting the FOR forms.
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.
Stacked on #2485; only the last commit is new here, and I will rebase once that one lands.
Trino spells time travel on Iceberg and Delta tables with a leading
FOR:https://trino.io/docs/current/connector/iceberg.html#time-travel-queries
The parser already accepts the Databricks forms without
FORbehindsupports_table_versioning. This addsTableVersion::ForTimestampAsOfandTableVersion::ForVersionAsOfwith their ownDisplay, behind a newDialect::supports_for_table_versionhook thatTrinoDialectopts into, so a statement round-trips in the spelling its engine accepts.VERSION AS OFkeeps its numeric-only argument; theFORform takes an expression because Iceberg accepts a branch or tag name there. Databricks keeps rejecting theFORforms, as its existing test asserts.One pre-existing issue noticed on the way, left for a separate change: an alias after a version clause parses, but the canonical form prints the alias first (
t AS a FOR VERSION AS OF 1), which no engine accepts.