Skip to content

Commit a0c9ab6

Browse files
author
Emil Ejbyfeldt
authored
[SPARK-45386][SQL]: Fix correctness issue with persist using StorageLevel.NONE on Dataset (#43188)
* SPARK-45386: Fix correctness issue with StorageLevel.NONE * Move to CacheManager * Add comment
1 parent 8f1b028 commit a0c9ab6

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

sql/core/src/main/scala/org/apache/spark/sql/execution/CacheManager.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ class CacheManager extends Logging with AdaptiveSparkPlanHelper {
113113
planToCache: LogicalPlan,
114114
tableName: Option[String],
115115
storageLevel: StorageLevel): Unit = {
116-
if (lookupCachedData(planToCache).nonEmpty) {
116+
if (storageLevel == StorageLevel.NONE) {
117+
// Do nothing for StorageLevel.NONE since it will not actually cache any data.
118+
} else if (lookupCachedData(planToCache).nonEmpty) {
117119
logWarning("Asked to cache already cached data.")
118120
} else {
119121
val sessionWithConfigsOff = getOrCloneSessionWithConfigsOff(spark)

sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import org.apache.spark.sql.functions._
4747
import org.apache.spark.sql.internal.SQLConf
4848
import org.apache.spark.sql.test.SharedSparkSession
4949
import org.apache.spark.sql.types._
50+
import org.apache.spark.storage.StorageLevel
5051

5152
case class TestDataPoint(x: Int, y: Double, s: String, t: TestDataPoint2)
5253
case class TestDataPoint2(x: Int, s: String)
@@ -2604,6 +2605,11 @@ class DatasetSuite extends QueryTest
26042605
parameters = Map("cls" -> classOf[Array[Int]].getName))
26052606
}
26062607
}
2608+
2609+
test("SPARK-45386: persist with StorageLevel.NONE should give correct count") {
2610+
val ds = Seq(1, 2).toDS().persist(StorageLevel.NONE)
2611+
assert(ds.count() == 2)
2612+
}
26072613
}
26082614

26092615
class DatasetLargeResultCollectingSuite extends QueryTest

0 commit comments

Comments
 (0)