Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timestamptz #3660

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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