You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/08/23 06:46:01 UTC

[GitHub] [spark] cfmcgrady commented on a diff in pull request #37439: [SPARK-39896][SQL] UnwrapCastInBinaryComparison should work when the literal of In/InSet downcast failed

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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/UnwrapCastInBinaryComparison.scala:
##########
@@ -155,7 +155,16 @@ object UnwrapCastInBinaryComparison extends Rule[LogicalPlan] {
       list.foreach {
         case lit @ Literal(null, _) => nullList += lit
         case lit @ NonNullLiteral(_, _) =>
-          unwrapCast(EqualTo(in.value, lit)) match {
+          val originalEqualTo = EqualTo(in.value, lit)
+          unwrapCast(originalEqualTo) match {
+            // the function `unwrapCast` may returns original expression when 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 equalTo: EqualTo if equalTo == originalEqualTo &&
+              Cast(lit, fromExp.dataType).eval() == null =>

Review Comment:
   if `Cast(lit, fromExp.dataType).eval()` is not equal to `null`, then the return expression of `unwrapCast` should be either `EqualTo(fromExp, lit)` or `falseIfNotNull(fromExp)` which was handled by L168-L169.
   
   https://github.com/apache/spark/blob/5a71a7f7b5c1762677ddbfe39a7c35d645c25e94/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/UnwrapCastInBinaryComparison.scala#L305-L346
   
   > we may have a return value from L322, L331 or L340.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org