fix: get_json_object returns first value for duplicate keys to match Spark#4971
Open
u70b3 wants to merge 2 commits into
Open
fix: get_json_object returns first value for duplicate keys to match Spark#4971u70b3 wants to merge 2 commits into
get_json_object returns first value for duplicate keys to match Spark#4971u70b3 wants to merge 2 commits into
Conversation
u70b3
force-pushed
the
fix/json-dup-key-first-wins
branch
from
July 18, 2026 00:46
bf2cf17 to
90db735
Compare
…h Spark Spark's GetJsonObjectEvaluator stops at the first matching field, but Comet's SegmentVisitor.visit_map kept overwriting the result, resolving a duplicated key to its last occurrence. Lock in the first match (even when the subpath misses, per Spark semantics) and skip later occurrences while still consuming all entries to validate the document. Closes apache#4947
u70b3
force-pushed
the
fix/json-dup-key-first-wins
branch
from
July 18, 2026 04:37
90db735 to
ec8fafb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #4947.
Rationale for this change
For a JSON object with duplicate keys, Spark's
GetJsonObjectEvaluatorstops at the first matching field, but Comet's native implementation resolved the key to its last occurrence (matchingserde_json's overwrite semantics rather than Spark's):What changes are included in this PR?
SegmentVisitor::visit_mapinnative/spark-expr/src/string_funcs/get_json_object.rsnow locks in the first key match and consumes later occurrences viaIgnoredAnyinstead of re-parsing them withPathSeed:nulland the second duplicate key is never consulted, matching Spark.How are these changes tested?
test_duplicate_key_last_winsunit test totest_duplicate_key_first_wins.test_duplicate_key_first_wins_nested({"a":{"b":1},"a":{"b":2}}/$.a.b->1).test_duplicate_key_first_match_locks_value({"a":{"x":1},"a":{"b":2}}/$.a.b->null, matching Spark's lock-on-first-match semantics).datafusion-comet-spark-exprsuite passes (497 tests), plusclippyandfmtchecks.spark/src/test/resources/sql-tests/andCometJsonJvmSuitefor duplicate-key cases: the only repeated keys there are across different objects inside arrays, which are unaffected by this change.