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

Raise Unsupported SQL type for Time(WithTimeZone) and Time(Tz) #3718

Merged
merged 2 commits into from Oct 5, 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
65 changes: 65 additions & 0 deletions datafusion/core/tests/sql/timestamp.rs
Expand Up @@ -1554,3 +1554,68 @@ async fn cast_timestamp_to_timestamptz() -> Result<()> {

Ok(())
}

#[tokio::test]
async fn test_cast_to_time() -> Result<()> {
let ctx = SessionContext::new();
let sql = "SELECT 0::TIME";
let actual = execute_to_batches(&ctx, sql).await;

let expected = vec![
"+----------+",
"| Int64(0) |",
"+----------+",
"| 00:00:00 |",
"+----------+",
];
assert_batches_eq!(expected, &actual);

Ok(())
}

#[tokio::test]
async fn test_cast_to_time_with_time_zone_should_not_work() -> Result<()> {
// this should not work until we implement tz for DataType::Time64
let ctx = SessionContext::new();
let sql = "SELECT 0::TIME WITH TIME ZONE";
let results = plan_and_collect(&ctx, sql).await.unwrap_err();

assert_eq!(
results.to_string(),
"This feature is not implemented: Unsupported SQL type Time(WithTimeZone)"
);

Ok(())
}

#[tokio::test]
async fn test_cast_to_time_without_time_zone() -> Result<()> {
let ctx = SessionContext::new();
let sql = "SELECT 0::TIME WITHOUT TIME ZONE";
let actual = execute_to_batches(&ctx, sql).await;

let expected = vec![
"+----------+",
"| Int64(0) |",
"+----------+",
"| 00:00:00 |",
"+----------+",
];
assert_batches_eq!(expected, &actual);

Ok(())
}

#[tokio::test]
async fn test_cast_to_timetz_should_not_work() -> Result<()> {
// this should not work until we implement tz for DataType::Time64
let ctx = SessionContext::new();
let sql = "SELECT 0::TIMETZ";
let results = plan_and_collect(&ctx, sql).await.unwrap_err();

assert_eq!(
results.to_string(),
"This feature is not implemented: Unsupported SQL type Time(Tz)"
);
Ok(())
}
14 changes: 13 additions & 1 deletion datafusion/sql/src/planner.rs
Expand Up @@ -2714,7 +2714,19 @@ pub fn convert_simple_data_type(sql_type: &SQLDataType) -> Result<DataType> {
Ok(DataType::Timestamp(TimeUnit::Nanosecond, tz))
}
SQLDataType::Date => Ok(DataType::Date32),
SQLDataType::Time(_) => Ok(DataType::Time64(TimeUnit::Nanosecond)),
SQLDataType::Time(tz_info) => {
if matches!(tz_info, TimezoneInfo::None)
|| matches!(tz_info, TimezoneInfo::WithoutTimeZone)
{
Ok(DataType::Time64(TimeUnit::Nanosecond))
} else {
// We dont support TIMETZ and TIME WITH TIME ZONE for now
Err(DataFusionError::NotImplemented(format!(
"Unsupported SQL type {:?}",
sql_type
)))
}
}
SQLDataType::Decimal(precision, scale) => make_decimal_type(*precision, *scale),
SQLDataType::Bytea => Ok(DataType::Binary),
// Explicitly list all other types so that if sqlparser
Expand Down