aboutsummaryrefslogtreecommitdiff
path: root/sql/core
diff options
context:
space:
mode:
authorCheng Hao <hao.cheng@intel.com>2014-12-11 22:41:36 -0800
committerMichael Armbrust <michael@databricks.com>2014-12-11 22:41:36 -0800
commitbf40cf89e37aeaf80e37a4b0ae001ba25f819821 (patch)
tree7ff108fc6a13c558659ff1f7ec18a6b07b153791 /sql/core
parentb004150adb503ddbb54d5cd544e39ad974497c41 (diff)
downloadspark-bf40cf89e37aeaf80e37a4b0ae001ba25f819821.tar.gz
spark-bf40cf89e37aeaf80e37a4b0ae001ba25f819821.tar.bz2
spark-bf40cf89e37aeaf80e37a4b0ae001ba25f819821.zip
[SPARK-4713] [SQL] SchemaRDD.unpersist() should not raise exception if it is not persisted
Unpersist a uncached RDD, will not raise exception, for example: ``` val data = Array(1, 2, 3, 4, 5) val distData = sc.parallelize(data) distData.unpersist(true) ``` But the `SchemaRDD` will raise exception if the `SchemaRDD` is not cached. Since `SchemaRDD` is the subclasses of the `RDD`, we should follow the same behavior. Author: Cheng Hao <hao.cheng@intel.com> Closes #3572 from chenghao-intel/try_uncache and squashes the following commits: 50a7a89 [Cheng Hao] SchemaRDD.unpersist() should not raise exception if it is not persisted
Diffstat (limited to 'sql/core')
-rw-r--r--sql/core/src/main/scala/org/apache/spark/sql/SchemaRDD.scala2
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala14
2 files changed, 15 insertions, 1 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/SchemaRDD.scala b/sql/core/src/main/scala/org/apache/spark/sql/SchemaRDD.scala
index 95d73c1711..a66af602a1 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/SchemaRDD.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/SchemaRDD.scala
@@ -501,7 +501,7 @@ class SchemaRDD(
}
override def unpersist(blocking: Boolean): this.type = {
- sqlContext.uncacheQuery(this, blocking)
+ sqlContext.tryUncacheQuery(this, blocking)
this
}
}
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala
index 042210176a..cfc037caff 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala
@@ -49,6 +49,20 @@ class CachedTableSuite extends QueryTest {
uncacheTable("tempTable")
}
+ test("unpersist an uncached table will not raise exception") {
+ assert(None == lookupCachedData(testData))
+ testData.unpersist(true)
+ assert(None == lookupCachedData(testData))
+ testData.unpersist(false)
+ assert(None == lookupCachedData(testData))
+ testData.persist()
+ assert(None != lookupCachedData(testData))
+ testData.unpersist(true)
+ assert(None == lookupCachedData(testData))
+ testData.unpersist(false)
+ assert(None == lookupCachedData(testData))
+ }
+
test("cache table as select") {
sql("CACHE TABLE tempTable AS SELECT key FROM testData")
assertCached(sql("SELECT COUNT(*) FROM tempTable"))