← Back to Pull requests

stream ROW_NUMBER output by input batch #7461

Open
unknown opened this pull request with 513 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 03, 2026 16:39 UTC
Author

Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example Closes #123 indicates that this PR will close issue #123.
-->

Closes #7466.

Rationale for this change

<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->

ROW_NUMBER currently uses the generic bounded window executor, which performs per-partition state management and batch slicing even though this function only needs a counter and partition boundary detection. That overhead is particularly expensive for many small window partitions.

What changes are included in this PR?

<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->

  • Add RowNumberExec to generate row numbers directly within each input batch, carrying the final partition key and counter across batches.

  • Select it when every window expression is built-in ROW_NUMBER with matching partition and ordering keys.

  • Reuse input column buffers and share the generated array between repeated ROW_NUMBER expressions.

  • Account for retained partition-key buffers through DataFusion’s memory pool, including cleanup on completion, errors, and cancellation.

  • Preserve existing ordering, distribution, statistics, and result-cast behaviour, and document the new execution path.
  • How are these changes tested?

    <!--
    We typically require tests for all PRs in order to:
    1. Prevent the code from being accidentally broken by subsequent changes
    2. Serve as another way to document the expected behavior of the code

    If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
    -->

  • Regression tests compare results against the generic executor across partition boundaries, sliced and empty batches, global windows, repeated expressions, and nullable, dictionary, and nested keys.

  • Memory tests cover retained-buffer accounting, reservation failures, cancellation, and avoiding retention of unrelated dictionary or view buffers.

  • Spark SQL regressions cover global and partitioned windows, multiple batch sizes, ANSI modes, repeated expressions, and mixed-function windows. A planner regression checks executor selection alongside result casts and timing metrics.

  • Benchmarks compare both executors on identical inputs and verify every row number before timing. The benchmark shows improvements across all tested partition sizes, with the largest gains for small partitions.
  • The 12 operator tests pass in an isolated harness. The Spark test additions compile but have not been executed locally.

    Benchmark results

    Median runtime for 262,144 rows in 32 batches of 8,192 rows, using three string partition keys. Measurements pool two runs of 10 samples each on an Apple M3 Max. The repeat measures streaming first.

    The unchanged benchmark source ran in an isolated harness using Comet’s release settings, DataFusion 55.2.0, and Arrow 59.3.2. These measurements cover window execution over already-sorted input.

    Input / rows per partition | Base ms | Candidate ms | Speedup range
    -- | -- | -- | --
    String keys / 1 | 270–284 | 3.76–13.67 | 20–75×
    String keys / 4 | 71.47–72.01 | 3.01–3.07 | 23.3–23.9×
    String keys / 64 | 10.61–10.81 | 2.55–2.57 | 4.1–4.2×
    String keys / 16,384 | 7.26–7.57 | 2.54–2.56 | 2.8–3.0×
    String keys / 262,144 | 8.46–22.53 | 2.52–2.54 | 3.3–8.9×
    Bigint keys / 4 | 51.48–52.32 | 0.737–0.741 | 69.5–71.0×
    Bigint keys / 16,384 | 4.83–4.85 | 0.318–0.320 | 15.1–15.3×
    Global window | 4.26–18.01 | 0.235–0.386 | 11–77×
    18 carried columns / 4 | 137–288 | 3.04–12.56 | 11–95×
    18 carried columns / 16,384 | 11.35–30.92 | 2.56–2.61 | 4.4–12.1×

    Diff: 513 lines (+384 / -129) across 6 files Reviewer: comphead Review duration: 1866m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.48) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 513 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.373
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #7461"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 47.7% (MEDIUM) · Higher = larger blast radius
    47.7%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 25.4% · Safe to merge
    25.4%