← Back to Pull requests

refactor: share Spark element matching across array_contains, array_position and array_remove #7717

Open
unknown opened this pull request with 369 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 20, 2026 22:14 UTC
Author

Which issue does this PR close?

Part of #6614 and #6385. Struct support for array_position and array_remove remains outstanding in #6614. Related dispatcher coverage is tracked in #5582.

Rationale for this change

Spark uses the same equality rule for all three functions. Signed zeros compare equal, and any NaN matches any other NaN, including inside arrays and structs. Comet's native array_contains and array_remove each implemented scalar float comparison and per-row search. array_position expanded a scalar search value to a column and normalized both nested operands before comparing them.

What changes are included in this PR?

  • Share row traversal and element comparison across the three Comet kernels. A scalar search value occupies one slot. For a column, each list uses the value at its row index. Nested elements use the existing recursive Spark equality predicate directly on the input buffers.

  • array_contains and array_position share a search that stops at the first match. On a miss, a null element makes array_contains return null, while array_position returns zero. array_remove visits all elements and copies the survivors with their original bits and nulls.

  • For a scalar float, array_contains and array_remove use the existing vectorized Spark comparison kernel to build their match and keep masks over the visible list elements. array_position uses the early-exit search for scalar inputs too, so a match at the start of a long list ends the search there.
  • This applies to the current native paths. In particular, nested floats in array_contains go through Spark's codegen dispatcher by default, following the benchmark in #6599.

    How are these changes tested?

    The SQL fixture compares native array_position with Spark for scalar and per-row values, including signed zeros, duplicates, nulls, empty lists and nested arrays. Negating a stored NaN after the Parquet read creates an opposite-sign NaN. Searching [NULL, -NaN, NaN] for NaN must return 2, and the nested case exercises the same rule with a null inside each child array.

    A Rust test checks the first match for a scalar NaN in a sliced LargeList with nonzero offsets. Existing contains and remove tests cover nulls, NaN payloads, bitmap word boundaries and the bits of surviving elements.

    Checked rustfmt --check and git diff --check locally. Hosted CI passed the Rust and Spark SQL suites on e686f53. A review measured that commit against the merge base using float_arrays, array_position, and a temporary nested array_position benchmark. Contains, remove, and nested position stayed within noise. Flat position with a scalar search value was 5–19% faster in most cases. See the review measurements. The follow-up changes have not been benchmarked.

    Diff: 369 lines (+276 / -93) across 4 files Reviewer: viirya Review duration: 14272m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 369 lines diff across 4 files
    0.43
    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.354
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #7717"
    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: 42.8% (MEDIUM) · Higher = larger blast radius
    42.8%
    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: 22.8% · Safe to merge
    22.8%