refactor: share Spark element matching across array_contains, array_position and array_remove #7717
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
viirya
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_containsandarray_removeeach implemented scalar float comparison and per-row search.array_positionexpanded a scalar search value to a column and normalized both nested operands before comparing them.What changes are included in this PR?
array_containsandarray_positionshare a search that stops at the first match. On a miss, a null element makesarray_containsreturn null, whilearray_positionreturns zero.array_removevisits all elements and copies the survivors with their original bits and nulls.array_containsandarray_removeuse the existing vectorized Spark comparison kernel to build their match and keep masks over the visible list elements.array_positionuses 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_containsgo through Spark's codegen dispatcher by default, following the benchmark in #6599.How are these changes tested?
The SQL fixture compares native
array_positionwith 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
LargeListwith nonzero offsets. Existing contains and remove tests cover nulls, NaN payloads, bitmap word boundaries and the bits of surviving elements.Checked
rustfmt --checkandgit diff --checklocally. 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.