Skip to content

Conversation

@JamesVorder
Copy link

This PR adds support for Databricks' timstamp-based time travel. This is a first step toward resolvign #2006.

The following is now supported:

SELECT 1 FROM t1 TIMESTAMP AS OF '2018-10-18T22:15:12.013Z';
SELECT 1 FROM t1 TIMESTAMP AS OF CURRENT_TIMESTAMP() - INTERVAL 12 HOURS;
-- etc.

let func_name = self.parse_object_name(true)?;
let func = self.parse_function(func_name)?;
return Ok(Some(TableVersion::Function(func)));
} else if dialect_of!(self is DatabricksDialect)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should use the defined supports_timestamp_versioning?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think relying on supports_timestamp_versioning alone might be insufficient. Please help me understand the desired behavior, I'm pretty new to the project.

The reason that I think that supports_timestamp_versioning may be insufficient on its own is that if we rely exclusively on that function to decide whether we parse TIMESTAMP AS OF syntax, then it will become available in the BigQuery dialect (and Snowflake, and MSSQL) - incorrectly. This is the reason I added an assertion to the BigQuery time travel test, looking for an error when TIMESTAMP AS OF is used.

In fact, I think what I have in this PR is also insufficient. If I use valid Snowflake time travel syntax (SELECT * FROM tbl AT(TIMESTAMP => '2024-12-15 00:00:00')), it's being accepted by the Databricks dialect. Instead, I would expect the Databricks dialect to throw an error (AT... is not valid time travel syntax in Databricks.)

Please help me understand the desired behavior here. Am I right to expect that an error should be thrown in the cases mentioned?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To demonstrate my thinking here, I've added the following 2 commits, which result in two failing tests:

  • b353499 -- sqlparse_bigquery::parse_table_timetravel fails after this commit
  • 759406f -- sqlparse_databricks::parse_table_timetravel fails after this commit

Are these failures valid, or is my expectation incorrect?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah its fine for the parser to be permissive and accept sql statements for a dialect that wouldn't necessarily be supported by the dialect (downstream crates are expected to validate the returned AST if the behavior is undesirable for a specific use case), so that e.g. having bigquery accept the 'TIMESTAMP AS OF' would be fine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! That makes sense, thank you for explaining. I believe this is addressed by the following 2 commits:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants