← Back to Pull requests

Fix assert_equal never comparing map values [databricks] #17285

Open
unknown opened this pull request with 582 lines diff across 7 files
View on GitHub
unknown unknown commented on Dec 03, 2026 15:57 UTC
Author

Contributes to #17018.

Description

assert_equal in integration_tests/src/main/python/asserts.py never compared dict (map) values. The dict branch called list(cpu.items()).sort(key=_RowCmp), and list.sort() returns None, so it compared None to None and always passed. The fix is to use sorted(...). The sort cost is unchanged. The same bug was in udf_cudf_test.py (cpu_ret.sort() == gpu_ret.sort()), which is fixed here too.

With the check actually running, a number of tests now fail. These are real CPU/GPU differences or test side problems that the broken assert was hiding. How each group is handled:

| Issue | Problem | Handling in this PR |
|---|---|---|
| #17281 | map_zip_with returns values attached to the wrong keys (mapZip is evaluated twice in GpuMapZipWith, and indices_of in the JNI kernel uses idx % start instead of idx - start) | MapZipWith is now disabled by default with a documented reason (docs/compatibility.md). The tests enable it explicitly and are xfail. A new test checks the fallback. |
| #15240 (was #17282) | from_json to MAP<STRING,STRING> keeps raw JSON text where the CPU normalizes it | xfail citing #15240. In test_from_json_map_string_string, only the 12 input files that fail carry xfail(strict=True). The 7 that pass stay guarded. |
| #17283 | Spark's Hive SerDe writer collapses MAP<DATE, …> keys (upstream Spark bug, the GPU result is correct) | No xfail. The date-keyed map generator now uses an int key with date values, so the rest of the write tests stay covered. |
| #17284 | DESCRIBE HISTORY operationMetrics byte counts differ | Fixed here instead of xfailing: assert_delta_history_equal normalizes both histories with the existing _fixup_* helpers. |
| (new) | Before Spark 4.0 the CPU keeps 0.0 and -0.0 as separate map keys (SPARK-47563) and cuDF merges them, so test_map_concat, test_map_concat_with_lit and test_map_from_arrays fail on some seeds | No xfail. Float/Double map keys drop -0.0 on Spark < 4.0 and keep NaN. The existing helpers moved from array_test.py to data_gen.py. |

Changes for DBR 17.3, from the failures reported in the PR comments:

  • normalized_add_actions now builds its physical-to-logical column map per commit from metaData.schemaString. Before, it used only the final schema, which left version 0 column names unmapped.

  • assert_delta_history_equal takes ignore_metrics, and the empty-input CTAS/RTAS test ignores numFiles. An empty GPU write can emit a zero-row Parquet file where the DBR CPU emits none.
  • Testing

  • Added to asserts_regression_test.py:

  • - Equal maps with different insertion order pass.
    - Unequal maps raise AssertionError: different value, swapped values, missing entry, extra entry and different key.
    - Nested map values and NaN keys, plus a mismatch test for each.
    - A NaN-row test for assert_equal_with_local_sort.
  • Ran locally on Spark 4.1.1 (Scala 2.13, GPU): map_test.py, json_test.py, json_matrix_test.py, hive_parquet_write_test.py, the Delta tests (Delta 4.1.0) and the Iceberg tests (Iceberg 1.11.0).

  • Reproduced the signed-zero failure on Spark 3.3.0 (seed 5) and confirmed the fix there.
  • Validation gaps

  • Databricks DBR 17.3: the normalized_add_actions change and the numFiles handling follow the failures reported in the DBR run on this PR. I did not run them on DBR. The [databricks] tag is on the title so the DBR suites run.

  • Spark 3.5.x paths, the cudf UDF tests (udf_cudf_test.py) and the Scala unit tests were not run locally.

  • #17018 stays open until the 3.x and Databricks paths are green, and until the xfailed tests are fixed.
  • Related PRs

  • #17297 makes the same assert_delta_history_equal change. The helper code here is identical. #17297 also adds unit tests for the helper, which this PR does not.
  • Checklists

    Documentation

  • Updated for new or modified user-facing features or behaviors

  • No user-facing change
  • Testing

  • Added or modified tests to cover new code paths

  • Covered by existing tests

  • Not required
  • Performance

  • Tests ran and results are added in the PR description

  • Issue filed with a link in the PR description (#17281)

  • Not required
  • MapZipWith is now disabled by default, so map_zip_with queries run on the CPU instead of returning wrong results on the GPU. No performance comparison is meaningful while the GPU output is wrong. Re enabling is tracked in #17281, and users can opt in with spark.rapids.sql.expression.MapZipWith=true. Everything else in this PR is test only.

    Diff: 582 lines (+436 / -146) across 7 files Reviewer: gerashegalov Review duration: 2498m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 582 lines diff across 7 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%
    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.381
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #17285"
    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: 49.9% (MEDIUM) · Higher = larger blast radius
    49.9%
    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: 26.6% · Safe to merge
    26.6%