← Back to Pull requests

feat: add native MIN/MAX Parquet reader filtering 1/n #7598

Closed
unknown closed this pull request without merging on Nov 16, 2026 19:57 UTC
View on GitHub
unknown unknown commented on Nov 10, 2026 23:33 UTC
Author

Which issue does this PR close?

Part 1 of #5774; this PR does not close the issue. The three-PR plan is in this issue comment.

Rationale for this change

A partial MIN(x) or MAX(x) can tighten a bound while consuming Parquet input and skip later row groups that cannot improve the result. DataFusion already updates that bound, but Comet needs to connect its producer to the native reader and scope the mutable state to one execution.

What changes are included in this PR?

Add the internal MinMaxReaderFilterExec with the existing Parquet reader attachment. It accepts one unfiltered, non-distinct DataFusion MIN/MAX over a direct signed-integer column, with no grouping, in Partial mode, and one native input partition. Standalone projections, filters, limits, non-Parquet inputs, pushed scan predicates, and computed expressions in scan projections remain ineligible. Direct-column scan projections retain the existing file-column mapping.

Each execution constructs a fresh aggregate and uses its DataFusion-created predicate and accumulator-bound state. Aggregate metric handles and attachment counters belong to the wrapper; reader pruning and byte metrics stay with the scan. Unsupported reader attachment retains ordinary aggregation. The per-file schema guard preserves required-field validation for nullable physical columns and missing fields filled with NULL defaults. Nullable fields and non-NULL defaults remain eligible for pruning. MIN/MAX and TopK share metric handoff and runtime-state release on completion, error, or cancellation.

DataFusion 55.2 rechecks every unread row group at each boundary. Before executing the aggregate, inspect footers through the existing reader factory with Comet's 512 KiB hint unless the file provides an override and enable runtime pruning only when every file has at most 64 row groups. An oversized file, unavailable reader factory, or failed metadata inspection selects ordinary aggregation for the execution. The row-group limit is conservative for file ranges and stays until the upstream reader supports bounded pruning. Scans configured with decryption properties or a native key factory bypass preflight entirely and retain ordinary aggregation, avoiding an extra encrypted-footer read without the key.

Preflight hands its loaded readers and footers directly to the execution's scan, including ordinary fallback, so disabled or undersized shared caches do not cause duplicate footer reads. It stops when retained metadata exceeds 8 MiB and falls back, retaining the footer that crosses the limit for reuse. Readers are consumed by file occurrence and released with the runtime stream; repeated paths and Bloom-filter reader replacement cannot consume another occurrence's footer. Preflight still moves footer I/O ahead of the first output batch.

This is the native building block only: no Spark configuration, serialization, or planner integration is included, and existing Spark execution is unchanged. Those changes, including handling identity casts in MIN/MAX arguments, belong to PR 2. Only the try_new entry point carries a temporary dead-code allowance until that integration lands.

How are these changes tested?

Seventeen MIN/MAX tests cover:

  • Int32 MIN/MAX with empty/all-null input, duplicates, and negative values, plus attachment counters.

  • Filtering off/on for favorable and unfavorable layouts, with a remapped file column and assertions on row groups, scan rows, bytes, and metric ownership.

  • Fresh predicates and accumulator bounds across executions, resets, and child replacement; runtime-state release at completion and cancellation.

  • Unsupported aggregates/readers, computed scan projections, reader-attachment fallback, and omitted Parquet null counts.

  • Required-field validation with filtering on/off, including missing fields with NULL defaults and safe nullable/non-NULL-default controls that still prune.

  • A cold footer preflight uses one object-store request. Full scans match ordinary MIN footer loads and metadata bytes with disabled/undersized caches, prefetch on/off, repeated execution, and both row-group and metadata-budget fallback. Reader replacement preserves later occurrences of the same file.

  • Encrypted MIN matches ordinary aggregation with one footer read and equal metadata bytes. Factory-configured decryption bypasses preflight with zero I/O.

  • The 64/65-row-group boundary and an unfavorable 1,024-group layout, with results, scan rows, and attachment counters checked.
  • Tests live in child modules grouped by behavior. MIN/MAX and TopK share Parquet/session fixtures and footer-statistics helpers. Broader type comparisons with Spark belong to the SQL tests in PR 2.

    Validation:

  • cargo test --locked -p datafusion-comet --lib execution::operators::dynamic_filter::: 75 passed, including MIN/MAX and TopK.

  • The required NULL-default and encrypted-preflight regressions failed before their fixes and pass afterward. The encrypted fixture read 18,766 metadata bytes before the fix versus 9,383 for ordinary MIN; both now read 9,383.

  • rustfmt --check and git diff --check: passed.

  • dev/release/check-rat.sh HEAD: passed on the final source archive.

  • cargo clippy --locked --color=never --all-targets --workspace -- -D warnings: passed.

  • Two independent source reviews completed for each follow-up commit.

  • CI is rerunning on the updated head. Full fork CI on the previous c91a1203f head passed, including Comet, Spark SQL 4.1, Iceberg 1.11, TPC-H, and TPC-DS.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: sunchao Review duration: 8424m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #7598"
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 22.5% · Safe to merge
    22.5%