Skip to content

Commit

Permalink
add timestamptz (#3660)
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingkuo committed Sep 30, 2022
1 parent 65a5c6b commit bfc5ff0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
24 changes: 24 additions & 0 deletions datafusion/core/tests/sql/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
5 changes: 4 additions & 1 deletion datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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(_)
Expand Down

0 comments on commit bfc5ff0

Please sign in to comment.