← Back to Pull requests

feat: run inline, inline_outer, and stack generators natively #7251

Open
unknown opened this pull request with 367 lines diff across 4 files
View on GitHub
unknown unknown commented on Oct 26, 2026 22:51 UTC
Author

Which issue does this PR close?

Closes #5125.

Rationale for this change

GenerateExec runs natively only for explode and posexplode. inline (expanding an array of structs into columns) and stack (the standard unpivot) fall back to Spark and take the surrounding stage with them, often directly above a Parquet scan.

What changes are included in this PR?

  • inline / inline_outer: a new inline flag on the Explode proto message. The native planner unnests the array as before, then has ExplodeExec flatten the struct into one column per field, using the struct unnesting that the UnnestExec fork already carries. Every generated column is reported nullable.

  • Null struct elements: flatten_struct_cols folds a struct's null mask into each field it flattens, using children_with_parent_nulls from datafusion-comet-common. Arrow leaves field values under a null struct unspecified, and Spark's inline emits a row of nulls for a null element.

  • stack: the serde rewrites stack(n, v1, ..., vk) into inline over array(named_struct(...), ...), one struct per output row, padding the last row with null literals of the column type. Each argument is still evaluated once per input row, as in Spark. If an argument cannot be converted, the operator reports that argument's own fallback reason. A stack that Spark does not code-generate (more than 50 rows) stays on Spark, because the rewrite builds one struct expression per output row.

  • Zero-field structs: inline and inline_outer over an array of structs with no fields stay on Spark. The unnested rows would have no column to hold their count.

  • Docs: the expression and operator support pages, understanding-comet-plans.md, and audit notes for the three generators. Inline and Stack behave the same in Spark 3.4.3, 3.5.8, 4.0.1 and 4.1.1.
  • How are these changes tested?

  • New SQL file tests expressions/array/inline.sql and expressions/misc/stack.sql, which assert native execution and match Spark. They cover NULL, empty and NULL-element arrays, NULL fields, the _outer variant, LATERAL VIEW, a struct field named like a carried column, nested and wide field types, arrays built in the query, uneven stack argument counts, NULL literal arguments, and filters and aggregates above the generator.

  • A Rust unit test for flatten_struct_cols with a null struct over non-null field values, including a sliced input.

  • A CometGenerateExecSuite test that a stack argument which cannot run natively falls back with its own reason.

  • CometGenerateExecSuite tests that stack above 50 rows and inline / inline_outer over an array of zero-field structs fall back, and that stack with exactly 50 rows runs natively.

  • Ran locally on the default Spark 4.1 profile: CometGenerateExecSuite (57 passed), the inline, stack, explode and posexplode SQL files, and the explode Rust tests.
  • Diff: 367 lines (+275 / -92) across 4 files Reviewer: rich7420 Review duration: 50457m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.50) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 367 lines diff across 4 files
    0.50
    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%
    44%
    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.353
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #7251"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.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: 49.7% (MEDIUM) · Higher = larger blast radius
    49.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: 44.7% · Lower = rushed or shallow review
    44.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: 27.5% · Safe to merge
    27.5%