This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 2bd14cf62c Improve timestamp predicates support (#11326)
2bd14cf62c is described below
commit 2bd14cf62c4c22993eec589d81aa221014bd8218
Author: Sergei Grebnov <[email protected]>
AuthorDate: Mon Jul 8 05:17:03 2024 -0700
Improve timestamp predicates support (#11326)
---
datafusion/sql/src/unparser/expr.rs | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/datafusion/sql/src/unparser/expr.rs
b/datafusion/sql/src/unparser/expr.rs
index 07af4bfeba..198186934c 100644
--- a/datafusion/sql/src/unparser/expr.rs
+++ b/datafusion/sql/src/unparser/expr.rs
@@ -977,8 +977,13 @@ impl Unparser<'_> {
}
DataType::Float32 => Ok(ast::DataType::Float(None)),
DataType::Float64 => Ok(ast::DataType::Double),
- DataType::Timestamp(_, _) => {
- not_impl_err!("Unsupported DataType: conversion:
{data_type:?}")
+ DataType::Timestamp(_, tz) => {
+ let tz_info = match tz {
+ Some(_) => TimezoneInfo::WithTimeZone,
+ None => TimezoneInfo::None,
+ };
+
+ Ok(ast::DataType::Timestamp(None, tz_info))
}
DataType::Date32 => Ok(ast::DataType::Date),
DataType::Date64 => Ok(ast::DataType::Datetime(None)),
@@ -1063,9 +1068,9 @@ mod tests {
use std::ops::{Add, Sub};
use std::{any::Any, sync::Arc, vec};
+ use arrow::datatypes::TimeUnit;
use arrow::datatypes::{Field, Schema};
use arrow_schema::DataType::Int8;
-
use datafusion_common::TableReference;
use datafusion_expr::{
case, col, cube, exists, grouping_set, interval_datetime_lit,
@@ -1158,6 +1163,23 @@ mod tests {
}),
r#"CAST(a AS DATETIME)"#,
),
+ (
+ Expr::Cast(Cast {
+ expr: Box::new(col("a")),
+ data_type: DataType::Timestamp(
+ TimeUnit::Nanosecond,
+ Some("+08:00".into()),
+ ),
+ }),
+ r#"CAST(a AS TIMESTAMP WITH TIME ZONE)"#,
+ ),
+ (
+ Expr::Cast(Cast {
+ expr: Box::new(col("a")),
+ data_type: DataType::Timestamp(TimeUnit::Millisecond,
None),
+ }),
+ r#"CAST(a AS TIMESTAMP)"#,
+ ),
(
Expr::Cast(Cast {
expr: Box::new(col("a")),
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]