Skip to content

Drop the rows of a source's pipeline header in one place - #116641

Open
groeneai wants to merge 7 commits into
ClickHouse:masterfrom
groeneai:infra-rowless-source-header
Open

groeneai wants to merge 7 commits into
ClickHouse:masterfrom
groeneai:infra-rowless-source-header

Conversation

@groeneai

@groeneai groeneai commented Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #116269
Related: #116378

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Description

A port header describes the shape of a stream, not its contents, so it carries no rows. DictionarySourceFactory::createSampleBlock builds a dictionary source's sample block with one row per column, because row 0 of each attribute holds its declared DEFAULT and several sources read it as a value. #116378 fixed #116269 by writing ISource(std::make_shared<const Block>(sample_block->cloneEmpty())) by hand at nine sites, and forgetting it at a new one is silent until StorageMerge wraps the source in materialize and gets ... to have 0 rows, but it has 1.

ISource's constructor now drops the rows once, which covers every source's port header, including the getInputFormat route. The nine strips from #116378, and a tenth copied since, become plain ISource(sample_block), as do the older ones in SourceFromSingleChunk and PostgreSQLSource.

NativeORCBlockInputFormat is the only format that reads a value out of the block it was handed: for a column the payload omits it copies row 0, so an ORC dictionary source returns the declared DEFAULT. It now keeps the block as supplied, and 05046_orc_dictionary_declared_default pins that.

Nothing user-visible changes on master. 05043_direct_dictionary_in_merge gains a DEFAULT and a plain SELECT arm. Validated with four Build-ID-checked binaries: master and this PR pass both tests; reverting only the ISource hunk makes 05043 hit the #116269 logical error, and reverting only the ORC hunk makes 05046 return 0 instead of 999.

I left the IOutputFormat and transform sites alone, since they legitimately pass a populated block, and the strips whose argument is a Block rather than a SharedHeader (for example MySQLSource, SQLiteSource, ArrowFlightSource), where make_shared is needed anyway.


Workflow [PR]
Sync PR [sync-upstream/pr/116641]

A pipeline port header describes the shape of a stream, not its contents, so it
must have no rows. Nothing enforced that. Every dictionary source that published
its factory sample block as its own header had to remember to write
ISource(std::make_shared<const Block>(sample_block->cloneEmpty())), and
DictionarySourceFactory::createSampleBlock deliberately seeds one row per column,
where an attribute's row 0 holds that attribute's declared DEFAULT. Forgetting the
strip stayed silent until some caller evaluated the header with
input_rows_count = 0: StorageMerge wraps every child output in materialize, and
checkFunctionArgumentSizes then reports a logical error.

Normalize in ISource's constructor instead, which is the single point every
source's port header passes through, so the strip cannot be forgotten. This also
stops a DIRECT dictionary over an HTTP source from returning row 0 of its sample
block as an extra data row.

NativeORCBlockInputFormat is the one format that reads a value out of the block it
was handed rather than out of its own columns: for a column the payload omits it
does header_column.column->cloneResized(num_rows), which copies row 0, so an ORC
dictionary source returns the attribute's declared DEFAULT instead of the type
default. It now keeps the block as supplied, so that behaviour is unchanged.

Closes: ClickHouse#116269
Both call sites already hold the block as a SharedHeader, so the wrapper collapses
to passing it straight through.

MySQLSource and SQLiteSource keep theirs on purpose: their parameter is a
`const Block &`, so they have to build a shared_ptr in any case, and dropping
`cloneEmpty()` there would copy the data instead of the shape without removing a
line.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Aug 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold
review of the resulting tree (1 nit). Coverage recorded by the independent pass: all changed
files, the full changed ORC functions and the missing-column path, every ISource
construction site, the relevant callers and sibling formats, and both tests.

# Sev Finding Verdict Evidence / action
1 💡 ProjectionsDescription.cpp:178 still writes the manual cloneEmpty() that the second commit removes elsewhere AGREE, not blocking It is the last such site in the tree and it is now a redundant allocation, which is exactly the property this change establishes, so I did not enlarge the cleanup commit for it.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Also checked and found clean, since they are the two ways this change could go wrong silently:
the only reader of a port header's row 0 in the tree is NativeORCBlockInputFormat, which this
change gives its own carrier (ArrowColumnToCHColumn's three construction sites all read a
member or a local, and Arrow and Parquet fill an omitted column with the type default); and
checkColumnStructure's const-value comparison is already guarded by a pre-existing
!empty() test, so no header that was ever valid loses a check.

Session id: cron:clickhouse-review-slot-9:20260827-041000

@clickhouse-gh clickhouse-gh Bot closed this Aug 27, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, 100%, not a rate. clickhouse-test 05045_direct_dictionary_rowless_header against a pristine 349752afc755237 build fails every run and aborts the server in a debug build.
b Root cause explained? createSampleBlock returns one Block carrying two contracts: a parse schema and declared-default carrier, which needs row 0, and a port header, which must have none. Nothing enforced the second, so each source had to strip the rows by hand. A forgotten strip is silent until StorageMerge's materialize evaluates the header with input_rows_count = 0 and checkFunctionArgumentSizes reports to have 0 rows, but it has 1.
c Fix matches root cause? Yes. The invariant is established at ISource's constructor, the single point every source's port header passes through, so the mistake becomes unrepresentable. StorageMerge, FunctionHelpers.cpp, ActionsDAG.cpp and DictionarySourceFactory.cpp are untouched, so this is not a guard at the failure site.
d Test intent preserved / new tests added? Two new tests, each pinned by its own mutant, reddening disjoint arms. No existing test weakened or removed, no bound widened, no no-parallel tag.
e Both directions demonstrated? Yes, on Build-ID-verified binaries: base fails 05045 and passes 05046; the final build passes both.
f Fix is general across code paths? Covers all 114 ISource construction sites at once, including the indirect getInputFormat -> IRowInputFormat -> IInputFormat -> ISource route that produced the issue, rather than nine sites by hand. Consumer side swept: cloneResized( over src/Processors/Formats/ and src/Formats/ gives 6 hits, only 2 resize a header column, and only ORC's receiver is a port header. insertFrom(/insertRangeFrom( there: 12 hits, none sourced from a header. Parquet and Arrow positively measured as type-default fillers.
g Fix generalizes across inputs (params/datatypes/wrappers)? Type wrappers are structurally irrelevant: the change keys on Block::rows, never on a column type. A type-only header reports 0 rows and is passed through with no clone. ColumnConst keeps its value through cloneEmpty, so const-reading consumers are unaffected. A 0-column block is passed through untouched. 05046 covers the attribute-with-DEFAULT, attribute-supplied and no-DEFAULT matrix.
h Backward compatible? (maintainer-approved exception only) Yes. No setting added or changed, so no SettingsChangesHistory.cpp entry is due; no serialization or on-disk format touched; no experimental gate needed.
i Invariants and contracts preserved? It establishes "a port header reachable from an ISource has 0 rows", which IInputFormat::getChunkForCount, ConstChunkGenerator, Squashing and AggregatingTransform already silently required. Header structure is untouched, and checkColumnStructure never compares row counts, so connect cannot start failing. There are 0 pointer comparisons of a SharedHeader in src/, so handing out a new one is safe. ORC's ORCColumnToCHColumn::header is a reference, so supplied_header is declared before orc_column_to_ch_column and outlives it by reverse-order member destruction.

Session id: cron:clickhouse-impl-slot-41:20260827-020100

@clickhouse-gh

clickhouse-gh Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [aedbdd8]

Summary: ❌

job_name test_name status info comment
Upgrade check (amd_release) FAIL
Cannot start clickhouse-server FAIL cidb
Server failed to start (see application_errors.txt and clickhouse-server.clean.log) FAIL cidb
Check failed FAIL cidb

AI Review

Summary

The PR centralizes empty pipeline headers in ISource, removes redundant header cloning from source adapters, and preserves ORC dictionary defaults through a separate sample-block reference. No actionable findings.

Missing context / blind spots
  • ⚠️ Full CI for head aedbdd85cdb41446390c4b12fc01f54f2aca8da9 is still running. 05043_direct_dictionary_in_merge passes at this head; 05046_orc_dictionary_declared_default passed at preceding head e26b2badb62c8446ce7f1f442fb5f043a25c49e6. Current-head ORC and sanitizer results remain pending. Tests were not run locally.
Final Verdict

Status: ✅ Approve. No code changes requested; required CI should complete before merging.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @novikd @Avogar, could you review this? ISource's constructor now drops the rows of the header it is given, because a dictionary source's sample block deliberately carries one row (row 0 holds each attribute's declared DEFAULT) and every source publishing that block as its port header had to remember to empty it by hand. NativeORCBlockInputFormat keeps the block as supplied, since it is the one format that synthesizes a column the payload omits by copying row 0.

@clickhouse-gh

clickhouse-gh Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit aedbdd85cdb41446390c4b12fc01f54f2aca8da9 was not compared: the CI logs cluster did not answer (exception 241, code 500: { "meta": [ { "name": "file", "type": "LowCardinality(String)" …).

See the job log for details.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - c4d18f8

Every failure below has an owner: a fixing PR, or a full-effort fix task whose fixing-PR link
will be posted here when it opens.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug, targeted) / Inconsistent AST formatting (STID 1941-26fa) pre-existing trunk defect, not caused by this PR: a column-list PRIMARY KEY on CREATE TABLE ... AS <table function> is hoisted to PRIMARY KEY tuple(x) and cannot be parsed back. 77 rows across 55 distinct PRs with 2 true-master rows in the last 30 days #116645 (mine, open)
AST fuzzer (amd_debug, targeted, old_compatibility) / same assertion same defect, same failing shape: ... AS postgresql(...) PRIMARY KEY tuple(x). The targeted corpus picked postgresql because this PR touches PostgreSQLSource.cpp, but the abort happens in AST formatting, before any source is constructed #116645 (mine, open)
Integration tests (amd_asan_ubsan, db disk, old analyzer, 1/6 .. 6/6), Integration tests (amd_asan_ubsan, targeted), Stateless tests (amd_asan_ubsan, flaky check), Stateless tests (amd_binary, flaky check) a second PR workflow run was dispatched at this same commit (33040682270 alongside 33040674324, both run_attempt 1) and the two collided on the shared build artifact: the pre-run GetObject of build_amd_binary/clickhouse failed PreconditionFailed, so these nine legs died before running. All nine are success in the sibling run at the identical tree a fix task is created (investigating at full effort - fixing-PR link to follow on this PR)
Finish Workflow same duplicate run: its aggregator errored the nine legs above. The sibling run's Finish Workflow succeeded at the identical tree a fix task is created (investigating at full effort - fixing-PR link to follow on this PR)
PR report rollup; it is red only because of the two AST fuzzer rows above. praktika reports 154 OK, 19 SKIPPED, 0 DROPPED at this head #116645 (mine, open)
CH Inc sync pending CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260827-103000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the two ledger rows above (the duplicate PR workflow run at this commit, and the
Finish Workflow that errored its nine legs): #116701

It gives the pull_request workflows a concurrency group keyed on workflow, PR number and head
sha with cancel-in-progress, so a second dispatch at one commit supersedes the first instead of
racing it over the artifact keys and the shared result document.

One conflict, in SourceFromSingleChunk's SharedHeader constructor. Master gave it
an enable_auto_progress parameter and forwards it to ISource; this branch had
dropped the manual cloneEmpty() from the same call. Kept both: the parameter and
its forwarding stay, the block is passed straight through, and ISource strips the
rows.
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 76a03bc

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Fast test (arm_darwin) / 01599_multiline_input_and_singleline_comments test hangs to the runner cap, macOS only #117053 (ours, open)
CH Inc sync private sync CH Inc sync (not actionable by me)

Mergeable Check and PR are aggregates of those two jobs, not separate failures. Nothing else failed: 153 passed, and CIDB reports one failing test for this commit.

Not caused by this PR: that test drives an interactive client and waits on a fixed sleep for the prompt, which has nothing to do with a source's pipeline header. Over the last 30 days it failed 13 times, on 13 other pull requests and never on master, always and only in Fast test (arm_darwin). #117053 replaces the sleep with a wait on the prompt and changes nothing else.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116641&sha=76a03bc8bf9b2847d0009cd0a0e8132797896a6f&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29

Session id: cron:our-pr-ci-monitor:20260829-180000

rorylshanks pushed a commit to rorylshanks/ClickHouse that referenced this pull request Sep 2, 2026
A PR that is opened and then reopened seconds later delivers two pull_request
events at one head commit, so GitHub dispatches two complete PR workflow runs in
parallel. Both are run_attempt = 1, and TEMPLATE_PULL_REQUEST_0 emits no
concurrency block, unlike TEMPLATE_SCHEDULE and TEMPLATE_DISPATCH_WORKFLOW, so
neither run supersedes the other.

Everything the two runs share is keyed by (PR, sha) and never by RUN_ID: the S3
artifact objects from _Environment.get_s3_prefix_static, and the
result_<workflow>.json document merged by _ResultS3.update_workflow_results. Two
consequences measured at one commit of ClickHouse#116641 and of ClickHouse#116642:

  - Nine legs of one run died in the praktika pre-run artifact download with
    PreconditionFailed, because the other run re-uploaded the key while the
    ranged GET was in flight, so its ETag precondition no longer held. All nine
    are success in the sibling run at the identical tree, and two of them are
    flaky check legs. praktika had already closed this same race for the
    submodule cache object alone, with an If-None-Match write-once create in
    native_jobs.py.

  - The losing run's Finish Workflow read the shared result document while the
    other run's per-arch jobs were still RUNNING, and published "No per-arch
    Bugfix Validation job validated the bug". The sibling run contradicts it
    with three success jobs.

Emit a concurrency group of workflow, PR number and head sha, with
cancel-in-progress, for pull_request workflows. The head sha is in the group so
a push starts a new group and never cancels the run at the previous commit. When
the second run appears the first has created exactly one job, Config Workflow,
so a supersession cancels that job and nothing else.

The group is populated per event rather than written into the template, because
TEMPLATE_PULL_REQUEST_0 is shared with the push workflows, where
github.event.pull_request is null. A literal in the template would give MasterCI
a degenerate group and, with cancel-in-progress, cancel every in-flight run on
every master commit. master.yml and release_branches.yml stay byte-identical.

The close-and-reopen originates from an app outside this repository. This change
neither depends on it nor alters it, and a genuinely reopened PR still gets a
run.

retry_infra_failures.yml partially masks this today: a pre-run S3 failure is
classified as infrastructure by its rule for a Run step that failed in under two
minutes, and the run is retried.

Co-Authored-By: Claude Opus 5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 4, 2026
…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.
@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog and removed pr-bugfix Pull request with bugfix, not backported by default labels Oct 12, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logical error: Expected the argument №A ('B' of type C) to have D rows, but it has E (STID: 2959-3bc4)

2 participants