Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Blizzara committed Jul 22, 2024
1 parent 8426a13 commit 49d90c8
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions datafusion/substrait/src/logical_plan/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,41 +1410,31 @@ fn to_substrait_type(
nullability,
})),
}),
DataType::Timestamp(unit, None) => {
DataType::Timestamp(unit, tz) => {
let precision = match unit {
TimeUnit::Second => 0,
TimeUnit::Millisecond => 3,
TimeUnit::Microsecond => 6,
TimeUnit::Nanosecond => 9,
};
Ok(substrait::proto::Type {
kind: Some(r#type::Kind::PrecisionTimestamp(
r#type::PrecisionTimestamp {
let kind = match tz {
None => r#type::Kind::PrecisionTimestamp(r#type::PrecisionTimestamp {
type_variation_reference: DEFAULT_TYPE_VARIATION_REF,
nullability,
precision,
}),
Some(_) => {
// If timezone is present, no matter what the actual tz value is, it indicates the
// value of the timestamp is tied to UTC epoch. That's all that Substrait cares about.
// As the timezone is lost, this conversion may be lossy for downstream use of the value.
r#type::Kind::PrecisionTimestampTz(r#type::PrecisionTimestampTz {
type_variation_reference: DEFAULT_TYPE_VARIATION_REF,
nullability,
precision,
},
)),
})
}
DataType::Timestamp(unit, Some(_)) => {
// If timezone is present, no matter what the actual tz value is, it indicates the
// value of the timestamp is tied to UTC epoch. That's all that Substrait cares about.
let precision = match unit {
TimeUnit::Second => 0,
TimeUnit::Millisecond => 3,
TimeUnit::Microsecond => 6,
TimeUnit::Nanosecond => 9,
})
}
};
Ok(substrait::proto::Type {
kind: Some(r#type::Kind::PrecisionTimestampTz(
r#type::PrecisionTimestampTz {
type_variation_reference: DEFAULT_TYPE_VARIATION_REF,
nullability,
precision,
},
)),
})
Ok(substrait::proto::Type { kind: Some(kind) })
}
DataType::Date32 => Ok(substrait::proto::Type {
kind: Some(r#type::Kind::Date(r#type::Date {
Expand Down Expand Up @@ -1883,6 +1873,7 @@ fn to_substrait_literal(
),
// If timezone is present, no matter what the actual tz value is, it indicates the
// value of the timestamp is tied to UTC epoch. That's all that Substrait cares about.
// As the timezone is lost, this conversion may be lossy for downstream use of the value.
ScalarValue::TimestampSecond(Some(t), Some(_)) => (
LiteralType::PrecisionTimestampTz(PrecisionTimestamp {
precision: 0,
Expand Down

0 comments on commit 49d90c8

Please sign in to comment.