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


##########
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:
   As the comment shown in L149 ~ L153
   
   > There are 3 kinds of literals in the in.list:
   > 1. null literals
   > 2. The literals that can cast to fromExp.dataType
   > 3. The literals that cannot cast to fromExp.dataType
   
   for 3, we have tow cases.
   
   - A. the literal cannot cast to fromExp.dataType, and there is no min/max 
for the `fromType`, then `unwrapCast` returns None
   
   for instance:
   
   ```
   cast(input[2, decimal(5,2), true] as decimal(10,4)) = 123456.1234
   ```
   
   
   - B. the literal `value` is out of `fromType` range `(min, max)`, then 
`unwrapCast` returns `falseIfNotNull(fromExp)`
   
   for instance:
   
   ```
   cast(input[0, smallint, true] as bigint) = 2147483647
   ```
   



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