Add support for Databricks TIMESTAMP_NTZ. (#1781)

Co-authored-by: Roman Borschel <roman@cluvio.com>
This commit is contained in:
Roman Borschel 2025-03-31 17:51:55 +02:00 committed by GitHub
parent 95d7b86da5
commit 91327bb0c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 47 additions and 0 deletions

View file

@ -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,

View file

@ -875,6 +875,7 @@ define_keywords!(
TIME,
TIMESTAMP,
TIMESTAMPTZ,
TIMESTAMP_NTZ,
TIMETZ,
TIMEZONE,
TIMEZONE_ABBR,

View file

@ -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) {

View file

@ -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),
}
}