Repository: spark
Updated Branches:
  refs/heads/branch-2.2 0f060a251 -> 71d1cb6a4


[SPARK-22249][SQL] isin with empty list throws exception on cached DataFrame

## What changes were proposed in this pull request?

As pointed out in the JIRA, there is a bug which causes an exception to be 
thrown if `isin` is called with an empty list on a cached DataFrame. The PR 
fixes it.

## How was this patch tested?

Added UT.

Author: Marco Gaido <marcogaid...@gmail.com>

Closes #19494 from mgaido91/SPARK-22249.

(cherry picked from commit 8148f19ca1f0e0375603cb4f180c1bad8b0b8042)
Signed-off-by: Sean Owen <so...@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/71d1cb6a
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/71d1cb6a
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/71d1cb6a

Branch: refs/heads/branch-2.2
Commit: 71d1cb6a432bd4d24a1d5fe53bb970902dd268b9
Parents: 0f060a2
Author: Marco Gaido <marcogaid...@gmail.com>
Authored: Tue Oct 17 09:41:23 2017 +0200
Committer: Sean Owen <so...@cloudera.com>
Committed: Tue Oct 17 09:41:42 2017 +0200

----------------------------------------------------------------------
 .../execution/columnar/InMemoryTableScanExec.scala   |  1 +
 .../columnar/InMemoryColumnarQuerySuite.scala        | 15 +++++++++++++++
 2 files changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/71d1cb6a/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/InMemoryTableScanExec.scala
----------------------------------------------------------------------
diff --git 
a/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/InMemoryTableScanExec.scala
 
b/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/InMemoryTableScanExec.scala
index 7063b08..e792a45 100644
--- 
a/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/InMemoryTableScanExec.scala
+++ 
b/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/InMemoryTableScanExec.scala
@@ -102,6 +102,7 @@ case class InMemoryTableScanExec(
     case IsNull(a: Attribute) => statsFor(a).nullCount > 0
     case IsNotNull(a: Attribute) => statsFor(a).count - statsFor(a).nullCount 
> 0
 
+    case In(_: AttributeReference, list: Seq[Expression]) if list.isEmpty => 
Literal.FalseLiteral
     case In(a: AttributeReference, list: Seq[Expression]) if 
list.forall(_.isInstanceOf[Literal]) =>
       list.map(l => statsFor(a).lowerBound <= l.asInstanceOf[Literal] &&
         l.asInstanceOf[Literal] <= statsFor(a).upperBound).reduce(_ || _)

http://git-wip-us.apache.org/repos/asf/spark/blob/71d1cb6a/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/InMemoryColumnarQuerySuite.scala
----------------------------------------------------------------------
diff --git 
a/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/InMemoryColumnarQuerySuite.scala
 
b/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/InMemoryColumnarQuerySuite.scala
index 109b1d9..67cff51 100644
--- 
a/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/InMemoryColumnarQuerySuite.scala
+++ 
b/sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/InMemoryColumnarQuerySuite.scala
@@ -429,4 +429,19 @@ class InMemoryColumnarQuerySuite extends QueryTest with 
SharedSQLContext {
       checkAnswer(agg_without_cache, agg_with_cache)
     }
   }
+
+  test("SPARK-22249: IN should work also with cached DataFrame") {
+    val df = spark.range(10).cache()
+    // with an empty list
+    assert(df.filter($"id".isin()).count() == 0)
+    // with a non-empty list
+    assert(df.filter($"id".isin(2)).count() == 1)
+    assert(df.filter($"id".isin(2, 3)).count() == 2)
+    df.unpersist()
+    val dfNulls = spark.range(10).selectExpr("null as id").cache()
+    // with null as value for the attribute
+    assert(dfNulls.filter($"id".isin()).count() == 0)
+    assert(dfNulls.filter($"id".isin(2, 3)).count() == 0)
+    dfNulls.unpersist()
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to