Skip to content

Commit f47e74d

Browse files
use coercion_comparison instead of can_cast_types
1 parent 7fe8eeb commit f47e74d

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

datafusion/expr/src/type_coercion/binary.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -638,21 +638,26 @@ fn dictionary_coercion(
638638
preserve_dictionaries: bool,
639639
) -> Option<DataType> {
640640
use arrow::datatypes::DataType::*;
641+
let maybe_preserve_dictionaries =
642+
|index_type: &DataType, value_type: DataType| -> DataType {
643+
if preserve_dictionaries {
644+
Dictionary(Box::new(index_type.clone()), Box::new(value_type))
645+
} else {
646+
value_type
647+
}
648+
};
641649
match (lhs_type, rhs_type) {
642650
(
643651
Dictionary(_lhs_index_type, lhs_value_type),
644652
Dictionary(_rhs_index_type, rhs_value_type),
645653
) => comparison_coercion(lhs_value_type, rhs_value_type),
646-
(d @ Dictionary(_, _), other_type) | (other_type, d @ Dictionary(_, _))
647-
if preserve_dictionaries && can_cast_types(other_type, d) =>
648-
{
649-
Some(d.clone())
650-
}
651-
(Dictionary(_index_type, value_type), _) => {
654+
(Dictionary(index_type, value_type), _) => {
652655
comparison_coercion(value_type, rhs_type)
656+
.map(|new_type| maybe_preserve_dictionaries(index_type, new_type))
653657
}
654-
(_, Dictionary(_index_type, value_type)) => {
658+
(_, Dictionary(index_type, value_type)) => {
655659
comparison_coercion(lhs_type, value_type)
660+
.map(|new_type| maybe_preserve_dictionaries(index_type, new_type))
656661
}
657662
_ => None,
658663
}

0 commit comments

Comments
 (0)