You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "liukuijian8040 (via GitHub)" <gi...@apache.org> on 2023/05/18 01:53:30 UTC

[GitHub] [spark] liukuijian8040 commented on a diff in pull request #41162: [SPARK-43491][SQL] In expression should act as same as EqualTo when elements in IN expression have same DataType.

liukuijian8040 commented on code in PR #41162:
URL: https://github.com/apache/spark/pull/41162#discussion_r1197258991


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala:
##########
@@ -509,16 +509,25 @@ case class In(value: Expression, list: Seq[Expression]) extends Predicate {
     val valueArg = ctx.freshName("valueArg")
     // All the blocks are meant to be inside a do { ... } while (false); loop.
     // The evaluation of variables can be stopped when we find a matching value.
-    val listCode = listGen.map(x =>
-      s"""
-         |${x.code}
-         |if (${x.isNull}) {
-         |  $tmpResult = $HAS_NULL; // ${ev.isNull} = true;
-         |} else if (${ctx.genEqual(value.dataType, valueArg, x.value)}) {
-         |  $tmpResult = $MATCHED; // ${ev.isNull} = false; ${ev.value} = true;
-         |  continue;
-         |}
-       """.stripMargin)
+    val listCode = listGen.map { x =>
+      val codeIf =
+        s"""
+           |${x.code}
+           |if (${x.isNull}) {
+           |  $tmpResult = $HAS_NULL; // ${ev.isNull} = true;
+           |}
+         """.stripMargin
+      val codeElseIf =
+        if (!java.lang.Boolean.parseBoolean(x.isNull.toString)) {

Review Comment:
   `x.null` is a `ExprCode` type. and toString returns code string. So, there are three cases:
   a. code is a variable name of the Boolean type, for example, if (varArg_0)
   b. code is false, if (false)
   c. code is true, if (true)
   The `else if` branch does not need to be generated when isNull is set to true.
    
   ![image](https://github.com/apache/spark/assets/132866841/9e133749-30f7-4644-8d56-ede17bea7ff4)
   



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