Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,25 @@ case class InSet(child: Expression, hset: Set[Any]) extends UnaryExpression with
break;
""")

val switchCode = if (caseBranches.size > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to compute caseBranches, too, if hset is empty?

    val valueGen = child.genCode(ctx)
    val switchCode = if (hset.isEmpty) {
      val caseValuesGen = hset.filter(_ != null).map(Literal(_).genCode(ctx))
      val caseBranches = caseValuesGen.map(literal =>
        code"""
          case ${literal.value}:
            ${ev.value} = true;
            break;
       """)

      code"""
        switch (${valueGen.value}) {
          ${caseBranches.mkString("\n")}
          default:
            ${ev.isNull} = $hasNull;
        }
       """
    } else {
      s"${ev.isNull} = $hasNull;"
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, can we fold this expr in the optimizer when hset is empty?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if hset is empty, the computation of caseBranches is noop, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a special case. Usually InSet wouldn't have empty set, as we have a threshold to convert In to Inset.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ur, I see.

code"""
switch (${valueGen.value}) {
${caseBranches.mkString("\n")}
default:
${ev.isNull} = $hasNull;
}
"""
} else {
s"${ev.isNull} = $hasNull;"
}

ev.copy(code =
code"""
${valueGen.code}
${CodeGenerator.JAVA_BOOLEAN} ${ev.isNull} = ${valueGen.isNull};
${CodeGenerator.JAVA_BOOLEAN} ${ev.value} = false;
if (!${valueGen.isNull}) {
switch (${valueGen.value}) {
${caseBranches.mkString("\n")}
default:
${ev.isNull} = $hasNull;
}
$switchCode
}
""")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,10 @@ class PredicateSuite extends SparkFunSuite with ExpressionEvalHelper {
assert(msg.contains("argument 1 requires boolean type"))
}
}

test("SPARK-29100: InSet with empty input set") {
val row = create_row(1)
val inSet = InSet(BoundReference(0, IntegerType, true), Set.empty)
checkEvaluation(inSet, false, row)
}
}