spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davies <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-10323] [SQL] fix nullability of In/InSe...
Date Fri, 28 Aug 2015 18:30:58 GMT
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8492#discussion_r38229646
  
    --- 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 --
    
    nullSafeCodeGen is similar to 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message