Skip to content

Commit 91327bb

Browse files
romanbRoman Borschel
and
Roman Borschel
authored
Add support for Databricks TIMESTAMP_NTZ. (#1781)
Co-authored-by: Roman Borschel <[email protected]>
1 parent 95d7b86 commit 91327bb

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

src/ast/data_type.rs

+5
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ pub enum DataType {
312312
///
313313
/// [1]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#datetime-type
314314
Timestamp(Option<u64>, TimezoneInfo),
315+
/// Databricks timestamp without time zone. See [1].
316+
///
317+
/// [1]: https://docs.databricks.com/aws/en/sql/language-manual/data-types/timestamp-ntz-type
318+
TimestampNtz,
315319
/// Interval
316320
Interval,
317321
/// JSON type
@@ -567,6 +571,7 @@ impl fmt::Display for DataType {
567571
DataType::Timestamp(precision, timezone_info) => {
568572
format_datetime_precision_and_tz(f, "TIMESTAMP", precision, timezone_info)
569573
}
574+
DataType::TimestampNtz => write!(f, "TIMESTAMP_NTZ"),
570575
DataType::Datetime64(precision, timezone) => {
571576
format_clickhouse_datetime_precision_and_timezone(
572577
f,

src/keywords.rs

+1
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ define_keywords!(
875875
TIME,
876876
TIMESTAMP,
877877
TIMESTAMPTZ,
878+
TIMESTAMP_NTZ,
878879
TIMETZ,
879880
TIMEZONE,
880881
TIMEZONE_ABBR,

src/parser/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9247,6 +9247,7 @@ impl<'a> Parser<'a> {
92479247
self.parse_optional_precision()?,
92489248
TimezoneInfo::Tz,
92499249
)),
9250+
Keyword::TIMESTAMP_NTZ => Ok(DataType::TimestampNtz),
92509251
Keyword::TIME => {
92519252
let precision = self.parse_optional_precision()?;
92529253
let tz = if self.parse_keyword(Keyword::WITH) {

tests/sqlparser_databricks.rs

+40
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,43 @@ fn parse_databricks_struct_function() {
317317
})
318318
);
319319
}
320+
321+
#[test]
322+
fn data_type_timestamp_ntz() {
323+
// Literal
324+
assert_eq!(
325+
databricks().verified_expr("TIMESTAMP_NTZ '2025-03-29T18:52:00'"),
326+
Expr::TypedString {
327+
data_type: DataType::TimestampNtz,
328+
value: Value::SingleQuotedString("2025-03-29T18:52:00".to_owned())
329+
}
330+
);
331+
332+
// Cast
333+
assert_eq!(
334+
databricks().verified_expr("(created_at)::TIMESTAMP_NTZ"),
335+
Expr::Cast {
336+
kind: CastKind::DoubleColon,
337+
expr: Box::new(Expr::Nested(Box::new(Expr::Identifier(
338+
"created_at".into()
339+
)))),
340+
data_type: DataType::TimestampNtz,
341+
format: None
342+
}
343+
);
344+
345+
// Column definition
346+
match databricks().verified_stmt("CREATE TABLE foo (x TIMESTAMP_NTZ)") {
347+
Statement::CreateTable(CreateTable { columns, .. }) => {
348+
assert_eq!(
349+
columns,
350+
vec![ColumnDef {
351+
name: "x".into(),
352+
data_type: DataType::TimestampNtz,
353+
options: vec![],
354+
}]
355+
);
356+
}
357+
s => panic!("Unexpected statement: {:?}", s),
358+
}
359+
}

0 commit comments

Comments
 (0)