Skip to content

Native implementation of get_json_object returns last value for duplicate keys, Spark returns first #4947

Closed

Description

@andygrove

Describe the bug

get_json_object diverges from Spark when a JSON object contains duplicate keys.

For input {"a":1,"a":2} and path $.a:

  • Comet returns 2 (the last occurrence)
  • Spark returns 1 (the first occurrence)

Spark's GetJsonObjectEvaluator.evaluatePath (sql/catalyst/.../json/JsonExpressionEvalUtils.scala) stops at the first matching field once dirty is set, so it returns the first occurrence. Comet visits every entry and resolves to the last occurrence, matching serde_json's preserve_order overwrite semantics rather than Spark's.

This is a pre-existing divergence, not a regression. It predates the streaming rewrite in #4907 (the old serde_json + preserve_order path had the same last-wins behavior). It was noted during review of #4907.

Steps to reproduce

SELECT get_json_object('{"a":1,"a":2}', '$.a');
-- Spark: 1
-- Comet: 2

Expected behavior

Match Spark and return the first occurrence of a duplicated key.

Additional context

The fix is on the Rust side in native/spark-expr/src/string_funcs/get_json_object.rs: SegmentVisitor::visit_map should stop updating found once a key has matched (while still consuming the remaining entries to validate the document). The test_duplicate_key_last_wins test added in #4907 would need to be flipped to first-wins.

Activity

  1. changed the title [-]get_json_object returns last value for duplicate keys, Spark returns first[/-] [+]Native implementation of `get_json_object` returns last value for duplicate keys, Spark returns first[/+] on Jul 15, 2026
  2. u70b3 commented on Jul 17, 2026

    @u70b3
    Contributor

    take

  3. added 2 commits that reference this issue on Jul 18, 2026
    90db735
    ec8fafb
  4. added
    bugSomething isn't working
    priority:criticalData corruption, silent wrong results, security issues
    and removed on Jul 20, 2026
  5. kazuyukitanimura commented on Jul 20, 2026

    @kazuyukitanimura
    Contributor

    Already marked as incompatible, downgrading the priority

  6. added
    priority:highCrashes, panics, segfaults, major functional breakage
    and removed
    priority:criticalData corruption, silent wrong results, security issues
    on Jul 20, 2026
  7. added a commit that references this issue on Jul 22, 2026
    847b4ec
  8. 6 remaining items

  9. modified the milestones: 1.1.0, 1.0.1 on Aug 17, 2026
  10. added a commit that references this issue on Aug 21, 2026
    08d951d
  11. added 4 commits that reference this issue on Aug 27, 2026
    dd18261
    51ce133
    4ecffa3
    c8c5dba
  12. added a commit that references this issue on Sep 20, 2026
    03bd43a
  13. added a commit that references this issue on Oct 1, 2026
    cb0b584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:expressionsExpression evaluationbugSomething isn't workingcorrectnesspriority:highCrashes, panics, segfaults, major functional breakage

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions