cfmcgrady commented on code in PR #37439:
URL: https://github.com/apache/spark/pull/37439#discussion_r955632072


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/UnwrapCastInBinaryComparison.scala:
##########
@@ -156,29 +157,36 @@ object UnwrapCastInBinaryComparison extends 
Rule[LogicalPlan] {
         case lit @ Literal(null, _) => nullList += lit
         case lit @ NonNullLiteral(_, _) =>
           unwrapCast(EqualTo(in.value, lit)) match {
-            case EqualTo(_, unwrapLit: Literal) => canCastList += unwrapLit
-            case e @ And(IsNull(_), Literal(null, BooleanType)) => 
cannotCastList += e
+            // the function `unwrapCast` returns None means the literal can 
not cast to fromType,
+            // for instance: (the boundreference is of type DECIMAL(5,2))
+            //     CAST(boundreference() AS DECIMAL(10,4)) = 123456.1234BD
+            // Due to `cast(lit, fromExp.dataType) == null` we simply return
+            // `falseIfNotNull(fromExp)`.
+            case None | Some(And(IsNull(_), Literal(null, BooleanType))) =>

Review Comment:
   Actually, I missed another case before.
   - C. the literal value is rounded up/down after casting to `fromType`, for 
instance:
   ```
   cast(input[1, float, true] as double) = 3.14
   ```
    note that 3.14 will be rounded to 3.14000010... after casting to float
   



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