Skip to content

Commit 320dd91

Browse files
shivbhatia10Shiv Bhatia
andauthored
Extend datatype semantic equality check to include timestamps (#17777)
* Extend datatype semantic equality to include timestamps * test * Respond to comments * cargo fmt --------- Co-authored-by: Shiv Bhatia <sbhatia@palantir.com>
1 parent 2f54f30 commit 320dd91

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

datafusion/common/src/dfschema.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,8 @@ impl DFSchema {
747747
}
748748

749749
/// Returns true of two [`DataType`]s are semantically equal (same
750-
/// name and type), ignoring both metadata and nullability, and decimal precision/scale.
750+
/// name and type), ignoring both metadata and nullability, decimal precision/scale,
751+
/// and timezone time units/timezones.
751752
///
752753
/// request to upstream: <https://github.com/apache/arrow-rs/issues/3199>
753754
pub fn datatype_is_semantically_equal(dt1: &DataType, dt2: &DataType) -> bool {
@@ -814,6 +815,10 @@ impl DFSchema {
814815
DataType::Decimal256(_l_precision, _l_scale),
815816
DataType::Decimal256(_r_precision, _r_scale),
816817
) => true,
818+
(
819+
DataType::Timestamp(_l_time_unit, _l_timezone),
820+
DataType::Timestamp(_r_time_unit, _r_timezone),
821+
) => true,
817822
_ => dt1 == dt2,
818823
}
819824
}
@@ -1811,6 +1816,15 @@ mod tests {
18111816
&DataType::Decimal256(2, 1),
18121817
));
18131818

1819+
// Any two timestamp types should match
1820+
assert!(DFSchema::datatype_is_semantically_equal(
1821+
&DataType::Timestamp(
1822+
arrow::datatypes::TimeUnit::Microsecond,
1823+
Some("UTC".into())
1824+
),
1825+
&DataType::Timestamp(arrow::datatypes::TimeUnit::Millisecond, None),
1826+
));
1827+
18141828
// Test lists
18151829

18161830
// Succeeds if both have the same element type, disregards names and nullability

0 commit comments

Comments
 (0)