Skip to content

Commit ade5232

Browse files
hareshkhshivbhatia10Shiv Bhatiaalamb
authored
[branch-50] Extend datatype semantic equality check to include timestamps (#17777) (#18129)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Related to #17776 - Related to #18072 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> If I've understood semantic equality correctly, any two timestamps should meet the bar for equality regardless of time units and timezones, but the current code doesn't reflect that. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> Adds a branch to this method for timestamps. ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Yes ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> Yes <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> --------- Co-authored-by: Shiv Bhatia <shivbhatia10@gmail.com> Co-authored-by: Shiv Bhatia <sbhatia@palantir.com> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
1 parent e3f8e37 commit ade5232

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

datafusion/common/src/dfschema.rs

Lines changed: 14 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 {
@@ -806,6 +807,10 @@ impl DFSchema {
806807
DataType::Decimal256(_l_precision, _l_scale),
807808
DataType::Decimal256(_r_precision, _r_scale),
808809
) => true,
810+
(
811+
DataType::Timestamp(_l_time_unit, _l_timezone),
812+
DataType::Timestamp(_r_time_unit, _r_timezone),
813+
) => true,
809814
_ => dt1 == dt2,
810815
}
811816
}
@@ -1596,6 +1601,14 @@ mod tests {
15961601
&DataType::Int16
15971602
));
15981603

1604+
// Any two timestamp types should match
1605+
assert!(DFSchema::datatype_is_semantically_equal(
1606+
&DataType::Timestamp(
1607+
arrow::datatypes::TimeUnit::Microsecond,
1608+
Some("UTC".into())
1609+
),
1610+
&DataType::Timestamp(arrow::datatypes::TimeUnit::Millisecond, None),
1611+
));
15991612
// Test lists
16001613

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

0 commit comments

Comments
 (0)