@@ -638,21 +638,26 @@ fn dictionary_coercion(
638
638
preserve_dictionaries : bool ,
639
639
) -> Option < DataType > {
640
640
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
+ } ;
641
649
match ( lhs_type, rhs_type) {
642
650
(
643
651
Dictionary ( _lhs_index_type, lhs_value_type) ,
644
652
Dictionary ( _rhs_index_type, rhs_value_type) ,
645
653
) => 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) , _) => {
652
655
comparison_coercion ( value_type, rhs_type)
656
+ . map ( |new_type| maybe_preserve_dictionaries ( index_type, new_type) )
653
657
}
654
- ( _, Dictionary ( _index_type , value_type) ) => {
658
+ ( _, Dictionary ( index_type , value_type) ) => {
655
659
comparison_coercion ( lhs_type, value_type)
660
+ . map ( |new_type| maybe_preserve_dictionaries ( index_type, new_type) )
656
661
}
657
662
_ => None ,
658
663
}
0 commit comments