Skip to content

Commit e77ecbc

Browse files
authored
Revert "Add support for Snowflake AT/BEFORE (apache#1667)"
This reverts commit 748a274.
1 parent bd84d9d commit e77ecbc

File tree

7 files changed

+12
-48
lines changed

7 files changed

+12
-48
lines changed

src/ast/query.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,19 +1873,13 @@ impl fmt::Display for TableAliasColumnDef {
18731873
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
18741874
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
18751875
pub enum TableVersion {
1876-
/// When the table version is defined using `FOR SYSTEM_TIME AS OF`.
1877-
/// For example: `SELECT * FROM tbl FOR SYSTEM_TIME AS OF TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 HOUR)`
18781876
ForSystemTimeAsOf(Expr),
1879-
/// When the table version is defined using a function.
1880-
/// For example: `SELECT * FROM tbl AT(TIMESTAMP => '2020-08-14 09:30:00')`
1881-
Function(Expr),
18821877
}
18831878

18841879
impl Display for TableVersion {
18851880
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18861881
match self {
18871882
TableVersion::ForSystemTimeAsOf(e) => write!(f, " FOR SYSTEM_TIME AS OF {e}")?,
1888-
TableVersion::Function(func) => write!(f, " {func}")?,
18891883
}
18901884
Ok(())
18911885
}

src/dialect/bigquery.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,4 @@ impl Dialect for BigQueryDialect {
7777
fn supports_struct_literal(&self) -> bool {
7878
true
7979
}
80-
81-
// See <https://cloud.google.com/bigquery/docs/access-historical-data>
82-
fn supports_timestamp_versioning(&self) -> bool {
83-
true
84-
}
8580
}

src/dialect/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -834,12 +834,6 @@ pub trait Dialect: Debug + Any {
834834
fn is_table_factor_alias(&self, explicit: bool, kw: &Keyword, _parser: &mut Parser) -> bool {
835835
explicit || !keywords::RESERVED_FOR_TABLE_ALIAS.contains(kw)
836836
}
837-
838-
/// Returns true if this dialect supports querying historical table data
839-
/// by specifying which version of the data to query.
840-
fn supports_timestamp_versioning(&self) -> bool {
841-
false
842-
}
843837
}
844838

845839
/// This represents the operators for which precedence must be defined

src/dialect/mssql.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,4 @@ impl Dialect for MsSqlDialect {
9090
fn supports_set_stmt_without_operator(&self) -> bool {
9191
true
9292
}
93-
94-
/// See: <https://learn.microsoft.com/en-us/sql/relational-databases/tables/querying-data-in-a-system-versioned-temporal-table>
95-
fn supports_timestamp_versioning(&self) -> bool {
96-
true
97-
}
9893
}

src/dialect/snowflake.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,6 @@ impl Dialect for SnowflakeDialect {
307307
_ => true,
308308
}
309309
}
310-
311-
/// See: <https://docs.snowflake.com/en/sql-reference/constructs/at-before>
312-
fn supports_timestamp_versioning(&self) -> bool {
313-
true
314-
}
315310
}
316311

317312
fn parse_file_staging_command(kw: Keyword, parser: &mut Parser) -> Result<Statement, ParserError> {

src/parser/mod.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11208,7 +11208,7 @@ impl<'a> Parser<'a> {
1120811208
};
1120911209

1121011210
// Parse potential version qualifier
11211-
let version = self.maybe_parse_table_version()?;
11211+
let version = self.parse_table_version()?;
1121211212

1121311213
// Postgres, MSSQL, ClickHouse: table-valued functions:
1121411214
let args = if self.consume_token(&Token::LParen) {
@@ -11639,20 +11639,18 @@ impl<'a> Parser<'a> {
1163911639
}
1164011640
}
1164111641

11642-
/// Parses a the timestamp version specifier (i.e. query historical data)
11643-
pub fn maybe_parse_table_version(&mut self) -> Result<Option<TableVersion>, ParserError> {
11644-
if self.dialect.supports_timestamp_versioning() {
11645-
if self.parse_keywords(&[Keyword::FOR, Keyword::SYSTEM_TIME, Keyword::AS, Keyword::OF])
11646-
{
11647-
let expr = self.parse_expr()?;
11648-
return Ok(Some(TableVersion::ForSystemTimeAsOf(expr)));
11649-
} else if self.peek_keyword(Keyword::AT) || self.peek_keyword(Keyword::BEFORE) {
11650-
let func_name = self.parse_object_name(true)?;
11651-
let func = self.parse_function(func_name)?;
11652-
return Ok(Some(TableVersion::Function(func)));
11653-
}
11642+
/// Parse a given table version specifier.
11643+
///
11644+
/// For now it only supports timestamp versioning for BigQuery and MSSQL dialects.
11645+
pub fn parse_table_version(&mut self) -> Result<Option<TableVersion>, ParserError> {
11646+
if dialect_of!(self is BigQueryDialect | MsSqlDialect)
11647+
&& self.parse_keywords(&[Keyword::FOR, Keyword::SYSTEM_TIME, Keyword::AS, Keyword::OF])
11648+
{
11649+
let expr = self.parse_expr()?;
11650+
Ok(Some(TableVersion::ForSystemTimeAsOf(expr)))
11651+
} else {
11652+
Ok(None)
1165411653
}
11655-
Ok(None)
1165611654
}
1165711655

1165811656
/// Parses MySQL's JSON_TABLE column definition.

tests/sqlparser_snowflake.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,10 +3144,3 @@ fn test_sql_keywords_as_select_item_aliases() {
31443144
.is_err());
31453145
}
31463146
}
3147-
3148-
#[test]
3149-
fn test_timetravel_at_before() {
3150-
snowflake().verified_only_select("SELECT * FROM tbl AT(TIMESTAMP => '2024-12-15 00:00:00')");
3151-
snowflake()
3152-
.verified_only_select("SELECT * FROM tbl BEFORE(TIMESTAMP => '2024-12-15 00:00:00')");
3153-
}

0 commit comments

Comments
 (0)