File tree Expand file tree Collapse file tree 5 files changed +28
-1
lines changed
Expand file tree Collapse file tree 5 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -2254,6 +2254,10 @@ pub enum TableVersion {
22542254 /// When the table version is defined using `FOR SYSTEM_TIME AS OF`.
22552255 /// For example: `SELECT * FROM tbl FOR SYSTEM_TIME AS OF TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 HOUR)`
22562256 ForSystemTimeAsOf ( Expr ) ,
2257+ /// When the table version is defined using `TIMESTAMP AS OF`.
2258+ /// Databricks supports this syntax.
2259+ /// For example: `SELECT * FROM tbl TIMESTAMP AS OF CURRENT_TIMESTAMP() - INTERVAL 1 HOUR`
2260+ TimestampAsOf ( Expr ) ,
22572261 /// When the table version is defined using a function.
22582262 /// For example: `SELECT * FROM tbl AT(TIMESTAMP => '2020-08-14 09:30:00')`
22592263 Function ( Expr ) ,
@@ -2263,6 +2267,7 @@ impl Display for TableVersion {
22632267 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
22642268 match self {
22652269 TableVersion :: ForSystemTimeAsOf ( e) => write ! ( f, "FOR SYSTEM_TIME AS OF {e}" ) ?,
2270+ TableVersion :: TimestampAsOf ( e) => write ! ( f, "TIMESTAMP AS OF {e}" ) ?,
22662271 TableVersion :: Function ( func) => write ! ( f, "{func}" ) ?,
22672272 }
22682273 Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ impl Dialect for DatabricksDialect {
6262 true
6363 }
6464
65+ /// <https://docs.databricks.com/gcp/en/delta/history#delta-time-travel-syntax>
66+ fn supports_timestamp_versioning ( & self ) -> bool {
67+ true
68+ }
69+
6570 fn supports_lambda_functions ( & self ) -> bool {
6671 true
6772 }
Original file line number Diff line number Diff line change @@ -15525,6 +15525,9 @@ impl<'a> Parser<'a> {
1552515525 let func_name = self.parse_object_name(true)?;
1552615526 let func = self.parse_function(func_name)?;
1552715527 return Ok(Some(TableVersion::Function(func)));
15528+ } else if self.parse_keywords(&[Keyword::TIMESTAMP, Keyword::AS, Keyword::OF]) {
15529+ let expr = self.parse_expr()?;
15530+ return Ok(Some(TableVersion::TimestampAsOf(expr)));
1552815531 }
1552915532 }
1553015533 Ok(None)
Original file line number Diff line number Diff line change @@ -1739,7 +1739,7 @@ fn parse_table_time_travel() {
17391739 args: None ,
17401740 with_hints: vec![ ] ,
17411741 version: Some ( TableVersion :: ForSystemTimeAsOf ( Expr :: Value (
1742- Value :: SingleQuotedString ( version) . with_empty_span( )
1742+ Value :: SingleQuotedString ( version. clone ( ) ) . with_empty_span( )
17431743 ) ) ) ,
17441744 partitions: vec![ ] ,
17451745 with_ordinality: false ,
Original file line number Diff line number Diff line change @@ -486,3 +486,17 @@ fn parse_semi_structured_data_traversal() {
486486 select. projection[ 0 ]
487487 ) ;
488488}
489+
490+ #[ test]
491+ fn parse_table_time_travel ( ) {
492+ all_dialects_where ( |d| d. supports_timestamp_versioning ( ) )
493+ . verified_only_select ( "SELECT 1 FROM t1 TIMESTAMP AS OF '2018-10-18T22:15:12.013Z'" ) ;
494+
495+ all_dialects_where ( |d| d. supports_timestamp_versioning ( ) ) . verified_only_select (
496+ "SELECT 1 FROM t1 TIMESTAMP AS OF CURRENT_TIMESTAMP() - INTERVAL 12 HOURS" ,
497+ ) ;
498+
499+ assert ! ( databricks( )
500+ . parse_sql_statements( "SELECT 1 FROM t1 FOR TIMESTAMP AS OF 'some_timestamp'" )
501+ . is_err( ) ) ;
502+ }
You can’t perform that action at this time.
0 commit comments