Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18455#discussion_r125486277
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
 ---
    @@ -274,24 +278,32 @@ case class InSet(child: Expression, hset: Set[Any]) 
extends UnaryExpression with
         }
       }
     
    -  def getHSet(): Set[Any] = hset
    +  @transient private[this] lazy val set = child.dataType match {
    +    case _: StructType =>
    +      // for structs use interpreted ordering to be able to compare 
UnsafeRows with non-UnsafeRows
    +      TreeSet.empty (TypeUtils.getInterpretedOrdering (child.dataType) ) 
++ hset
    +    case _ => hset
    +  }
    +
    +  def getSet(): Set[Any] = set
     
       override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
         val setName = classOf[Set[Any]].getName
         val InSetName = classOf[InSet].getName
         val childGen = child.genCode(ctx)
         ctx.references += this
    -    val hsetTerm = ctx.freshName("hset")
    +    val setTerm = ctx.freshName("set")
         val hasNullTerm = ctx.freshName("hasNull")
    -    ctx.addMutableState(setName, hsetTerm,
    -      s"$hsetTerm = (($InSetName)references[${ctx.references.size - 
1}]).getHSet();")
    -    ctx.addMutableState("boolean", hasNullTerm, s"$hasNullTerm = 
$hsetTerm.contains(null);")
    +    ctx.addMutableState(setName, setTerm,
    +      s"$setTerm = (($InSetName)references[${ctx.references.size - 
1}]).getSet();")
    +    ctx.addMutableState("boolean", hasNullTerm,
    +      s"$hasNullTerm = ${if (hasNull) "true" else "false"};")
         ev.copy(code = s"""
           ${childGen.code}
           boolean ${ev.isNull} = ${childGen.isNull};
           boolean ${ev.value} = false;
           if (!${ev.isNull}) {
    -        ${ev.value} = $hsetTerm.contains(${childGen.value});
    +        ${ev.value} = $setTerm.contains(${childGen.value});
             if (!${ev.value} && $hasNullTerm) {
    --- End diff --
    
    ```
    val setNull = if (hasNull) {
      s"""
        if (!${ev.value}) {
          ${ev.isNull} = true;
        }
      """
    } else {
      ""
    }
    ```
    Then we can  just write `$setNull` here.


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