Skip to content
Merged
Changes from 1 commit
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
36 changes: 35 additions & 1 deletion 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 @@ -806,6 +807,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 @@ -1596,6 +1601,35 @@ mod tests {
&DataType::Int16
));

// Succeeds if decimal precision and scale are different
assert!(DFSchema::datatype_is_semantically_equal(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these decimal tests appear to have been backported from main without the corresponding code. I will remove them

&DataType::Decimal32(1, 2),
&DataType::Decimal32(2, 1),
));

assert!(DFSchema::datatype_is_semantically_equal(
&DataType::Decimal64(1, 2),
&DataType::Decimal64(2, 1),
));

assert!(DFSchema::datatype_is_semantically_equal(
&DataType::Decimal128(1, 2),
&DataType::Decimal128(2, 1),
));

assert!(DFSchema::datatype_is_semantically_equal(
&DataType::Decimal256(1, 2),
&DataType::Decimal256(2, 1),
));

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

// Succeeds if both have the same element type, disregards names and nullability
Expand Down
Loading