jayzhan211 commented on code in PR #10221:
URL: https://github.com/apache/datafusion/pull/10221#discussion_r1578683165


##########
datafusion/expr/src/type_coercion/binary.rs:
##########
@@ -643,9 +643,8 @@ fn dictionary_coercion(
             Dictionary(_lhs_index_type, lhs_value_type),
             Dictionary(_rhs_index_type, rhs_value_type),
         ) => comparison_coercion(lhs_value_type, rhs_value_type),
-        (d @ Dictionary(_, value_type), other_type)
-        | (other_type, d @ Dictionary(_, value_type))
-            if preserve_dictionaries && value_type.as_ref() == other_type =>
+        (d @ Dictionary(_, _), other_type) | (other_type, d @ Dictionary(_, _))
+            if preserve_dictionaries && can_cast_types(other_type, d) =>

Review Comment:
   If I understand correctly, we should check whether `value_type` and 
`other_type` are coercible. If yes return the new dict with new value type
   
   `Dict(k, i8) and i64 -> Dict(k, i64)`
   
   Instead of `Some(d.clone())` we should create a new dict with new value type.
   
   And, I think we should use the coerce logic in `comparison_coercion` not 
`can_cast_types`, because the logic is not totally the same.
   
   ```rust
           | (other_type, d @ Dictionary(key_type, value_type))
               if preserve_dictionaries && 
comparison_coercion(value_type.as_ref(), other_type).is_some() =>
           {
               let new_value = comparison_coercion(&value_type, 
other_type).unwrap();
               Some(DataType::Dictionary(key_type.clone(), Box::new(new_value)))
           }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to