Github user cloud-fan commented on a diff in the pull request: https://github.com/apache/spark/pull/22315#discussion_r214647587 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala --- @@ -1464,17 +1464,33 @@ case class ArrayContains(left: Expression, right: Expression) nullSafeCodeGen(ctx, ev, (arr, value) => { val i = ctx.freshName("i") val getValue = CodeGenerator.getValue(arr, right.dataType, i) - s""" - for (int $i = 0; $i < $arr.numElements(); $i ++) { - if ($arr.isNullAt($i)) { - ${ev.isNull} = true; - } else if (${ctx.genEqual(right.dataType, value, getValue)}) { - ${ev.isNull} = false; - ${ev.value} = true; - break; - } + def checkAndSetIsNullCode(body: String) = if (nullable) { + s""" + |if ($arr.isNullAt($i)) { + | ${ev.isNull} = true; + |} else { + | $body + |} + """.stripMargin + } else { + body } - """ + val unsetIsNullCode = if (nullable) s"${ev.isNull} = false;" else "" + val code = checkAndSetIsNullCode( --- End diff -- This seems too complicated to save a few duplicated code, how about ``` val loopBody = if (nullable) { s""" |if ($arr.isNullAt($i)) { | ${ev.isNull} = true; |} else ... """ } else { s""" |if (${ctx.genEqual(right.dataType, value, getValue)}) {... """ } ```
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org