Skip to content

Commit 0dbb6d2

Browse files
authored
Merge pull request #74 from DataDog/annarose/fix_logically_equal_dict
fix: datatype_is_logically_equal for Dictionaries
2 parents 4e0bc18 + ddd0927 commit 0dbb6d2

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

datafusion/common/src/dfschema.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,12 @@ impl DFSchema {
698698
// check nested fields
699699
match (dt1, dt2) {
700700
(DataType::Dictionary(_, v1), DataType::Dictionary(_, v2)) => {
701-
v1.as_ref() == v2.as_ref()
701+
Self::datatype_is_logically_equal(v1.as_ref(), v2.as_ref())
702+
}
703+
(DataType::Dictionary(_, v1), othertype)
704+
| (othertype, DataType::Dictionary(_, v1)) => {
705+
Self::datatype_is_logically_equal(v1.as_ref(), othertype)
702706
}
703-
(DataType::Dictionary(_, v1), othertype) => v1.as_ref() == othertype,
704-
(othertype, DataType::Dictionary(_, v1)) => v1.as_ref() == othertype,
705707
(DataType::List(f1), DataType::List(f2))
706708
| (DataType::LargeList(f1), DataType::LargeList(f2))
707709
| (DataType::FixedSizeList(f1, _), DataType::FixedSizeList(f2, _)) => {
@@ -1792,6 +1794,27 @@ mod tests {
17921794
&DataType::Utf8,
17931795
&DataType::Dictionary(Box::new(DataType::Int32), Box::new(DataType::Utf8))
17941796
));
1797+
1798+
// Dictionary is logically equal to logically equivalent value type
1799+
assert!(DFSchema::datatype_is_logically_equal(
1800+
&DataType::Utf8View,
1801+
&DataType::Dictionary(Box::new(DataType::Int32), Box::new(DataType::Utf8))
1802+
));
1803+
1804+
assert!(DFSchema::datatype_is_logically_equal(
1805+
&DataType::Dictionary(
1806+
Box::new(DataType::Int32),
1807+
Box::new(DataType::List(
1808+
Field::new("element", DataType::Utf8, false).into()
1809+
))
1810+
),
1811+
&DataType::Dictionary(
1812+
Box::new(DataType::Int32),
1813+
Box::new(DataType::List(
1814+
Field::new("element", DataType::Utf8View, false).into()
1815+
))
1816+
)
1817+
));
17951818
}
17961819

17971820
#[test]

0 commit comments

Comments
 (0)