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

    https://github.com/apache/spark/pull/7893#discussion_r36212686
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
 ---
    @@ -97,32 +101,68 @@ case class Not(child: Expression)
     /**
      * Evaluates to `true` if `list` contains `value`.
      */
    -case class In(value: Expression, list: Seq[Expression]) extends Predicate 
with CodegenFallback {
    +case class In(value: Expression, list: Seq[Expression]) extends Predicate {
       override def children: Seq[Expression] = value +: list
     
    -  override def nullable: Boolean = true // TODO: Figure out correct 
nullability semantics of IN.
    +  override def nullable: Boolean = false // TODO: Figure out correct 
nullability semantics of IN.
       override def toString: String = s"$value IN ${list.mkString("(", ",", 
")")}"
     
       override def eval(input: InternalRow): Any = {
         val evaluatedValue = value.eval(input)
         list.exists(e => e.eval(input) == evaluatedValue)
       }
    -}
     
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): 
String = {
    +    val valueGen = value.gen(ctx)
    +    val listGen = list.map(_.gen(ctx))
    +    val listCode = listGen.map(x =>
    +      s"""
    +        if (!${ev.primitive}) {
    +          ${x.code}
    +          if (${ctx.genEqual(value.dataType, valueGen.primitive, 
x.primitive)}) {
    +            ${ev.primitive} = true;
    +          }
    +        }
    +       """).foldLeft("")((a, b) => a + "\n" + b)
    +    s"""
    +      ${valueGen.code}
    +      boolean ${ev.primitive} = false;
    +      boolean ${ev.isNull} = false;
    +      $listCode
    +    """
    +  }
    +}
     
     /**
      * Optimized version of In clause, when all filter values of In clause are
      * static.
      */
    -case class InSet(child: Expression, hset: Set[Any])
    -  extends UnaryExpression with Predicate with CodegenFallback {
    +case class InSet(child: Expression, hset: Set[Any]) extends 
UnaryExpression with Predicate {
     
    -  override def nullable: Boolean = true // TODO: Figure out correct 
nullability semantics of IN.
    +  override def nullable: Boolean = false // TODO: Figure out correct 
nullability semantics of IN.
       override def toString: String = s"$child INSET ${hset.mkString("(", ",", 
")")}"
     
       override def eval(input: InternalRow): Any = {
         hset.contains(child.eval(input))
       }
    +
    +  def getHSet(): Set[Any] = hset
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): 
String = {
    +    val setName = classOf[Set[Any]].getName
    +    val InSetName = classOf[InSet].getName
    +    val childGen = child.gen(ctx)
    +    ctx.references += this
    +    val hsetTerm = ctx.freshName("hset")
    +    ctx.addMutableState(setName, hsetTerm,
    +      s"$hsetTerm = (($InSetName)expressions[${ctx.references.size - 
1}]).getHSet();")
    +    s"""
    +      ${childGen.code}
    +      boolean ${ev.isNull} = false;
    +      boolean ${ev.primitive} =
    --- End diff --
    
    nit: this could fit in one line


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to