alamb commented on issue #22142:
URL: https://github.com/apache/datafusion/issues/22142#issuecomment-4722841439

   The original optimization was based on Spark's  
`UnwrapCastInBinaryComparison` as I recall: 
https://github.com/apache/spark/blob/a6e3fdd504cbff4dff739801e0b0b0f2b6402502/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/UnwrapCastInBinaryComparison.scala#L30-L101
   
   It seems that that code has a 2 layer check, 
   
   
   Layer 1: first on data types
   
https://github.com/apache/spark/blob/a6e3fdd504cbff4dff739801e0b0b0f2b6402502/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/UnwrapCastInBinaryComparison.scala#L462-L485
   
   Layer 2: checks if the literal can be casted losslessly
   
https://github.com/apache/spark/blob/a6e3fdd504cbff4dff739801e0b0b0f2b6402502/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/UnwrapCastInBinaryComparison.scala#L112
   
https://github.com/apache/spark/blob/a6e3fdd504cbff4dff739801e0b0b0f2b6402502/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/UnwrapCastInBinaryComparison.scala#L282-L340
   
   This seems somewhat equivalent to `try_cast_literal_to_type` 
https://github.com/apache/datafusion/blob/eedae1154bf2745ea6d025f3e55901db1d8b7fb7/datafusion/expr-common/src/casts.rs#L59-L58
   
   So it seems to me that DataFusion is  missing the Layer 1 check, and it 
seems like your PR in https://github.com/apache/datafusion/pull/22837 is adding 
this check. 
   
   So in my opinion, we should proceed with 
https://github.com/apache/datafusion/pull/22837 and I will do so
    


-- 
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