← Back to Pull requests

Accept `optimizations` in the streaming engines' `execute` #25662

Merged
madsbk merged 7 files (119 lines) on Dec 03, 2026 14:35 UTC
View on GitHub
madsbk madsbk commented on Dec 02, 2026 16:34 UTC
Author

Description


This PR makes lf.execute(engine=...) work with SPMDEngine, DaskEngine and RayEngine. It returns the engine's GPU-resident PersistedQueryResult, as engine.execute(lf) already does. Previously it raised TypeError: ... got an unexpected keyword argument 'optimizations'.

execute now takes an optional keyword-only optimizations argument, which is applied to the query before translation, so flags such as pl.QueryOptFlags(predicate_pushdown=False) take effect. PersistedQueryResult now implements the Polars QueryResult protocol. Its head and n_rows_total are not supported yet and are None for now.

Closes #25651

Checklist


  • I am familiar with the Contributing Guidelines.

  • New or existing tests cover these changes.

  • The documentation is up to date with these changes.
  • Diff: 119 lines (+103 / -16) across 7 files Reviewer: TomAugspurger Review duration: 1320m
    All Vouch review confidence checks passed
    Residual risk 0.07 = Change Risk (0.40) × (1 − Review Confidence (0.82)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 119 lines diff across 7 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.73 · 5 substantive comment(s)
    0.73
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    81%
    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.286
    Real PR Conversation Timeline
    7 items
    coderabbitai[bot] coderabbitai[bot] commented on Dec 02, 2026 17:11 UTC
    Bot

    <!-- coderabbit-ai-generated:v1 -->

    <!-- This is an auto-generated comment: summarize by coderabbit.ai -->
    <!-- review_stack_entry_start -->

    <a href="https://app.coderabbit.ai/change-stack/NVIDIA/cudf/pull/25662?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a>

    <!-- review_stack_entry_end -->
    <!-- recent_review_status_start -->

    No actionable comments were generated in the recent review.

    <!-- recent_review_status_end -->
    <!-- walkthrough_start -->

    <details>
    <summary><strong>Summary</strong></summary>
    <dl>
    <dd>
    <br>

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    New Features
    Distributed query engines now accept optional optimization settings, allowing you to control which query optimizations are applied. If omitted, default optimizations are used.
    Persisted query results now support Polars’ query-result interface. The head and total-row-count metadata are reported as unavailable.
    Documentation
    Updated the API reference to describe the persisted query result metadata.
    Tests
    Added coverage for optimization settings, result metadata, and collecting persisted query results.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->
    DaskEngine, RayEngine, and SPMDEngine accept optional optimization flags and pass them to persisted-query execution. PersistedQueryResult implements Polars’ QueryResult protocol with head and n_rows_total properties that return None. Tests cover result compatibility, collection, and optimization effects on translated plans.

    Changes: Polars engine execution

    |Layer / File(s)|Summary|
    |:---|:---|
    |Persisted result and optimization handling <br> python/cudf_polars/cudf_polars/engine/persisted_result.py, docs/cudf/source/cudf_polars/api.md, docs/cudf/source/conf.py|PersistedQueryResult adds head and n_rows_total properties that return None. execute_persisted_query accepts optional optimization flags and applies them before translation when provided. The API reference lists the new properties, and Sphinx ignores the pl.QueryOptFlags class target during nitpicky checks.|
    |Engine forwarding and execution tests <br> python/cudf_polars/cudf_polars/engine/dask.py, python/cudf_polars/cudf_polars/engine/ray.py, python/cudf_polars/cudf_polars/engine/spmd.py, python/cudf_polars/tests/test_engine_execute.py|The three engines accept and forward optional optimization flags. Tests check result compatibility, collection, and translated plan roots for selected optimization settings.|

    <!-- change_assessment_start -->
    Estimated code review effort: 3 (Moderate) | ~20 minutes

    <!-- change_assessment_commit:"8bd98869ef78199f5031387cdc0095b22312dbc1" -->
    <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} -->
    Change: Bug fix · Severity of issue fixed: Medium
    <!-- change_assessment_end -->

    Possibly related issues

  • Issue 22917: This change lets DaskEngine, RayEngine, and SPMDEngine return a PersistedQueryResult that implements Polars’ QueryResult protocol. Other gaps described in that issue are not addressed.
  • Suggested reviewers: tomaugspurger

    </dd>
    </dl>
    </details>

    <!-- walkthrough_end -->
    <details>
    <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>8bd98</code></summary>
    <dl>
    <dd>
    <br>

    <!-- final_review_risk_start -->
    <!-- final_review_risk_label
    Merge Risk: ⚪ Minimal · up to 8bd98
    -->
    <!-- final_review_risk_coverage:{"sourceCommitId":"8bd98869ef78199f5031387cdc0095b22312dbc1","coveredCommitId":"8bd98869ef78199f5031387cdc0095b22312dbc1","kind":"reviewed"} -->

    This change lets lf.execute(engine=...) work with the SPMD, Dask, and Ray engines and accept optimization flags. Existing calls behave as before, and the new tests cover the main paths. No merge-blocking risk is evident.
    <!-- final_review_risk_end -->

    </dd>
    </dl>
    </details>

    <details>
    <summary><strong>Security architecture risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>8bd98</code></summary>
    <dl>
    <dd>
    <br>

    <!-- architecture_review_start -->
    <!-- architecture_review_label

    Security Architecture Review

    Security architecture risk: ⚪ Minimal · up to 8bd98
    -->

    Polars callers can now pass optimizer flags to the streaming engines and receive a GPU-resident result. The change uses the same engine, validation, and cleanup path as direct engine execution. The result's preview and total row count remain unsupported.

    <details>
    <summary><strong>Security review details</strong></summary>
    <dl>
    <dd>
    <br>

    Security Blast Radius

  • _inferred_ — The newly usable Polars call reaches the same rank-side persistence path as the existing direct call for the supplied engine. The reviewed changes do not select a different backend or store identifier.
  • Trust Boundaries and Controls

  • _observed_ — The optimizer input can change the plan presented to the translator, but it does not skip the helper's post-translation checks or change which backend receives the plan.
  • Data and control flow

  • _observed_ — The helper applies supplied flags before translating the plan; when the argument is None, it uses the plan's existing optimizations. Translation error handling and the Time-dtype guard still precede GPU persistence.
  • Resilience and Maintainability Implications

  • _observed_ — If flag application fails, this call has not yet started backend persistence, so there are no partitions from that call to release. After successful persistence, the result owns cleanup through explicit release or finalization, keyed to a fresh query ID for each call. This does not add recovery for a backend failure after writing partitions but before returning a result; that window existed in the merge base.
  • </dd>
    </dl>
    </details>
    <!-- architecture_review_end -->

    </dd>
    </dl>
    </details>
    <!-- pre_merge_checks_walkthrough_start -->

    <details>
    <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4</strong></summary>
    <dl>
    <dd>
    <br>

    | Check name | Status | Explanation |
    | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | Title check | !Passed | The title names the main change: the streaming engines' execute methods now accept the optimizations argument. The raw summary confirms SPMDEngine, DaskEngine, and RayEngine each gained this… |
    | Description check | !Passed | The description matches the changeset. It explains that lf.execute(engine=...) now works with SPMDEngine, DaskEngine, and RayEngine. It describes the new keyword-only optimizations argument … |
    | Linked Issues check | !Passed | [#25651] The issue requires three coding behaviors. (1) lf.execute(engine=SPMDEngine()) must accept the optimizations keyword instead of raising TypeError. (2) Non-None flags must apply to the… |
    | Out of Scope Changes check | !Passed | Every changed area maps to #25651 or its stated scope. spmd.py, dask.py, and ray.py add and forward the optimizations argument, and the TODOs in these files name the same mismatch. persisted_… |

    <details>
    <summary><strong>Full details: Title check</strong></summary>
    <dl>
    <dd>
    <br>

    Explanation

    The title names the main change: the streaming engines' execute methods now accept the optimizations argument. The raw summary confirms SPMDEngine, DaskEngine, and RayEngine each gained this keyword-only argument, forwarded to execute_persisted_query. The title is specific and matches the changeset. It omits the PersistedQueryResult protocol change, which is acceptable because the title need not cover every detail.

    </dd>
    </dl>
    </details>

    <details>
    <summary><strong>Full details: Description check</strong></summary>
    <dl>
    <dd>
    <br>

    Explanation

    The description matches the changeset. It explains that lf.execute(engine=...) now works with SPMDEngine, DaskEngine, and RayEngine. It describes the new keyword-only optimizations argument and the PersistedQueryResult protocol changes, where head and n_rows_total return None. It also links issue #25651 and lists the checklist items.

    </dd>
    </dl>
    </details>

    <details>
    <summary><strong>Full details: Linked Issues check</strong></summary>
    <dl>
    <dd>
    <br>

    Explanation

    [#25651] The issue requires three coding behaviors. (1) lf.execute(engine=SPMDEngine()) must accept the optimizations keyword instead of raising TypeError. (2) Non-None flags must apply to the lazy frame before translation. (3) The call must return a PersistedQueryResult, and direct engine.execute(lf) must keep working. At the current head, SPMDEngine.execute, DaskEngine.execute, and RayEngine.execute each take a keyword-only optimizations: pl.QueryOptFlags | None = None and forward it to execute_persisted_query. This review read the dask.py and persisted_result.py diffs against the merge base directly. execute_persisted_query calls ldf.with_optimizations(optimizations._pyoptflags) before Translator(ldf.visit(), engine). The return type is unchanged, and the default None path keeps direct calls working. PersistedQueryResult provides head and n_rows_total returning None, which the PR states but the issue does not require. test_engine_execute.py covers the lf.execute(engine=...) round trip and the HStack versus Filter root difference for predicate_pushdown=False, which addresses the issue's plan-change point. The issue's older Polars version compatibility point is not covered by any test in the PR. The previous PASS remains supported.

    </dd>
    </dl>
    </details>

    <details>
    <summary><strong>Full details: Out of Scope Changes check</strong></summary>
    <dl>
    <dd>
    <br>

    Explanation

    Every changed area maps to #25651 or its stated scope. spmd.py, dask.py, and ray.py add and forward the optimizations argument, and the TODOs in these files name the same mismatch. persisted_result.py adds the optimization hook in execute_persisted_query and the QueryResult protocol properties head and n_rows_total, which support the issue's compatible-result requirement. The docs changes in conf.py (ignoring pl.QueryOptFlags as a nitpick target) and api.md (documenting head and n_rows_total) support the new public API surface. The tests in test_engine_execute.py cover the same behavior. No unrelated module or behavior change was found in the inspected diffs.

    </dd>
    </dl>
    </details>

    </dd>
    </dl>
    </details>

    <!-- pre_merge_checks_walkthrough_end -->
    <!-- finishing_touch_checkbox_start -->

    <details>
    <summary><strong>Finishing Touches</strong></summary>
    <dl>
    <dd>
    <br>

    <details open>
    <summary><strong>Generate unit tests (beta)</strong></summary>
    <dl>
    <dd>
    <br>

  • <!-- {"checkboxId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} --> Create a new PR
  • </dd>
    </dl>
    </details>

    </dd>
    </dl>
    </details>

    <!-- finishing_touch_checkbox_end -->

    <!-- autopilot:start -->

  • <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

  • <!-- autopilot:end -->
    <!-- recent_review_start -->

    <h6>
    <details>
    <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary>
    <dl>
    <dd>
    <br>

    <!-- review_info_content -->
    <details>
    <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary>
    <dl>
    <dd>
    <br>

  • Source mode: Auto

  • Repository: [NVIDIA/cudf](<https://github.com/NVIDIA/cudf>)

  • Branch: [main](<https://github.com/NVIDIA/cudf/tree/main>)

  • File: [.coderabbit.yaml](<https://github.com/NVIDIA/cudf/blob/f3a547636fe2bb3e02639b01903e4d2db55a6641/.coderabbit.yaml>)

  • Commit: [f3a5476](<https://github.com/NVIDIA/cudf/commit/f3a547636fe2bb3e02639b01903e4d2db55a6641>)

  • Layers: Repository YAML

  • Review profile: CHILL

  • Plan: Enterprise

  • Run ID: 44992219-ee0b-49b9-948c-ac67281e602c
  • </dd>
    </dl>
    </details>

    <details>
    <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary>
    <dl>
    <dd>
    <br>

    Reviewing files that changed from the base of the PR and between 08d8ab7a1e3621c3c726436b790a14690182fb5e and 8bd98869ef78199f5031387cdc0095b22312dbc1.

    </dd>
    </dl>
    </details>

    <details>
    <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 3</strong></summary>
    <dl>
    <dd>
    <br>

    docs/cudf/source/conf.py
    docs/cudf/source/cudf_polars/api.md
    python/cudf_polars/cudf_polars/engine/persisted_result.py`

    </dd>
    </dl>
    </details>

    <details>
    <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-similar-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-similar.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files skipped from review as they are similar to previous changes: 1</strong></summary>
    <dl>
    <dd>
    <br>

  • python/cudf_polars/cudf_polars/engine/persisted_result.py
  • </dd>
    </dl>
    </details>

    Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.

    </dd>
    </dl>
    </details>
    </h6>

    <!-- recent_review_end -->

    TomAugspurger TomAugspurger commented on code on Dec 02, 2026 22:52 UTC
    Code Review
    python/cudf_polars/tests/test_engine_execute.py:1
    @@ -198,6 +198,47 @@ def test_execute_chains_into_another_execute(streaming_engine):
         assert_frame_equal(collected, lf.filter(pl.col("a") > 1).collect())
     
     
    +def test_lazyframe_execute_dispatches_to_engine(streaming_engine):

    Do we not have an existing test for this? If so, the new result.head and result.n_rows_total assertions could be added to that.

    TomAugspurger TomAugspurger approved these changes on Dec 02, 2026 22:53 UTC
    Approved Reviewer

    Approved these changes.

    madsbk madsbk commented on code on Dec 03, 2026 07:29 UTC
    Code Review
    python/cudf_polars/tests/test_engine_execute.py:1
    @@ -198,6 +198,47 @@ def test_execute_chains_into_another_execute(streaming_engine):
         assert_frame_equal(collected, lf.filter(pl.col("a") > 1).collect())
     
     
    +def test_lazyframe_execute_dispatches_to_engine(streaming_engine):

    Not for lf.execute(engine=...), which was the bug, but test_execute_lazy_roundtrip covered the same round trip via engine.execute(lf). I've merged them: that test now goes through lf.execute(engine=...) and has the new assertions.

    madsbk madsbk commented on Dec 03, 2026 14:34 UTC
    Author

    /merge

    Matt711 Matt711 commented on Dec 03, 2026 15:09 UTC
    Contributor

    Thanks @madsbk!

    Reviewers
    Assignees
    madsbk madsbk
    Labels
    risk: low confidence: 81.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: 40.4% (MEDIUM) · Higher = larger blast radius
    40.4%
    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: 81.8% · Lower = rushed or shallow review
    81.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: 7.3% · Safe to merge
    7.3%
    Repository