Repository navigation
Conversation
A block used as a pipeline header must have 0 rows, but a dictionary source's
sample block has one row per column by construction: createSampleBlock
(DictionarySourceFactory.cpp) fills the key columns with insertDefault() and the
attribute columns with the declared null_value.
HTTPDictionarySource passed that block verbatim as the input format's header, and
the format chain forwards it unchanged, so the source's output port header carried
a row. DirectDictionary::read is the only layout that forwards the raw source
pipeline instead of rebuilding a header from the dictionary structure, so the
illegal header escaped to StorageMerge, which wraps every child output in
materialize and evaluates it with input_rows_count = 0. checkFunctionArgumentSizes
then compared 1 against 0:
Expected the argument N1 ('word' of type String) to have 0 rows, but it has 1:
while executing function materialize
reachable from ordinary SQL on a released build by reading a LAYOUT(DIRECT())
dictionary through merge(). Layouts other than DIRECT build their headers from the
dictionary structure via DictionarySourceCoordinator, which uses
type->createColumn(), so they were already unaffected.
Empty the block at each of the 10 places where it becomes a pipeline header. This
generalizes the guard that ClickHouseDictionarySource has carried since
4587947 "DirectDictionary updated" (2021), which added it to that one
source.
Four of these constructors use the sample block for two purposes at once, the
ISource port header and a parse schema or default-value source kept in a member, so
only the header argument is emptied and the member is left alone, following the
existing MySQLSource and PostgreSQLSource split. That distinction is load-bearing
rather than stylistic: MongoDBSource::insertDefaultValue does
insertFrom(sample_column, 0), reading row 0 of its member as the value substituted
for every absent or null BSON field, which for a dictionary is the user's declared
NULL_VALUE. Emptying the member would read out of bounds or silently substitute a
different value, which is also why the smaller-looking fix of emptying
createSampleBlock itself was rejected. RedisSource and CassandraSource still hand
the full block to description.init, and ExternalResultDescription::init refills
empty columns, so RedisSource's description.sample_block.rows() == 0 early-exit is
unaffected.
The new test uses an HTTP source because it is the only one that both supports
selective load, which LAYOUT(DIRECT()) requires, and is actually fixed here: the
ClickHouse source was already guarded and a FILE source cannot be used with
LAYOUT(DIRECT()) at all.
Closes: ClickHouse#116269
Internal second-model reviewAn independent cold review plus a second-model gate ran over this change before publication. Two
Checked and found sound, so raised as no finding:
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20260825-114100 |
|
Workflow [PR], commit [628a6f4] Summary: ✅
AI ReviewSummaryThis PR fixes the one-row pipeline-header invariant violation for Final VerdictStatus: ✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 23/35 (65.71%) · Uncovered code |
|
cc @nihalzp @vitlibar, could you review this? A dictionary source's sample block carries one row per column by construction, and |
|
cc @alexey-milovidov you can look at this |
…ress family The fallback URL in the test bracketed CLICKHOUSE_HOST whenever the local HTTP server had been bound to an IPv6 address. Those are independent: with CLICKHOUSE_HOST set to a name that resolves to an IPv6 address, the fallback built http://[<name>]:<port>, and urllib rejects a bracketed name with ValueError: '<name>' does not appear to be an IPv4 or IPv6 address. Bracket only when the host parses as an IPv6 literal, and leave a name unbracketed. Measured on the fallback path across four spellings of CLICKHOUSE_HOST (127.0.0.1, ::1, localhost, ip6-localhost): before, ip6-localhost raised that ValueError before any query ran; after, all four pass. Inverting the guard's polarity fails 127.0.0.1 with "An IPv4 address cannot be in brackets", confirming the branch is reached.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units13 translation units recompiled, 35 s compile time in total, 13 of them have a recent master baseline. |
…he pipeline head The input format is not only a schema consumer. ORC synthesizes a column that is absent from the payload as header_column.column->cloneResized(num_rows), and createSampleBlock seeds that column object with the attribute's configured null_value, so emptying the block passed to getInputFormat made a payload that omits an attribute produce the type default instead of the declared value. Measured on a FLAT dictionary with counter UInt32 DEFAULT 999 over an ORC payload carrying only the key column: master and this commit both return 999, while emptying the getInputFormat argument returned 0. A payload that does include the column returns 7 on every arm. Pass the populated block to the format again, and strip the rows where the header actually reaches an output port instead: the two SourceFromQueryPipeline constructors, which are what DirectDictionary::read hands to StorageMerge. That is the only place the sample row escaped into a port header, so the rest of the sources keep the blocks they parse and default with. Reverting only the SourceFromQueryPipeline change reproduces the original logical error from issue 116269 with the same message, and 05043_direct_dictionary_in_merge passes on this commit while aborting on master.
CI finish ledger - d4ed84fEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
The whole test matrix ran on this head: 38/38 Why #116441 owns this and not the already-merged #115726: the mirror-2 fallback #115726 added is Not caused by this PR: the diff is Session id: cron:our-pr-ci-monitor:20260826-050000 |
rienath
left a comment
There was a problem hiding this comment.
Good temporary patch, but it needs a redesign because at some point someone will forget to write std::make_shared<const Block>(...->cloneEmpty() and we'll end up with this problem again. Could you please file a follow-up with infrastructural fix and ask the owner of this code (the author if they're still with us or, if not, the component expert) for a review.
For this PR, please remove the comment you left in DirectDictionary and write a laconic one in createSampleBlock s.t. maintainers remember to do this trickery next time in the caller.
You can also simplify the test into roughly 15 line .sh file. Please try to do it
…ession test
The one-row block is built in createSampleBlock, so the note about a pipeline header
needing no rows belongs there: that is what a caller adding a new dictionary source
reads before publishing the block as its header.
The test no longer needs its own HTTP server. Pointing the dictionary at the server's
own HTTP interface reproduces the same logical error in 15 lines. Against a pre-fix
master debug build the test kills the server on 4 of 4 randomized-settings runs with
"Expected the argument No 1 ('word' of type String) to have 0 rows, but it has 1";
with the fix it passes 10 of 10 randomized runs and 4 of 4 concurrent runs.
Co-Authored-By: Claude Opus 5 <[email protected]>
|
Done for this PR in 628a6f4:
The source delta in that commit is comment-only, so behaviour is identical to the head that already finished CI. The infrastructural fix goes in a separate PR. I will cc the owner of that code there rather than here, and link it in this thread. |
|
The infrastructural fix is #116641. It drops the rows once in |
CI finish ledger - 628a6f4CI is fully finished at this commit. One check failed, and it has an owner.
Everything else at this commit is green: 178 praktika nodes, 155 Session id: cron:our-pr-ci-monitor:20260827-060000 |
dc90345
|
The 26.8 release branch still aborts with the defect this PR fixed. @alexey-milovidov, could you add
That is byte for byte the message #116269 quotes, down to the column name and the 0-vs-1 counts. Report What I measured:
I am asking for 26.8 only, where the failure is observed. |
Backport #116378 to 26.8: Do not put a row into a dictionary source's pipeline header
…y source's pipeline header
…ops the rows ClickHouse#116378 has merged, so master carries nine hand-written `std::make_shared<const Block>(...->cloneEmpty())` strips, plus a third YTsaurus one that a later PR copied (Cassandra, Redis, Null, DirectDictionary x2, MongoDB, ShellCommand, YTsaurus x3). Every one of them takes a `SharedHeader`, so with `ISource` normalizing the header they collapse to passing that header directly. The `createSampleBlock` comment no longer tells callers to strip the rows themselves. `05045_direct_dictionary_rowless_header` duplicated ClickHouse#116378's `05043_direct_dictionary_in_merge`; its two extra arms (a `DEFAULT` on the attribute and a plain `SELECT` from the dictionary) are folded into 05043 and 05045 is removed. With the strips gone, 05043 again fails if the `ISource` hunk is reverted.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a logical error (
... to have 0 rows, but it has 1: while executing function materialize) when a dictionary withLAYOUT(DIRECT())was read through themergetable function. Closes #116269.Description
Closes: #116269
On a released build (26.7.5), reading a
LAYOUT(DIRECT())dictionary throughmergeis rejected withCode: 49. Expected the argument ... to have 0 rows, but it has 1: while executing function materialize. Being aLOGICAL_ERROR, it aborts debug and sanitizer builds.Root cause. A block used as a pipeline header must have 0 rows.
createSampleBlock(
DictionarySourceFactory.cpp) deliberately builds a dictionary source's sample block with one row percolumn, and that block reached the source's output port unchanged.
DirectDictionary::readis the onlylayout that forwards the raw source pipeline instead of rebuilding a header from the dictionary
structure, so that header reaches
StorageMerge, which wraps every child output inmaterializeandevaluates it with
input_rows_count = 0, andcheckFunctionArgumentSizesthrows.The change. Strip the rows where the block becomes an output port header: the two
SourceFromQueryPipelineconstructors inDirectDictionary.cpp, which is whatDirectDictionary::readhands toStorageMerge, plus the source constructors passing the blockstraight to
ISource. The block given togetInputFormatstays populated on purpose:ORCmaterializes a column missing from the payload as
header_column.column->cloneResized(num_rows),reading the row
createSampleBlockseeds with the attribute'snull_value. Four constructors likewisekeep a populated member as a parse schema, per the existing
MySQLSource/PostgreSQLSourcesplit.Validation. The stateless test
05043_direct_dictionary_in_mergepoints the dictionary at theserver's own HTTP interface, so it needs no fixture and is parallel-safe. A pre-fix master debug build
aborts on it with the exact message above, 4 of 4 randomized runs; here it passes 10 of 10 randomized
and 4 of 4 concurrent runs. Reverting only the
SourceFromQueryPipelinechange reddens the same query.A
FLATdictionary declaringcounter UInt32 DEFAULT 999over anORCpayload carrying only the keyreturns
999on master and here, and7on every arm once the payload includes the column.Workflow [PR]
Sync PR [sync-upstream/pr/116378]
Version info
26.9.1.444-master(included in26.9and later)26.8.11.51