Skip to content

Fix type_json_allow_duplicated_key_with_literal_and_nested_object not working with typed paths in JSON - #108218

Merged
Avogar merged 2 commits into
masterfrom
fix-type-json-allow-duplicated-key-typed-paths
Jul 9, 2026
Merged

Avogar merged 2 commits into
masterfrom
fix-type-json-allow-duplicated-key-typed-paths

Conversation

@Avogar

@Avogar Avogar commented Jun 22, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix type_json_allow_duplicated_key_with_literal_and_nested_object not working with typed paths in JSON.

Version info

  • Merged into: 26.7.1.724 (included in 26.7 and later)
  • Backported to: 26.6.3.25, 26.5.7.34, 26.3.18.23

Avogar and others added 2 commits June 22, 2026 19:22
…ot working with typed paths in JSON

The setting `type_json_allow_duplicated_key_with_literal_and_nested_object`
was not honored when the JSON type had typed paths (e.g. `JSON(a Int32)`).
Parsing `{"a":42,"a":{"b":42}}::JSON(a Int32)` would throw an exception
about duplicate paths even with the setting enabled.

The fix restructures the object key iteration in `traverseAndInsert` into
two passes:
- First pass: collects distinct element types per key and validates
  duplicates upfront (throwing errors before any data is inserted).
- Second pass: processes keys in original order, using a
  `skip_typed_path_check` flag for object values of typed non-nested paths
  that have a literal+object duplicate. The flag makes the recursive call
  enter object traversal instead of trying to insert into the typed path,
  so the object's children go to dynamic/shared data while the literal
  fills the typed path.

This handles both key orderings correctly (literal-first and object-first).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [92c93f7]

Summary: ✅


AI Review

Summary

This PR fixes type_json_allow_duplicated_key_with_literal_and_nested_object for scalar typed paths in JSON, but the new dispatch still misses typed paths whose declared type can parse the object value itself. I left one inline comment; the PR should cover that case before merge.

Findings

⚠️ Majors

  • [src/Formats/JSONExtractTree.cpp:2026] The duplicate-key contract is still violated for object-capable typed paths. For {"a":42,"a":{"b":1}}::JSON(a Map(String, Int32)), skip_typed is false for both duplicate values: the literal is sent to MapNode and fails in literal-first order, while object-first order fills a and then the literal hits the duplicate typed-path check. The same issue applies to JSON/Tuple typed paths that this branch explicitly says should receive the object value.
    Suggested fix: when a typed path has a literal+object duplicate and the typed type should receive the object, skip or reroute the literal duplicate away from that same typed path, and keep the behavior deterministic for both key orders.
Tests

⚠️ Add focused regression coverage for object-capable typed paths, at least JSON(a Map(String, Int32)) and one of JSON(a Tuple(b Int32)) / JSON(a JSON), in both literal-first and object-first duplicate-key order.

Final Verdict

Status: ⚠️ Request changes

Minimum required action: fix the structured typed-path duplicate handling and add the missing regression tests.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 22, 2026
Comment thread src/Formats/JSONExtractTree.cpp Resolved
@yariks5s yariks5s self-assigned this Jun 25, 2026
@Avogar
Avogar requested a review from yariks5s July 8, 2026 12:31
@clickhouse-gh

clickhouse-gh Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.30% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 51/51 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@Avogar
Avogar added this pull request to the merge queue Jul 9, 2026
Merged via the queue into master with commit 797a5a9 Jul 9, 2026
327 of 330 checks passed
@Avogar
Avogar deleted the fix-type-json-allow-duplicated-key-typed-paths branch July 9, 2026 18:00
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 9, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi — this looks like a backport candidate for 26.3, 26.4, 26.5, 26.6. I ran this PR's own regression test against each branch's binary and the bug reproduces there (the fix isn't present yet).

@samay-sharma samay-sharma added pr-must-backport Pull request should be backported intentionally. Use this label with great care! v26.2-must-backport labels Jul 31, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jul 31, 2026
Avogar added a commit that referenced this pull request Aug 10, 2026
Backport #108218 to 26.6: Fix `type_json_allow_duplicated_key_with_literal_and_nested_object` not working with typed paths in JSON
Avogar added a commit that referenced this pull request Aug 10, 2026
Backport #108218 to 26.5: Fix `type_json_allow_duplicated_key_with_literal_and_nested_object` not working with typed paths in JSON
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 10, 2026
alexey-milovidov added a commit that referenced this pull request Aug 12, 2026
Backport #108218 to 26.3: Fix `type_json_allow_duplicated_key_with_literal_and_nested_object` not working with typed paths in JSON
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
…ey_with_literal_and_nested_object` not working with typed paths in JSON
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
…ey_with_literal_and_nested_object` not working with typed paths in JSON
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…low-duplicated-key-typed-paths

Fix `type_json_allow_duplicated_key_with_literal_and_nested_object` not working with typed paths in JSON
VighneshPath pushed a commit to VighneshPath/ClickHouse that referenced this pull request Sep 16, 2026
…ey_with_literal_and_nested_object` not working with typed paths in JSON
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
PROTO: JSON typed paths with the duplicate-key setting -> exc.
Effect in the production build a394e92: wrong/failing (the upstream test fails on it and passes on official 26.8.8.8; evidence/fix_ci_20260925/upstream_repro/residual/108218.PROD263.txt).
Upstream patch unchanged, with its test(s): 04331_type_json_allow_duplicated_key_with_literal_and_nested_object_typed_paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants