This is an automated email from the ASF dual-hosted git repository.
iffyio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 91327bb0 Add support for Databricks TIMESTAMP_NTZ. (#1781)
91327bb0 is described below
commit 91327bb0c02a09e0b5c5322c813c4b2a3b564439
Author: Roman Borschel <[email protected]>
AuthorDate: Mon Mar 31 17:51:55 2025 +0200
Add support for Databricks TIMESTAMP_NTZ. (#1781)
Co-authored-by: Roman Borschel <[email protected]>
---
src/ast/data_type.rs | 5 +++++
src/keywords.rs | 1 +
src/parser/mod.rs | 1 +
tests/sqlparser_databricks.rs | 40 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 47 insertions(+)
diff --git a/src/ast/data_type.rs b/src/ast/data_type.rs
index 57bc6744..dc523696 100644
--- a/src/ast/data_type.rs
+++ b/src/ast/data_type.rs
@@ -312,6 +312,10 @@ pub enum DataType {
///
/// [1]:
https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#datetime-type
Timestamp(Option<u64>, TimezoneInfo),
+ /// Databricks timestamp without time zone. See [1].
+ ///
+ /// [1]:
https://docs.databricks.com/aws/en/sql/language-manual/data-types/timestamp-ntz-type
+ TimestampNtz,
/// Interval
Interval,
/// JSON type
@@ -567,6 +571,7 @@ impl fmt::Display for DataType {
DataType::Timestamp(precision, timezone_info) => {
format_datetime_precision_and_tz(f, "TIMESTAMP", precision,
timezone_info)
}
+ DataType::TimestampNtz => write!(f, "TIMESTAMP_NTZ"),
DataType::Datetime64(precision, timezone) => {
format_clickhouse_datetime_precision_and_timezone(
f,
diff --git a/src/keywords.rs b/src/keywords.rs
index a0c556d2..8609ec43 100644
--- a/src/keywords.rs
+++ b/src/keywords.rs
@@ -875,6 +875,7 @@ define_keywords!(
TIME,
TIMESTAMP,
TIMESTAMPTZ,
+ TIMESTAMP_NTZ,
TIMETZ,
TIMEZONE,
TIMEZONE_ABBR,
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index adaae286..2b61529f 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -9247,6 +9247,7 @@ impl<'a> Parser<'a> {
self.parse_optional_precision()?,
TimezoneInfo::Tz,
)),
+ Keyword::TIMESTAMP_NTZ => Ok(DataType::TimestampNtz),
Keyword::TIME => {
let precision = self.parse_optional_precision()?;
let tz = if self.parse_keyword(Keyword::WITH) {
diff --git a/tests/sqlparser_databricks.rs b/tests/sqlparser_databricks.rs
index 3b36d7a1..88aae499 100644
--- a/tests/sqlparser_databricks.rs
+++ b/tests/sqlparser_databricks.rs
@@ -317,3 +317,43 @@ fn parse_databricks_struct_function() {
})
);
}
+
+#[test]
+fn data_type_timestamp_ntz() {
+ // Literal
+ assert_eq!(
+ databricks().verified_expr("TIMESTAMP_NTZ '2025-03-29T18:52:00'"),
+ Expr::TypedString {
+ data_type: DataType::TimestampNtz,
+ value: Value::SingleQuotedString("2025-03-29T18:52:00".to_owned())
+ }
+ );
+
+ // Cast
+ assert_eq!(
+ databricks().verified_expr("(created_at)::TIMESTAMP_NTZ"),
+ Expr::Cast {
+ kind: CastKind::DoubleColon,
+ expr: Box::new(Expr::Nested(Box::new(Expr::Identifier(
+ "created_at".into()
+ )))),
+ data_type: DataType::TimestampNtz,
+ format: None
+ }
+ );
+
+ // Column definition
+ match databricks().verified_stmt("CREATE TABLE foo (x TIMESTAMP_NTZ)") {
+ Statement::CreateTable(CreateTable { columns, .. }) => {
+ assert_eq!(
+ columns,
+ vec![ColumnDef {
+ name: "x".into(),
+ data_type: DataType::TimestampNtz,
+ options: vec![],
+ }]
+ );
+ }
+ s => panic!("Unexpected statement: {:?}", s),
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]