Skip to content

Apache DataFusion SQL Query Engine

fix: datatype_is_logically_equal for dictionaries (#20153)

Anna-Rose Lescured46015af6f50
diff --git a/datafusion/common/src/dfschema.rs b/datafusion/common/src/dfschema.rs
index f67e7e4517..de0aacf9e8 100644
--- a/datafusion/common/src/dfschema.rs
+++ b/datafusion/common/src/dfschema.rs
@@ -698,10 +698,12 @@ impl DFSchema {
// check nested fields
match (dt1, dt2) {
(DataType::Dictionary(_, v1), DataType::Dictionary(_, v2)) => {
- v1.as_ref() == v2.as_ref()
+ Self::datatype_is_logically_equal(v1.as_ref(), v2.as_ref())
+ }
+ (DataType::Dictionary(_, v1), othertype)
+ | (othertype, DataType::Dictionary(_, v1)) => {
+ Self::datatype_is_logically_equal(v1.as_ref(), othertype)
}
- (DataType::Dictionary(_, v1), othertype) => v1.as_ref() == othertype,
- (othertype, DataType::Dictionary(_, v1)) => v1.as_ref() == othertype,
(DataType::List(f1), DataType::List(f2))
| (DataType::LargeList(f1), DataType::LargeList(f2))
| (DataType::FixedSizeList(f1, _), DataType::FixedSizeList(f2, _)) => {
@@ -1798,6 +1800,27 @@ mod tests {
&DataType::Utf8,
&DataType::Dictionary(Box::new(DataType::Int32), Box::new(DataType::Utf8))
));
+
+ // Dictionary is logically equal to the logically equivalent value type
+ assert!(DFSchema::datatype_is_logically_equal(
+ &DataType::Utf8View,
+ &DataType::Dictionary(Box::new(DataType::Int32), Box::new(DataType::Utf8))
+ ));
+
+ assert!(DFSchema::datatype_is_logically_equal(
+ &DataType::Dictionary(
+ Box::new(DataType::Int32),
+ Box::new(DataType::List(
+ Field::new("element", DataType::Utf8, false).into()
+ ))
+ ),
+ &DataType::Dictionary(
+ Box::new(DataType::Int32),
+ Box::new(DataType::List(
+ Field::new("element", DataType::Utf8View, false).into()
+ ))
+ )
+ ));
}
#[test]