Skip to content

Commit

Permalink
Fix NullType
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGekk committed Apr 25, 2020
1 parent 7357427 commit 67f34a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Expand Up @@ -426,7 +426,10 @@ case class In(value: Expression, list: Seq[Expression]) extends Predicate {
* 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 {
case class InSet(
child: Expression,
hset: Set[Any],
hsetElemType: Option[DataType] = None) extends UnaryExpression with Predicate {

require(hset != null, "hset could not be null")

Expand Down Expand Up @@ -520,8 +523,9 @@ case class InSet(child: Expression, hset: Set[Any]) extends UnaryExpression with

override def sql: String = {
val valueSQL = child.sql
val elemType = hsetElemType.getOrElse(child.dataType)
val listSQL = hset.toSeq
.map(elem => Literal(convertToScala(elem, child.dataType)).sql)
.map(elem => Literal(convertToScala(elem, elemType)).sql)
.mkString(", ")
s"($valueSQL IN ($listSQL))"
}
Expand Down
2 changes: 1 addition & 1 deletion sql/core/src/main/scala/org/apache/spark/sql/Column.scala
Expand Up @@ -830,7 +830,7 @@ class Column(val expr: Expression) extends Logging {
def isInCollection(values: scala.collection.Iterable[_]): Column = withExpr {
val exprValues = values.toSeq.map(lit(_).expr)
if (exprValues.size > SQLConf.get.optimizerInSetConversionThreshold) {
InSet(expr, exprValues.map(_.eval()).toSet)
InSet(expr, exprValues.map(_.eval()).toSet, exprValues.headOption.map(_.dataType))
} else {
In(expr, exprValues)
}
Expand Down

0 comments on commit 67f34a1

Please sign in to comment.