This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/master by this push:
new bfc5ff04f add timestamptz (#3660)
bfc5ff04f is described below
commit bfc5ff04fac3feacf24c46621a90ad8c79285ddf
Author: Wei-Ting Kuo <[email protected]>
AuthorDate: Fri Sep 30 19:00:19 2022 +0800
add timestamptz (#3660)
---
datafusion/core/tests/sql/timestamp.rs | 24 ++++++++++++++++++++++++
datafusion/sql/src/planner.rs | 5 ++++-
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/datafusion/core/tests/sql/timestamp.rs
b/datafusion/core/tests/sql/timestamp.rs
index fc3912a68..291197925 100644
--- a/datafusion/core/tests/sql/timestamp.rs
+++ b/datafusion/core/tests/sql/timestamp.rs
@@ -1530,3 +1530,27 @@ async fn cast_timestamp_before_1970() -> Result<()> {
Ok(())
}
+
+#[tokio::test]
+async fn cast_timestamp_to_timestamptz() -> Result<()> {
+ let ctx = SessionContext::new();
+ let table_a = make_timestamp_table::<TimestampNanosecondType>()?;
+
+ ctx.register_table("table_a", table_a)?;
+
+ let sql = "SELECT ts::timestamptz, arrow_typeof(ts::timestamptz) FROM
table_a;";
+ let actual = execute_to_batches(&ctx, sql).await;
+
+ let expected = vec![
+ "+----------------------------+------------------------------------+",
+ "| table_a.ts | arrowtypeof(table_a.ts) |",
+ "+----------------------------+------------------------------------+",
+ "| 2020-09-08 13:42:29.190855 | Timestamp(Nanosecond, Some(\"UTC\"))
|",
+ "| 2020-09-08 12:42:29.190855 | Timestamp(Nanosecond, Some(\"UTC\"))
|",
+ "| 2020-09-08 11:42:29.190855 | Timestamp(Nanosecond, Some(\"UTC\"))
|",
+ "+----------------------------+------------------------------------+",
+ ];
+ assert_batches_eq!(expected, &actual);
+
+ Ok(())
+}
diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs
index 202641175..b6a6d584a 100644
--- a/datafusion/sql/src/planner.rs
+++ b/datafusion/sql/src/planner.rs
@@ -2703,6 +2703,10 @@ pub fn convert_simple_data_type(sql_type: &SQLDataType)
-> Result<DataType> {
| SQLDataType::Text
| SQLDataType::String => Ok(DataType::Utf8),
SQLDataType::Timestamp => Ok(DataType::Timestamp(TimeUnit::Nanosecond,
None)),
+ SQLDataType::TimestampTz => Ok(DataType::Timestamp(
+ TimeUnit::Nanosecond,
+ Some("UTC".into()),
+ )),
SQLDataType::Date => Ok(DataType::Date32),
SQLDataType::Time => Ok(DataType::Time64(TimeUnit::Nanosecond)),
SQLDataType::Decimal(precision, scale) =>
make_decimal_type(*precision, *scale),
@@ -2716,7 +2720,6 @@ pub fn convert_simple_data_type(sql_type: &SQLDataType)
-> Result<DataType> {
| SQLDataType::Varbinary(_)
| SQLDataType::Blob(_)
| SQLDataType::Datetime
- | SQLDataType::TimestampTz
| SQLDataType::Interval
| SQLDataType::Regclass
| SQLDataType::Custom(_)