← Back to Pull requests

[SPARK-60486][SQL] Preserve Python UDF partition filters after V2 pushdown #59732

Closed
unknown closed this pull request without merging on Oct 28, 2026 19:05 UTC
View on GitHub
unknown unknown commented on Oct 23, 2026 00:28 UTC
Author

What changes were proposed in this pull request?

Preserve partition predicates rejected by FileScanBuilder as 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, and OR. 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..5 and partition column p = i % 3, filtering a V2 Parquet read with udf(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?

  • Built the unmodified master with Hive support, then rebuilt the candidate SQL reactor with Maven. PruneFileSourcePartitionsSuite: 9/9 passed.

  • The two expanded regressions: 2 failures before the production change, 2/2 passed afterward. An additional 20/20 existing filter, join, subquery, and nondeterministic UDF tests passed across pickle and Arrow UDF classes.

  • An independent 44-case matrix covering Parquet/ORC, V1/V2, pickle/Arrow, NULL partitions, compound predicates, and controls: 12 incorrect results before the fix, 44/44 correct afterward, with identical input file bytes and expected results. The 32 control cases remained correct.

  • Ruff check/format, Scala formatter validation, and git diff --check passed. The only difference between the locally built Scala source and the final source is two whitespace-only scalafmt changes (indentation and argument wrapping).

  • Fork CI completed successfully for implementation commit 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 only ReusedSQLTestCase.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 stock python/run-tests driver requires POSIX pty support.

    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.

    Diff: 453 lines (+339 / -114) across 5 files Reviewer: szehon-ho Review duration: 8316m
    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
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.5% (MEDIUM) · Higher = larger blast radius
    45.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.7% · Safe to merge
    19.7%
    Repository