You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2025/10/30 09:21:05 UTC

(datafusion-sqlparser-rs) branch gh-readonly-queue/main/pr-2080-67684c84d4c2589356c411ea4917dcf1defcd77c created (now bc6e1d6e)

This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a change to branch gh-readonly-queue/main/pr-2080-67684c84d4c2589356c411ea4917dcf1defcd77c
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


      at bc6e1d6e Added TIMESTAMP_NTZ type support with precision to Snowflake dialect (#2080)

This branch includes the following new commits:

     new bc6e1d6e Added TIMESTAMP_NTZ type support with precision to Snowflake dialect (#2080)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org


(datafusion-sqlparser-rs) 01/01: Added TIMESTAMP_NTZ type support with precision to Snowflake dialect (#2080)

Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a commit to branch gh-readonly-queue/main/pr-2080-67684c84d4c2589356c411ea4917dcf1defcd77c
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git

commit bc6e1d6e1a960c0c220c712a16b5046f563a5f6e
Author: Andriy Romanov <ar...@montecarlodata.com>
AuthorDate: Thu Oct 30 02:20:41 2025 -0700

    Added TIMESTAMP_NTZ type support with precision to Snowflake dialect (#2080)
---
 src/ast/data_type.rs          |  6 ++++--
 src/parser/mod.rs             |  4 +++-
 tests/sqlparser_databricks.rs |  6 +++---
 tests/sqlparser_snowflake.rs  | 15 +++++++++++++++
 4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/src/ast/data_type.rs b/src/ast/data_type.rs
index f8523e84..6da6a90d 100644
--- a/src/ast/data_type.rs
+++ b/src/ast/data_type.rs
@@ -375,7 +375,7 @@ pub enum DataType {
     /// Databricks timestamp without time zone. See [1].
     ///
     /// [1]: https://docs.databricks.com/aws/en/sql/language-manual/data-types/timestamp-ntz-type
-    TimestampNtz,
+    TimestampNtz(Option<u64>),
     /// Interval type.
     Interval {
         /// [PostgreSQL] fields specification like `INTERVAL YEAR TO MONTH`.
@@ -676,7 +676,9 @@ 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::TimestampNtz(precision) => {
+                format_type_with_optional_length(f, "TIMESTAMP_NTZ", precision, false)
+            }
             DataType::Datetime64(precision, timezone) => {
                 format_clickhouse_datetime_precision_and_timezone(
                     f,
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index b44171c7..1248c918 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -10542,7 +10542,9 @@ impl<'a> Parser<'a> {
                     self.parse_optional_precision()?,
                     TimezoneInfo::Tz,
                 )),
-                Keyword::TIMESTAMP_NTZ => Ok(DataType::TimestampNtz),
+                Keyword::TIMESTAMP_NTZ => {
+                    Ok(DataType::TimestampNtz(self.parse_optional_precision()?))
+                }
                 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 e01611b6..92b63533 100644
--- a/tests/sqlparser_databricks.rs
+++ b/tests/sqlparser_databricks.rs
@@ -328,7 +328,7 @@ fn data_type_timestamp_ntz() {
     assert_eq!(
         databricks().verified_expr("TIMESTAMP_NTZ '2025-03-29T18:52:00'"),
         Expr::TypedString(TypedString {
-            data_type: DataType::TimestampNtz,
+            data_type: DataType::TimestampNtz(None),
             value: ValueWithSpan {
                 value: Value::SingleQuotedString("2025-03-29T18:52:00".to_owned()),
                 span: Span::empty(),
@@ -345,7 +345,7 @@ fn data_type_timestamp_ntz() {
             expr: Box::new(Expr::Nested(Box::new(Expr::Identifier(
                 "created_at".into()
             )))),
-            data_type: DataType::TimestampNtz,
+            data_type: DataType::TimestampNtz(None),
             format: None
         }
     );
@@ -357,7 +357,7 @@ fn data_type_timestamp_ntz() {
                 columns,
                 vec![ColumnDef {
                     name: "x".into(),
-                    data_type: DataType::TimestampNtz,
+                    data_type: DataType::TimestampNtz(None),
                     options: vec![],
                 }]
             );
diff --git a/tests/sqlparser_snowflake.rs b/tests/sqlparser_snowflake.rs
index e7a12834..2be5eae8 100644
--- a/tests/sqlparser_snowflake.rs
+++ b/tests/sqlparser_snowflake.rs
@@ -4638,6 +4638,21 @@ fn test_create_database() {
     assert!(err.contains("Expected"), "Unexpected error: {err}");
 }
 
+#[test]
+fn test_timestamp_ntz_with_precision() {
+    snowflake().verified_stmt("SELECT CAST('2024-01-01 01:00:00' AS TIMESTAMP_NTZ(1))");
+    snowflake().verified_stmt("SELECT CAST('2024-01-01 01:00:00' AS TIMESTAMP_NTZ(9))");
+
+    let select =
+        snowflake().verified_only_select("SELECT CAST('2024-01-01 01:00:00' AS TIMESTAMP_NTZ(9))");
+    match expr_from_projection(only(&select.projection)) {
+        Expr::Cast { data_type, .. } => {
+            assert_eq!(*data_type, DataType::TimestampNtz(Some(9)));
+        }
+        _ => unreachable!(),
+    }
+}
+
 #[test]
 fn test_drop_constraints() {
     snowflake().verified_stmt("ALTER TABLE tbl DROP PRIMARY KEY");


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org