Skip to content

Commit 3d721b1

Browse files
authored
[Spark] Make partition-like skipping respect skipping stats disablement (#6751)
#### Which Delta project/connector is this regarding? - [x] Spark - [ ] Standalone - [ ] Flink - [ ] Kernel - [ ] Other (fill in here) ## Description Today, partition-like skipping doesn't respect skipping stats disablement, and would use stats for skipping even when this conf is off. This PR fixes it to respect the conf. ## How was this patch tested? See test change. ## Does this PR introduce _any_ user-facing changes? No.
1 parent 48ba860 commit 3d721b1

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

spark/src/main/scala/org/apache/spark/sql/delta/stats/DataSkippingReader.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ trait DataSkippingReaderBase
763763
// rough heuristic, require the table to no longer be considered a "small delta table."
764764
// 3. At least 1 data filter was not already used for data skipping.
765765
val shouldRewriteDataFiltersAsPartitionLike =
766-
spark.conf.get(DeltaSQLConf.DELTA_DATASKIPPING_PARTITION_LIKE_FILTERS_ENABLED) &&
766+
useStats &&
767+
spark.conf.get(DeltaSQLConf.DELTA_DATASKIPPING_PARTITION_LIKE_FILTERS_ENABLED) &&
767768
ClusteredTableUtils.isSupported(snapshotToScan.protocol) &&
768769
snapshotToScan.numOfFilesIfKnown.exists(_ >=
769770
spark.conf.get(DeltaSQLConf.DELTA_DATASKIPPING_PARTITION_LIKE_FILTERS_THRESHOLD)) &&

spark/src/test/scala/org/apache/spark/sql/delta/stats/PartitionLikeDataSkippingSuite.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,28 @@ trait PartitionLikeDataSkippingSuiteBase
448448
minNumFilesToApply = 1L)
449449
}
450450
}
451+
452+
test("partition-like skipping disabled when data skipping stats use is disabled") {
453+
withSQLConf(
454+
DeltaSQLConf.DELTA_STATS_SKIPPING.key -> "false",
455+
DeltaSQLConf.DELTA_DATASKIPPING_PARTITION_LIKE_FILTERS_ENABLED.key -> "true",
456+
DeltaSQLConf.DELTA_DATASKIPPING_PARTITION_LIKE_FILTERS_THRESHOLD.key -> "0") {
457+
// We can't test this E2E via a read (as `PrepareDeltaScan` will avoid file skipping when
458+
// stats collection is disabled), so we have to test this directly by invoking `filesForScan`
459+
// to simulate file skipping that might occur by another caller.
460+
val df = sql(
461+
s"SELECT * FROM $testTableName " +
462+
"WHERE LOWER(CONCAT('AAA', s.b)) = 'aaa1971-01-31 17:01:01.001'")
463+
val predicates = df.queryExecution.optimizedPlan.collect {
464+
case Filter(condition, _) => condition
465+
}.flatMap(splitConjunctivePredicates)
466+
val scanResult = DeltaLog.forTable(spark, TableIdentifier(testTableName))
467+
.update().filesForScan(predicates)
468+
assert(scanResult.files.length == 22)
469+
assert(scanResult.unusedFilters.nonEmpty)
470+
assert(scanResult.partitionLikeDataFilters.size == 0)
471+
}
472+
}
451473
}
452474

453475
class PartitionLikeDataSkippingSuite extends PartitionLikeDataSkippingSuiteBase

0 commit comments

Comments
 (0)