Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8492#discussion_r38225619
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
 ---
    @@ -145,46 +143,42 @@ case class ArrayContains(left: Expression, right: 
Expression)
         }
       }
     
    -  override def nullable: Boolean = false
    +  override def nullable: Boolean = {
    +    left.nullable || right.nullable || 
left.dataType.asInstanceOf[ArrayType].containsNull
    +  }
     
    -  override def eval(input: InternalRow): Boolean = {
    -    val arr = left.eval(input)
    -    if (arr == null) {
    -      false
    -    } else {
    -      val value = right.eval(input)
    -      if (value == null) {
    -        false
    -      } else {
    -        arr.asInstanceOf[ArrayData].foreach(right.dataType, (i, v) =>
    -          if (v == value) return true
    -        )
    -        false
    +  override def nullSafeEval(arr: Any, value: Any): Any = {
    +    var hasNull = false
    +    arr.asInstanceOf[ArrayData].foreach(right.dataType, (i, v) =>
    +      if (v == null) {
    +        hasNull = true
    +      } else if (v == value) {
    +        return true
           }
    +    )
    +    if (hasNull) {
    +      null
    +    } else {
    +      false
         }
       }
     
       override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): 
String = {
    -    val arrGen = left.gen(ctx)
    -    val elementGen = right.gen(ctx)
    -    val i = ctx.freshName("i")
    -    val getValue = ctx.getValue(arrGen.primitive, right.dataType, i)
    -    s"""
    -      ${arrGen.code}
    -      boolean ${ev.isNull} = false;
    -      boolean ${ev.primitive} = false;
    -      if (!${arrGen.isNull}) {
    -        ${elementGen.code}
    -        if (!${elementGen.isNull}) {
    -          for (int $i = 0; $i < ${arrGen.primitive}.numElements(); $i ++) {
    -            if (${ctx.genEqual(right.dataType, elementGen.primitive, 
getValue)}) {
    -              ${ev.primitive} = true;
    -              break;
    -            }
    -          }
    +    nullSafeCodeGen(ctx, ev, (arr, value) => {
    --- End diff --
    
    Do we need to call {defineCodeGen}?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to