[SPARK-60486][SQL] Preserve Python UDF partition filters after V2 pushdown #59732
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.45) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 453 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.366
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #59732"
general
weight: 0.35
szehon-ho
What changes were proposed in this pull request?
Preserve partition predicates rejected by
FileScanBuilderas post-scan filters. Python UDFs remain excluded from partition pruning, while their predicates remain available for subsequent Python UDF extraction and evaluation.Extend the existing shared PySpark DSv2 UDF regression with a partitioned input and exact-row checks for a partition UDF,
AND, andOR. Add a SQL migration note for the corrected results.Why are the changes needed?
SPARK-60486 reports incorrect results when filtering partitioned files through Data Source V2 with Python UDFs. The pruning guard added by SPARK-48666 removes such predicates from the pushed partition filters, but the returned post-scan filters currently omit them as well. The scan can therefore return rows that do not satisfy the original filter.
For example, after writing six rows with
i = 0..5and partition columnp = i % 3, filtering a V2 Parquet read withudf(lambda p: p == 1, "boolean")("p")returns all six rows on the unmodified master. It should return only(i=1, p=1)and(i=4, p=1).Does this PR introduce _any_ user-facing change?
Yes. Affected Data Source V2 file queries now apply the Python UDF filter and exclude rows that were incorrectly retained. This was independently reproduced on released Spark 4.2.0 and current master; this PR targets master. Built-in Parquet/ORC file reads use the V1 path by default through
spark.sql.sources.useV1SourceList; the affected queries are those routed to Data Source V2. The V1 path already evaluates these predicates after the scan.How was this patch tested?
PruneFileSourcePartitionsSuite: 9/9 passed.git diff --checkpassed. The only difference between the locally built Scala source and the final source is two whitespace-only scalafmt changes (indentation and argument wrapping).f886f78b: 30 checks passed and 2 integration checks were skipped. The subsequent documentation-only revision moves the migration note to the Spark 4.4 section per review; its CI is tracked separately.Local baseline: master
7e9a966c, Java 17, Python 3.12.Local PySpark tests use Python 3.12 on Windows through
unittest. A process-local fixture adapter closes onlyReusedSQLTestCase.setUpClass's temporary file before its existing unlink call, because Windows rejects unlinking the open handle. Product code, test assertions, and SQL/Arrow settings are unchanged by that adapter. The stockpython/run-testsdriver requires POSIXptysupport.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex (GPT-6)
This contribution is original work submitted under the project's Apache License 2.0.