Skip to content

Commit

Permalink
null timestamptzs
Browse files Browse the repository at this point in the history
  • Loading branch information
Blizzara committed Jul 17, 2024
1 parent c267ef5 commit 7999e1e
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions datafusion/substrait/src/logical_plan/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ use substrait::proto::{
};
use substrait::proto::{FunctionArgument, SortField};

// Substrait TimestampTz only says that the timestamp is relative to UTC, which
// is the same as the expectation for any NON-empty timezone in DF. Any timezone would give
// correct points on a timeline, but the timezone may get used for arithmetic and display.
const DEFAULT_TIMEZONE: &str = "UTC";

pub fn name_to_op(name: &str) -> Option<Operator> {
match name {
"equal" => Some(Operator::Eq),
Expand Down Expand Up @@ -1392,16 +1397,16 @@ fn from_substrait_type(
// is the same as the expectation for any non-empty timezone in DF. Which timezone
// we select here doesn't really matter that much, but we default to UTC.
TIMESTAMP_SECOND_TYPE_VARIATION_REF => {
Ok(DataType::Timestamp(TimeUnit::Second, Some("UTC".into())))
Ok(DataType::Timestamp(TimeUnit::Second, Some(DEFAULT_TIMEZONE.into())))
}
TIMESTAMP_MILLI_TYPE_VARIATION_REF => {
Ok(DataType::Timestamp(TimeUnit::Millisecond, Some("UTC".into())))
Ok(DataType::Timestamp(TimeUnit::Millisecond, Some(DEFAULT_TIMEZONE.into())))
}
TIMESTAMP_MICRO_TYPE_VARIATION_REF => {
Ok(DataType::Timestamp(TimeUnit::Microsecond, Some("UTC".into())))
Ok(DataType::Timestamp(TimeUnit::Microsecond, Some(DEFAULT_TIMEZONE.into())))
}
TIMESTAMP_NANO_TYPE_VARIATION_REF => {
Ok(DataType::Timestamp(TimeUnit::Nanosecond, Some("UTC".into())))
Ok(DataType::Timestamp(TimeUnit::Nanosecond, Some(DEFAULT_TIMEZONE.into())))
}
v => not_impl_err!(
"Unsupported Substrait type variation {v} of type {s_kind:?}"
Expand Down Expand Up @@ -1700,20 +1705,17 @@ fn from_substrait_literal(
}
},
Some(LiteralType::TimestampTz(t)) => match lit.type_variation_reference {
// Substrait TimestampTz only says that the timestamp is relative to UTC, which
// is the same as the expectation for any non-empty timezone in DF. Which timezone
// we select here doesn't really matter that much, but we default to UTC.
TIMESTAMP_SECOND_TYPE_VARIATION_REF => {
ScalarValue::TimestampSecond(Some(*t), Some("UTC".into()))
ScalarValue::TimestampSecond(Some(*t), Some(DEFAULT_TIMEZONE.into()))
}
TIMESTAMP_MILLI_TYPE_VARIATION_REF => {
ScalarValue::TimestampMillisecond(Some(*t), Some("UTC".into()))
ScalarValue::TimestampMillisecond(Some(*t), Some(DEFAULT_TIMEZONE.into()))
}
TIMESTAMP_MICRO_TYPE_VARIATION_REF => {
ScalarValue::TimestampMicrosecond(Some(*t), Some("UTC".into()))
ScalarValue::TimestampMicrosecond(Some(*t), Some(DEFAULT_TIMEZONE.into()))
}
TIMESTAMP_NANO_TYPE_VARIATION_REF => {
ScalarValue::TimestampNanosecond(Some(*t), Some("UTC".into()))
ScalarValue::TimestampNanosecond(Some(*t), Some(DEFAULT_TIMEZONE.into()))
}
others => {
return substrait_err!("Unknown type variation reference {others}");
Expand Down Expand Up @@ -1949,6 +1951,30 @@ fn from_substrait_null(
"Unsupported Substrait type variation {v} of type {kind:?}"
),
},
r#type::Kind::TimestampTz(ts) => match ts.type_variation_reference {
TIMESTAMP_SECOND_TYPE_VARIATION_REF => Ok(ScalarValue::TimestampSecond(
None,
Some(DEFAULT_TIMEZONE.into()),
)),
TIMESTAMP_MILLI_TYPE_VARIATION_REF => {
Ok(ScalarValue::TimestampMillisecond(
None,
Some(DEFAULT_TIMEZONE.into()),
))
}
TIMESTAMP_MICRO_TYPE_VARIATION_REF => {
Ok(ScalarValue::TimestampMicrosecond(
None,
Some(DEFAULT_TIMEZONE.into()),
))
}
TIMESTAMP_NANO_TYPE_VARIATION_REF => Ok(
ScalarValue::TimestampNanosecond(None, Some(DEFAULT_TIMEZONE.into())),
),
v => not_impl_err!(
"Unsupported Substrait type variation {v} of type {kind:?}"
),
},
r#type::Kind::Date(date) => match date.type_variation_reference {
DATE_32_TYPE_VARIATION_REF => Ok(ScalarValue::Date32(None)),
DATE_64_TYPE_VARIATION_REF => Ok(ScalarValue::Date64(None)),
Expand Down

0 comments on commit 7999e1e

Please sign in to comment.