Repository navigation
Use the type default for values missing from JSON in the JSON type and JSONExtract - #131213
Conversation
…JSONExtractTree and JSON functions
The container nodes of `JSONExtractTree` (used by the `JSON` data type for
typed paths and by `JSONExtract*`) and the per-row fallback of the JSON
functions inserted `IColumn::insertDefault` for every value they did not take
from the input: a missing `Tuple` element, a null `Tuple`, an invalid `Array`,
`Map` or `Tuple` element, and a failed `JSONExtract` row. That is the zero of
the column, which for an `Enum` without a 0 element is not a member, so a
`JSON` column with a typed `Tuple(..., Enum8(...))` path stored an
out-of-domain value (`SELECT` failed with `UNKNOWN_ELEMENT_OF_ENUM` while
`CHECK TABLE` passed) and `JSONExtract('{}', 'k', 'Enum8(...)')` returned 0.
`ArrayNode`, `TupleNode` and `MapNode` now get their element types from the
builder and insert `IDataType::insertDefaultInto` for a type whose default is
not the column zero, and the String-input executor does the same with the
result type. `isDefaultInsertTrivial` is evaluated once at construction, so
every other type keeps `IColumn::insertDefault` (the pattern `ObjectJSONNode`
already uses for typed paths). Which inputs a node accepts or rejects is
unchanged: `Nullable(Tuple)` from `{}` is still NULL, `Variant` still picks the
`Map` alternative, and the `JSON` type still rejects `{"t": {}}` for a typed
`Tuple` path.
`JSONExtract` on a native `JSON` argument (`runForObjectColumn`) is not
changed here.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Make the getTypeForDefault comment precise: an Enum default is its smallest value, so zero differs from it whenever that value is not 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings; 1 full pass), plus my own cold review of the same tree.
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261113-072500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261113-062000 |
|
Workflow [PR], commit [84f0cdd] Summary: ❌
AI ReviewSummaryReviewed #131213 at Final Verdict✅ Approve. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units8 translation units recompiled, 26 s compile time in total, 8 of them have a recent master baseline. |
CI finish ledger - c51b3d4Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261113-113012 |
|
The CI failure is unrelated. @groeneai you should fix it in another PR |
|
Agreed, the |
f50e945
|
The fix for the |
Related: #130898
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
JSONExtractfunctions and theJSONdata type filling a value missing from the input (an absent key, an invalidArrayorMapelement, a missingTupleelement) with 0 instead of the default of its type. AnEnumwithout a 0 element no longer gets a value outside its elements, which madeSELECTfail withUNKNOWN_ELEMENT_OF_ENUM.Description
On 26.10.2.103 and 26.9.19.9,
JSONExtract('{}', 'status', 'Enum8(''a'' = 1, ''b'' = 2)')returns 0, which is not an element of theEnum(Code: 691 UNKNOWN_ELEMENT_OF_ENUMwhen printed), and aJSON(t Tuple(n UInt8, status Enum8('a' = 1, 'b' = 2)))column stores 0 for{"t": {"n": 5}}, after whichSELECT *fails whileCHECK TABLEpasses.Root cause: the container nodes of
JSONExtractTree(ArrayNode,TupleNode,MapNode) and the per-row fallback of the JSON functions insertIColumn::insertDefault, the column zero, for every value they do not take from the input.Change: the builder passes the element types to those nodes, and they insert
IDataType::insertDefaultIntowhen the type's default is not the column zero (isDefaultInsertTrivial, asObjectJSONNodealready does for typed paths); the String-input executor does the same with the result type. Accepted and rejected inputs are unchanged:Nullable(Tuple)from{}is still NULL,Variantstill picksMap, and theJSONtype still rejects{"t": {}}for a typedTuplepath. For anEnumwhere 0 is an element but not the smallest one, such asEnum8('n' = -1, 'z' = 0), the result changes from'z'to'n', the value anINSERTthat omits the column stores.JSONExtracton a nativeJSONargument has the same problem in a different code path that #102039 is restructuring; it is left for a separate fix. The same class on other surfaces is fixed in #131189 (input formats), #131186 (CASTto a namedTuple), #131190 (null_as_default), #131198 (VALUES (DEFAULT)) and #130975 (CSV/TSV).Validation: the new test fails on master with
Code: 691and passes with the fix, 50/50 with randomized settings; 816 JSON-related stateless tests show no new failure; single-threaded parsing of 2MJSONrows and 5MJSONExtractrows is unchanged within noise.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/131213]
Version info
26.11.1.2242-master(included in26.11and later)