← Back to Pull requests

feat: support float keys in native map_from_arrays and map_from_entries #7722

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

Which issue does this PR close?

Closes #6549. Part of #6385.

Rationale for this change

#6992 sent floating-point map keys through JVM codegen dispatch for Spark compatibility. This PR restores Rust execution for map_from_arrays and map_from_entries with top-level FLOAT and DOUBLE keys, including grouped collect_list results with adaptive query execution enabled.

What changes are included in this PR?

  • One Rust function implements both builders. It compares all NaNs as one key and follows Spark's version and legacy setting for signed zero. Under LAST_WIN, the first occurrence determines the position and the last supplies the value. Under EXCEPTION, the first invalid key determines the error. The executor JDK formats duplicate floating-point keys.

  • Like Spark's map builder, map_from_arrays preserves the original keys when they are distinct. When a duplicate forces a rebuild, normalization applies to every stored key in that row. map_from_entries always applies the normalization setting.

  • Comet passes spark.sql.mapKeyDedupPolicy and the effective normalization setting as constants when serializing the expression. This removes the need to inspect or compile Spark codegen stages, rewrite plans or transfer settings through JNI. Set both options before planning. Changing them on an existing plan or overriding them through task-local properties is unsupported. No new public configuration or JVM API is required.

  • The outer null guard cannot prevent the null check and body of arrays_zip from evaluating a stateful child separately. Codegen dispatch preserves that child's evaluation and the bits Spark produces for NaN literals. The general stateful-input issue is tracked in #5781 and #5867. The fixed-width constructor restriction also limits peak memory before deduplication. Array columns, including variable-width and nested values, remain eligible. Struct and array keys containing floats retain codegen dispatch.

  • The kernel reuses input slices where possible, gathers surviving values, and shrinks its lookup table only when its capacity exceeds eight times the next nonempty row's size. For folded string and binary lists, the literal reader reserves the sum of the actual payload lengths.
  • How are these changes tested?

  • Parquet-backed SQL fixtures check both key widths, duplicate policies, normalization modes, null entries, error ordering and routing. Scala tests cover adaptive grouped aggregation, both normalization modes under stable settings, NaN literal bits and JDK error formatting. Rust tests inspect key and value bits, scalar reuse, duplicate rejection under EXCEPTION, sliced inputs and the Arrow offset limit when a nested list is repeated or discarded.

  • Apache CI and fork CI track d89346d. Formatting and git diff --check passed.

  • The existing map_from_arrays Criterion benchmark now covers eight distinct DOUBLE keys and string values per row.
  • Hosted comparison

    Measurements and raw samples · Reproduction code

    The fork-only harness used the native library built for d89346d and a planner switch to select Rust or JVM dispatch. The switch is outside this PR. Each run checked the selected route and compared a fingerprint of the ordered entries, raw key bits and values with Spark. The clock covered the Parquet scan, map construction and output consumption. Planning and input generation were outside the timer.

    Median wall time in milliseconds on one AMD EPYC 9V74 runner, Spark 4.1.3, JDK 17, local[2], LAST_WIN, three warmups and eight measured rounds per route with alternating order. For the first eight cases, 65,536 rows of array columns had either 32 distinct keys or 1–64 keys with duplicates in most rows. The batch size was 8,192.

    | Input | Builder | Keys | Rust (ms) | JVM dispatch (ms) | Spark (ms) |
    |---|---|---|---:|---:|---:|
    | Distinct | map_from_arrays | FLOAT | 68.4 | 146.5 | 150.7 |
    | Distinct | map_from_entries | FLOAT | 53.4 | 120.9 | 144.4 |
    | Distinct | map_from_arrays | DOUBLE | 59.5 | 135.5 | 135.1 |
    | Distinct | map_from_entries | DOUBLE | 60.5 | 123.2 | 143.8 |
    | Mixed | map_from_arrays | FLOAT | 60.0 | 125.3 | 163.0 |
    | Mixed | map_from_entries | FLOAT | 59.6 | 103.9 | 158.9 |
    | Mixed | map_from_arrays | DOUBLE | 66.4 | 124.5 | 133.3 |
    | Mixed | map_from_entries | DOUBLE | 57.3 | 111.8 | 135.3 |
    | Discard wide string | map_from_arrays | FLOAT | 480.5 | 41.4 | 45.8 |
    | Discard wide string | map_from_entries | FLOAT | 490.6 | 22.2 | 25.9 |

    Why restrict computed inputs?

    For array columns, JVM dispatch took 1.74–2.28 times as long as Rust in these runs. The last two rows bypass the input guard to measure the cost of constructing arrays in Rust. Both routes discard a 128 KiB string in favor of a short value on each of 2,048 rows. The outer null check cannot skip a non-null value that the map will later discard. Projecting just the same constructors in Rust produced 268,482,250 and 268,499,658 bytes of Arrow buffers across four 512-row batches. Only 21,418 bytes of string payload survived. The median sampled increase in process RSS during those queries was about 191 MiB for Rust and under 1 MiB for dispatch. RSS includes allocator reuse and JVM activity.

    This is why the default routes these constructors through dispatch. Materialized string and nested array columns remain eligible. Neither these timings nor the wide-string example establish a crossover point for all input sizes. For non-floating keys, LAST_WIN already uses dispatch.

    The separate arrays_zip evaluation problem also affects non-floating keys. Its null check and body can evaluate the same stateful child on different sets of rows. The existing issue and agreed approach cover that behavior across expressions. #5867 handles nondeterministic children. Changing evaluation of all native zip operands would affect other callers and overlap that work.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: viirya Review duration: 15565m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #7722"
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 27.7% · Safe to merge
    27.7%