Repository navigation
Apply column defaults for inline INSERT into table functions - #109258
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260703-053400 |
|
cc @KochetovNicolai @alexey-milovidov — could you review this? It fixes gap 1 of #109253: for server-side inline INSERT ( |
|
Workflow [PR], commit [1ae85cd] Summary: ✅
AI ReviewSummaryThis PR restores Final Verdict
|
495a342 to
02ed24b
Compare
|
Rebased onto current master and fixed a build break from base drift. Master's storage-metadata accessor now returns a Re-verified both directions on the merged base:
|
When the server parses INSERT ... VALUES inline data itself (send_table_structure_on_insert_with_inline_data = 0), an explicit NULL inserted into a non-Nullable column with a DEFAULT was not replaced by the default for INSERT INTO TABLE FUNCTION remote()/file(), producing 0 instead of the declared default. A plain table INSERT and the HTTP protocol apply it correctly. Root cause: getSourceFromInputFormat added AddingDefaultsTransform (which applies input_format_null_as_default during parsing) only when ast_insert_query->table_id was set. table_id is empty for table functions, so the transform was skipped. The synchronous path is the affected one; the asynchronous path adds its own AddingDefaultsTransform. Fix: when table_id is empty, fall back to the resolved destination columns saved in the context by InterpreterInsertQuery (getInsertionTableColumnsDescription), which is populated for table functions too. The input() path is unaffected (still gated by !input_function). Related: ClickHouse#109253 Caused by: ClickHouse#101034 Co-Authored-By: Claude Opus 4.8 <[email protected]>
02ed24b to
1ae85cd
Compare
|
Rebased onto master (head
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 15/15 (100.00%) · Uncovered code |
CI finish ledger — 1ae85cdCI fully finished (Finish Workflow SUCCESS). No failed checks on this head. The Bugfix-validation Session id: cron:our-pr-ci-monitor:20260703-173000 |
Backport #109258 to 26.6: Apply column defaults for inline INSERT into table functions
…e-insert-table-function-defaults-109253 Apply column defaults for inline INSERT into table functions
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a bug where column
DEFAULTvalues were not applied forINSERT INTO TABLE FUNCTION(for exampleremote(...)orfile(...)) with inlineVALUESdata when the server parses the inline data itself (send_table_structure_on_insert_with_inline_data = 0). An explicitNULLinserted into a non-Nullablecolumn with aDEFAULTbecame0instead of the declared default. It now behaves like a plain tableINSERTand the HTTP protocol.Description
Addresses gap 1 of #109253 (table-function defaults). The trailing-comment data-loss gap is not touched here.
Root cause: for inline (non-
SELECT)INSERT, defaults are applied by theAddingDefaultsTransformadded ingetSourceFromInputFormat(src/Processors/Transforms/getSourceFromASTInsertQuery.cpp). That transform was added only whenast_insert_query->table_idis set.table_idis empty for table functions, so the transform (which also performsinput_format_null_as_defaultduring parsing) was skipped and the explicitNULLwas not converted to the column default. The downstreamInsertDependenciesBuilder::createPreSink->addMissingDefaultspath only fills columns missing from the input header, and its null-as-default is gated toINSERT ... SELECT, so it does not cover inlineVALUES. The asynchronous insert path was unaffected because it adds its ownAddingDefaultsTransform, which is why the synchronous case (async_insert = 0, as CI runs) was the one that reproduced.Fix: when
table_idis empty, fall back to the resolved destination columns saved in the context byInterpreterInsertQuery::setInsertContextValues(Context::getInsertionTableColumnsDescription()), which is populated for table functions as well. Theinput()path stays gated out by!input_function.Verified in both directions on a local debug build (server-side inline path,
async_insert = 0,send_table_structure_on_insert_with_inline_data = 0):remote()Int DEFAULT 7,VALUES (NULL)file()CSVInt DEFAULT 77,VALUES (4, NULL)file()CSVLowCardinality(String) DEFAULT 'x'file()CSVArray(Int) DEFAULT [1, 2]file()CSVNullable(Int) DEFAULT 77, explicitNULLCI report showing the failure this fixes (03667 on PR #104640 head 8ed06ca,
send_table_structure_on_insert_with_inline_data = 0, 183/183 failing): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104640&sha=8ed06ca93081214a31acef155c8df020fd950600&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29Version info
26.7.1.781(included in26.7and later)26.6.2.62