linhongliu-db commented on code in PR #59890:
URL: https://github.com/apache/spark/pull/59890#discussion_r4426432615
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/CacheManager.scala:
##########
@@ -649,11 +666,13 @@ class CacheManager extends Logging with
AdaptiveSparkPlanHelper {
plan: LogicalPlan,
fs: FileSystem,
qualifiedPath: Path,
- includeTimeTravel: Boolean): Boolean = {
+ includeTimeTravel: Boolean,
+ refreshedIndexes: JSet[FileIndex]): Boolean = {
Review Comment:
Updated in 21319a61599: the ScalaDoc now describes the single-node V1/V2
check, per-call identity deduplication, time-travel exclusion, and true return
for an already refreshed match. For the subquery scope question, I kept the
existing operator-tree traversal and documented that scope in both the source
comment and PR description. Expanding refresh selection to subquery expressions
would be a separate behavior change.
##########
sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala:
##########
@@ -855,6 +856,133 @@ class CachedTableSuite extends SharedSparkSession
}
}
+ private def appendParquetWithoutRefresh(path: String, value: Long): Unit = {
+ withTempDir { staging =>
+ val output = new File(staging, "data")
+ spark.range(value, value + 1).write.parquet(output.getCanonicalPath)
+ // Move files externally so Spark does not refresh the destination
before refreshByPath.
+ output.listFiles().filter(_.getName.endsWith(".parquet")).foreach { file
=>
+ Files.move(file.toPath, new File(path, file.getName).toPath)
+ }
+ }
+ }
+
+ for {
+ useV1SourceList <- Seq("parquet", "")
+ relationCount <- Seq(1, 2, 3)
+ } {
+ val sourceVersion = if (useV1SourceList.nonEmpty) "V1" else "V2"
+ test(s"refreshByPath refreshes all $relationCount file indexes in one
cached plan " +
+ s"($sourceVersion)") {
+ withSQLConf(SQLConf.USE_V1_SOURCE_LIST.key -> useV1SourceList) {
+ withTempDir { dir =>
+ val paths = (0 until relationCount).map(i => new File(dir,
s"part$i").getCanonicalPath)
+ paths.foreach(path => spark.range(1).write.parquet(path))
+ val cached =
paths.map(spark.read.parquet(_)).reduce(_.union(_)).cache()
+ try {
+ // Check the analyzed relations so a V2 fallback cannot silently
test only V1.
+ val fileSources = cached.queryExecution.analyzed.collect {
+ case LogicalRelationWithTable(_: HadoopFsRelation, _) => "V1"
+ case DataSourceV2Relation(_: FileTable, _, _, _, _, _) => "V2"
+ }
+ assert(fileSources == Seq.fill(relationCount)(sourceVersion))
+ assert(cached.count() == relationCount)
+ paths.foreach(path => appendParquetWithoutRefresh(path, 1L))
+ assert(cached.count() == relationCount)
+ spark.catalog.refreshByPath(dir.getCanonicalPath)
Review Comment:
Added in 21319a61599: a cached union with a matching first read and an
unrelated trailing read. Files are appended externally under both paths;
refreshing the first path updates its rows and refresh count while leaving the
unrelated index and cached rows unchanged, including on a repeated refresh. The
test fails when the traversal overwrites the selection flag on every node. All
11 refreshByPath tests and 10 time-travel cache tests pass, along with SQL
source/test style checks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]