Repository navigation
Fix DEFAULT expression not applied to explicit null in JSONColumns formats - #127113
alexprabhat99 wants to merge 23 commits into
Conversation
|
Workflow [PR], commit [660cdbe] Summary: ❌
AI ReviewSummaryThe PR fixes explicit-null default tracking in the columnar JSON formats and expands default dependencies for file-like reads and Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block. Complete scalar alias binding in default dependency analysis and add the two focused regressions. |
|
Hi @NIKTONIKTO717 |
|
Hi @NIKTONIKTO717 |
|
I'm sorry @alexprabhat99 , I managed to do a code review but not to publish it 🤦. Would you mind please to take a look? Thanks! |
…nd fix `INSERT` with columns `FROM INFILE`
…olumn of a subcolumn used by a `DEFAULT`
ch-samuel-reviewer-1
left a comment
There was a problem hiding this comment.
Thank you @alexprabhat99 for addressing the comments, and sorry again for the delay on my side! The fixes look good to me: on master an explicit null in JSONColumns, JSONCompactColumns and JSONColumnsWithMetadata is inserted as 0 instead of a * 2, and both SELECT b FROM file(..., Parquet, 'a UInt32, b UInt32 DEFAULT a * 2') and INSERT INTO t (b) FROM INFILE ... FORMAT JSONEachRow throw UNKNOWN_IDENTIFIER. With this PR, all of them take the DEFAULT.
I agree with both findings of the AI review, so I think these still need to be addressed:
- The lambda capture in
substituteNotInsertedColumns. With the AI review's table (a UInt32 DEFAULT z * 2, b UInt32 DEFAULT arraySum(arrayMap(z -> a + z, [1, 2]))),INSERT INTO tl (z, b) FROM INFILEof{"z":10,"b":null}insertsb = 9, while the same row as inline data or inVALUESgives43. On master thisFROM INFILEthrowsUNKNOWN_IDENTIFIER, so with this PR the error becomes a silently wrong value. - With
input_format_defaults_for_omitted_fields = 0,SELECT b FROM file(..., JSONColumns, 'a UInt32, b UInt32 DEFAULT a * 2')of{"a":["oops"],"b":[3]}now parsesaand fails withCANNOT_PARSE_INPUT_ASSERTION_FAILED, while master returns3.
Could you please add both cases to the tests as well?
Could you please also update the changelog entry? The PR now fixes more than JSONColumns: INSERT INTO t (columns) FROM INFILE where a DEFAULT uses a column that isn't inserted (in any format, JSONEachRow included), and reading a subset of columns from file/url/s3 where a DEFAULT of a requested column uses a column that isn't read. For example:
Fix the
JSONColumns,JSONCompactColumnsandJSONColumnsWithMetadatainput formats inserting the type default instead of the column'sDEFAULTexpression for an explicitnullwithinput_format_null_as_default. Also fixUNKNOWN_IDENTIFIERwhen aDEFAULTexpression uses a column which is not read: inINSERT INTO t (columns) FROM INFILE, and when reading a subset of columns fromfile,urlors3.
This review was checked, modified and approved by human (@NIKTONIKTO717).
…OM INFILE` defaults, and skip reading the columns of `DEFAULT` expressions without `input_format_defaults_for_omitted_fields`
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes41 object files changed (+207.31 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units155 translation units recompiled, 1763 s compile time in total, 155 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.93 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
… defaults, and compute the defaults of columns read only for a `DEFAULT` only when that `DEFAULT` is computed
ch-samuel-reviewer-1
left a comment
There was a problem hiding this comment.
Thank you @alexprabhat99 for addressing the comments! Both cases from my previous review I consider fixed now. Thanks also for adding the tests and for updating the changelog entry.
Once the open threads of the AI review are addressed, I'll be happy to take another look.
This review was checked, modified and approved by human (@NIKTONIKTO717).
…ve tuple parents of subcolumns and stop at present columns when choosing the defaults to compute
… cycle through a subcolumn by the names as they are
…bcolumn of another column now sees its inserted value (https://github.com/ClickHouse/ClickHouse/actions/runs/41288457776/job/124794889528?pr=127113, ClickHouse#127113)
…sion, so that shared dependencies are not expanded again
…umns and `ALIAS` columns
… upstream `master` does
…ake subcolumns of lambda arguments for columns read by defaults
…take subcolumns of aliases for columns read by defaults
ch-samuel-reviewer-1
left a comment
There was a problem hiding this comment.
Thank you @alexprabhat99 for addressing the comments! I left one more comment, which will be marked as resolved just for the sake of having it mentioned, since we consider this trade-off.
This review was checked, modified and approved by human (@NIKTONIKTO717).
|
Hi @NIKTONIKTO717 |
It is very likely to be approved soon. I'm going through it one more time. Thank you @alexprabhat99; I don't think any action on your part will be necessary. |
|
@NIKTONIKTO717 The latest commit is causing the tests to fail. All checks were passing before this commit. |
…l-as-default-expression
…ull-as-default-expression # Conflicts: # src/Storages/prepareReadingFromFormat.h
…ull-as-default-expression # Conflicts: # src/Interpreters/RequiredSourceColumnsData.h
…ases of all expressions
| if (array_join_columns.contains(name) || array_join_columns.contains(table_name)) | ||
| continue; | ||
|
|
||
| if (mask_subcolumns_of_aliases && isSubcolumnOfAliases(name, pr.second.appears)) |
There was a problem hiding this comment.
[Blocker] Apply scope-aware dependency resolution to ordinary identifiers too
The new scope map is consulted only for compound identifiers. Plain identifiers still use the flat complex_aliases set, so a lambda-local alias can hide a real column reference outside that lambda. This leaves the dependency order incorrect for an input whose explicit nulls this PR now defaults:
CREATE TABLE t
(
z UInt32,
a UInt32 DEFAULT z,
b UInt32 DEFAULT
arraySum(arrayMap(x -> (toUInt32(2) AS a), [1, 2])) + a
) ENGINE = Memory;
INSERT INTO t FORMAT JSONColumns
{"z":[7,9],"a":[5,null],"b":[null,null]}
SELECT z, a, b FROM t ORDER BY z;The PR inserts (7, 5, 11) and (9, 9, 13); the first b must be 9. Because the lambda alias is visited first, the outer a is omitted from the dependency graph. Both defaults are evaluated together, and b uses z instead of the supplied a = 5. Moving the outer a before the lambda changes the result to the correct value. The scalar case already affects JSONEachRow; this PR also exposes it through JSONColumns.
There is an inverse failure for aliases on identifier nodes: with x.jsonl containing {"z":"oops","c":2,"b":null}, this valid subset read returns (2, 8) on master but throws CANNOT_PARSE_TEXT in the PR:
SELECT c, b FROM file('x.jsonl', JSONEachRow,
'z String, a UInt32 DEFAULT toUInt32(z), c UInt32,
b UInt32 DEFAULT arraySum(arrayMap(x -> (c AS a) + a, [1, 2]))');Here the local scalar alias is mistaken for the physical a, whose unrelated default is evaluated. Recording (c AS a) in alias_scopes does not fix scalar lookups. Reproduced with the ARM release binary at a5b8bc89; the relevant scalar lookup logic remains unchanged at 660cdbe0.
Please use shared scope-aware resolution for both scalar and compound identifiers, including every alias-bearing node, in dependency collection, pruning, and ordering. Add both focused regressions instead of another subcolumn-only exception.
Closes: #121905
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix the
JSONColumns,JSONCompactColumnsandJSONColumnsWithMetadatainput formats inserting the type default instead of the column'sDEFAULTexpression for an explicitnullwithinput_format_null_as_default. Also fixUNKNOWN_IDENTIFIERwhen aDEFAULTexpression uses a column which is not read: inINSERT INTO t (columns) FROM INFILE, and when reading a subset of columns fromfile,urlors3.Workflow [PR]
Sync PR [sync-upstream/pr/127113]