Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions datafusion/common/src/dfschema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@ impl DFSchema {
}

/// Returns true of two [`DataType`]s are semantically equal (same
/// name and type), ignoring both metadata and nullability, and decimal precision/scale.
/// name and type), ignoring both metadata and nullability, decimal precision/scale,
/// and timezone time units/timezones.
///
/// request to upstream: <https://github.com/apache/arrow-rs/issues/3199>
pub fn datatype_is_semantically_equal(dt1: &DataType, dt2: &DataType) -> bool {
Expand Down Expand Up @@ -814,6 +815,10 @@ impl DFSchema {
DataType::Decimal256(_l_precision, _l_scale),
DataType::Decimal256(_r_precision, _r_scale),
) => true,
(
DataType::Timestamp(_l_time_unit, _l_timezone),
DataType::Timestamp(_r_time_unit, _r_timezone),
) => true,
_ => dt1 == dt2,
}
}
Expand Down Expand Up @@ -1327,6 +1332,7 @@ pub fn qualified_name(qualifier: Option<&TableReference>, name: &str) -> String

#[cfg(test)]
mod tests {
use arrow::datatypes::TimeUnit;
use crate::assert_contains;

use super::*;
Expand Down Expand Up @@ -1811,6 +1817,12 @@ mod tests {
&DataType::Decimal256(2, 1),
));

// Any two timestamp types should match
assert!(DFSchema::datatype_is_semantically_equal(
&DataType::Timestamp(TimeUnit::Microsecond, Some("UTC".into())),
&DataType::Timestamp(TimeUnit::Millisecond, None),
));

// Test lists

// Succeeds if both have the same element type, disregards names and nullability
Expand Down Expand Up @@ -2106,7 +2118,7 @@ mod tests {
Field::new(
"timestamp_field",
DataType::Timestamp(
arrow::datatypes::TimeUnit::Microsecond,
TimeUnit::Microsecond,
Some("UTC".into()),
),
false,
Expand Down Expand Up @@ -2402,12 +2414,12 @@ mod tests {
Field::new("date64", DataType::Date64, false),
Field::new(
"time32_seconds",
DataType::Time32(arrow::datatypes::TimeUnit::Second),
DataType::Time32(TimeUnit::Second),
true,
),
Field::new(
"time64_nanoseconds",
DataType::Time64(arrow::datatypes::TimeUnit::Nanosecond),
DataType::Time64(TimeUnit::Nanosecond),
false,
),
]
Expand Down
Loading