Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/9889#discussion_r45824179
--- Diff: sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala
---
@@ -213,6 +215,56 @@ class DatasetSuite extends QueryTest with
SharedSQLContext {
}
+ test("persist and unpersist") {
+ val ds = Seq(("a", 1) , ("b", 2), ("c", 3)).toDS().select(expr("_2 +
1").as[Int])
+ val cached = ds.cache()
+ // count triggers the caching action. It should not throw.
+ cached.count()
+ // Make sure, the Dataset is indeed cached.
+ assert(sqlContext.cacheManager.lookupCachedData(cached).nonEmpty)
+ assertResult(1, "InMemoryRelation not found, testData should have been
cached") {
+ cached.queryExecution.withCachedData.collect {
+ case r: InMemoryRelation => r
+ }.size
+ }
+ // Check result.
+ checkAnswer(
+ cached,
+ 2, 3, 4)
+ // Drop the cache.
+ cached.unpersist()
+ }
+
+ test("persist and then rebind right encoder when join 2 datasets") {
+ val ds1 = Seq("1", "2").toDS().as("a")
+ val ds2 = Seq(2, 3).toDS().as("b")
+
+ ds1.persist()
+ ds2.persist()
+
+ val joined = ds1.joinWith(ds2, $"a.value" === $"b.value")
+ checkAnswer(joined, ("2", 2))
+
+ ds1.unpersist()
+ ds2.unpersist()
+ }
+
+ test("persist and then groupBy columns asKey, map") {
+ val ds = Seq(("a", 10), ("a", 20), ("b", 1), ("b", 2), ("c", 1)).toDS()
+ ds.persist()
+
+ val grouped = ds.groupBy($"_1").keyAs[String]
+ val agged = grouped.mapGroup { case (g, iter) => (g,
iter.map(_._2).sum) }
+ agged.persist()
--- End diff --
Its a little odd to have a test that persists more than one point in the
lineage, unless you are explicitly testing that only the latests possible set
of materialized data is being used.
---
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]