Repository navigation
Conversation
readSchemaFromFormatImpl rejects an empty inference result at ReadSchemaUtils.cpp:507, but the filter that drops columns with empty names runs 36 lines later, at :542-545, and the return at :547 is unchecked. An inference result in which every column name is empty therefore passes the guard as non-empty and is returned as a zero-column ColumnsDescription. TableFunctionFormat::parseData builds the input-format header from that empty structure, FormatFactory::getInputImpl has no zero-column guard, and RowInputFormatWithNamesAndTypes::readPrefix() then evaluates data_types.at(0) on an empty vector. std::out_of_range is a std::logic_error, so getCurrentExceptionMessageAndPattern routes it to abortOnFailedAssertion on a build with abort_on_logical_error (server abort, which is how the AST fuzzer surfaced it) and returns Code: 1001 STD_EXCEPTION to the user otherwise. Header detection is how an all-empty-names header arises: readNamesFromFields unescapes the first row, and both CSV "" and TSV \N unescape to the empty string. On stable 26.8.6.5, SELECT * FROM format(CSV, '""\n42\n') returns Code: 1001 and DESCRIBE on the same input succeeds while reporting zero columns. Add the missing emptiness check immediately after the erase. This is the producer rather than the crash site, so one hunk covers all seven RowInputFormatWithNamesAndTypes instantiations, and every downstream consumer already treats "no structure" as CANNOT_EXTRACT_TABLE_STRUCTURE. A guard in RowInputFormatWithNamesAndTypes would instead treat the symptom, and its precondition would be state that is already corrupt. Only columns whose name is empty are still dropped, and header detection is unchanged; both are pinned as controls in the new test, along with the single-row case that is never treated as a header. Co-Authored-By: Claude Opus 5 <[email protected]>
readSchemaFromFormatImpl checks for an empty inference result 36 lines before the filter that drops empty-named columns, and the return after that filter is unchecked. A header whose names all unescape to the empty string therefore passes the check and comes back as a zero-column structure, so RowInputFormatWithNamesAndTypes::readPrefix() evaluates data_types.at(0) on an empty vector. That is std::out_of_range, which derives from std::logic_error, so a debug or sanitizer build turns it into an abort; a release build returns Code: 1001 and answers DESCRIBE with no columns at all. Header detection produces the input: both CSV "" and TSV \N unescape to the empty string. The check goes at the producer rather than the crash site, so one place covers every RowInputFormatWithNamesAndTypes instantiation and that file is untouched. The same unfiltered list is also published to the per-storage schema cache, and a cache hit is handed back verbatim, so a second read of the same file() bypassed both the filter and the new check: it returned one unnamed column, and reading that column aborted the server at chassert(!part.empty()) in ASTIdentifier, reached through ColumnNode::toASTImpl. Both cache writes now publish the filtered list and skip the write when nothing survives it. They copy the list instead of mutating it, so UNION-mode accumulation and format adoption in the detection loop are unaffected. Four callers run inference only to learn the detected format and discard the columns, because they already hold an explicit structure: StorageFile and StorageURL when the engine or table function was given a structure and format auto, StorageFileCluster, and StorageObjectStorage through resolveFormatFromData. For them an inferred structure that is unusable on its own is not an error, and rejecting it would fail a query that did supply a structure and then advise the user to supply one. They pass structure_is_required = false; the parameter defaults to true, so every other call site is unchanged. The regression test covers both readers the CI history shows, the cached-read path, and the format-only path. It needs a one second sleep because SchemaCache::tryGetImpl invalidates an entry when the file's modification time is not strictly older than the entry's registration second, which would otherwise make the cached-read assertions pass without ever consulting the cache. Co-Authored-By: Claude Opus 5 <[email protected]>
Two follow-ups to the previous commit, both the second half of a pair it changed on one side only. StorageURLCluster is a fifth caller that runs inference only to learn the detected format, structurally identical to StorageFileCluster: the same else branch of if (columns_.empty()), the same consumption of .second alone. It was missed because structure_is_required defaults to true, so omitting the argument opts into the rejection and nothing fails to build. The effect was that urlCluster(cluster, url, auto, 'a Nullable(Int64)') over data whose inferred names are all empty was rejected and told to specify the structure manually, for a query that did supply one. The enumeration behind the previous commit was rerun over src, programs and utils and classified by how each site consumes the returned pair; five sites want the format only and all five now ask for it. The previous commit also claimed that copying the list at the two cache writes left UNION-mode accumulation unaffected. That was wrong. A cache hit contributes cached_columns->getAll(), which those writes had made filtered, while a freshly inferred file contributed names_and_types, which is not; the merge keys on column name and raises TYPE_MISMATCH when two files disagree on a type, and empty names are dropped only after the merge. So a glob over a mix of named and empty-named files could fail on a cold cache and succeed on a warm one. Both fresh-read sites now contribute the same filtered list, which also means UNION mode no longer raises TYPE_MISMATCH over a column named "" that it was about to drop. The filter deliberately stays where it is. The format-detection loop uses an empty inferred schema to decide that a candidate format did not match, both in the skip at the top of the loop and in the comparison that picks the format with the most columns, so filtering earlier would silently reclassify an all-empty-name file as some other format. The test gains four assertions. Two read system.schema_inference_cache directly, because every existing cache assertion expects exactly what a fresh inference returns and so cannot tell a hit from a miss; the count of cached entries is restricted to a non-null schema because setNumRowsToLastFile still records a row count for a file whose structure is not cached. Two more read a two-file glob under schema_inference_mode = 'union' twice, cold and warm. That pair needs JSONColumns with the format passed explicitly: JSONColumns retains empty JSON keys and supports reading a subset of columns, so union mode accepts it, while an extension-less path never reaches the cache lookup and CSV is refused by union mode outright. The two files share only the empty name, as Nullable(Int64) against Array(Nullable(Int64)), a pair the JSON type transform cannot unify, so an unfiltered contribution collides. The last assertion reads the format-only fixture through fileCluster, since the existing one covers only one of the five format-only call sites. Co-Authored-By: Claude Opus 5 <[email protected]>
Fix round r3. Corrects a claim made in the r2 commit message. The r2 message said that filtering both UNION accumulation sites had no net effect on behaviour, "the final column set is unchanged (the union was filtered at :559 anyway)". That is false in the all-empty case, and the defect it hid is the same shape as the bug this PR fixes, one guard further down: a filter that now runs before an emptiness guard which was written for a different reason. With both UNION pushes filtered, a set of files whose every inferred name is empty merges to an empty names_and_types, and the generic "no file yielded a schema" guard fires unconditionally, before the gate that consults structure_is_required. So all five format-only callers were rejected under schema_inference_mode='union' and told to specify a structure they had already supplied, which is the regression class the structure_is_required gate exists to prevent; and the structure-required caller lost its specific message for the generic one with an empty error list, since exception_messages is empty when no file failed. Gate that guard on being in UNION mode with a non-empty accumulator, so control falls through to the existing rejection site, which is correct in both directions. The predicate is exact: in UNION mode a file that fails inference throws immediately, and an empty file throws earlier still, so a non-empty accumulator means every processed file was inferred successfully. An empty merge then means every contribution carried only empty names, which is precisely "all inferred column names are empty". When the accumulator is itself empty no file was processed at all, and the generic message stays correct and still fires. removeColumnsWithEmpty Names is a no-op on an already-empty list, so nothing else moves, and the filter is deliberately still not moved earlier: the detection loop uses an empty inferred schema to decide that a candidate format did not match. Measured on three binaries: the union format-only read answers 0 on pristine master, Code 636 on the previous revision of this PR, and 0 again here; the two-file glob does the same through the other branch of the guard; default mode is unchanged. The test gains the union format-only assertion, which reddens on the previous revision, and two query_log assertions proving that a read meant to be warm really consumed a cached structure. Without them the repeated reads could silently decay into repeated cold reads and keep matching, which would quietly disable the cold-versus-warm pair added in r2. Both were shown to fail under schema_inference_use_cache_for_file=0.
readSchemaFromFormatImpl publishes columns into the schema cache from two places: the known-format path, and the branch that detects the format from the file contents. Which one a fixture reaches is decided by its name, and every cache assertion in the test reached only the first: the two .csv fixtures carry an extension the iterator resolves a format from, and the union fixtures are read with an explicit 'JSONColumns'. The extension-less fixture is the only one whose format is detected from the bytes, and it was described once for its rejection and then read only through consumers that take the detected format name and discard the inferred columns. Dropping the filter from the detection branch therefore left every assertion in the file matching, while the structure published to the cache carried an unnamed column again. Assert that the detection branch publishes nothing carrying an empty name. The assertion is on the write rather than on a later read, so it does not depend on a file's mtime falling in an earlier second than the registration time of its cache entry, and it cannot decay into a check that passes because the cache was never consulted. Measured: on pristine master the count is 1 and the stored schema is " Nullable(Int64)", a leading space where the name should be; here it is 0. Forcing that one writer back to publishing the unfiltered list fails the test on exactly one line, 0 against 2, with every other statement byte-identical, so the new assertion is neither vacuous nor over-broad.
Collapse the structure_is_required note in ReadSchemaUtils.h to a one-line parameter contract.
Internal second-model reviewTwo independent passes per round over five rounds raised thirty items: four blockers and seven majors, all ❌ The schema cache was written before the new rejection, so a first read of a ❌ The rejection reached callers that only wanted the detected format: five sites that already hold an ❌ ❌ That fix reintroduced the rejection one guard further down (round 3): under
💡 Scope, so this does not read as more than it is: the accessor that threw reads the read port's header, 💡 Nits, all folded in: a control comment stated the wrong reason, and the description understated the caller |
|
Workflow [PR], commit [84234ff] Summary: ✅
AI ReviewSummaryReviewed commit The new Final Verdict✅ Approve — no unresolved findings. No inline review comments were posted. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260917-033800 |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units41 translation units recompiled, 372 s compile time in total, 41 of them have a recent master baseline. |
CI finish ledger - 1598a54Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Neither red is caused by this PR: the diff is confined to Session id: cron:our-pr-ci-monitor:20260917-093342 |
|
Correction to the NATS line of the ledger above, and the fixing-PR link it owed. #115343 is an ancestor of this head but its code is not: #119270 reverted it on 2026-09-10 ( Fixing PR: #119301 (external, open), which re-applies #115343, gated on #120202 pinning the vendored-client fixes behind the master reds that motivated the revert. Measured on |
…e-all-empty-column-names # Conflicts: # src/Formats/ReadSchemaUtils.cpp
Master now filters empty names from a schema-cache hit in the default mode, so the hit is no longer returned verbatim. The write-side filter is still needed: a hit skips the all-empty check, and the union mode uses cached columns as is.
The default-mode cache-hit filter merged from master now sees entries that the writers have already filtered, and with that filter in place reading the cached structure back no longer catches a writer regression on its own; the system.schema_inference_cache assertions do.
…nly empty column names Five Arrow IPC stream fuzzer files in `contrib/arrow-testing` have a schema with a single field named '' (checked with pyarrow). Master drops that column and then fails with the misleading `INCORRECT_DATA` "A hive partitioned file can't contain only partition columns"; with this PR schema inference rejects the result with `CANNOT_EXTRACT_TABLE_STRUCTURE`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e-all-empty-column-names # Conflicts: # src/Storages/StorageURL.cpp # src/Storages/StorageURL.h # src/Storages/StorageURLCluster.cpp
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
Code: 1001, std::out_of_range: vectorwhen reading aTSVorCSVinput whose detected header is entirely empty column names, such asSELECT * FROM format(CSV, '""\n42\n'); debug and sanitizer builds aborted on it instead of returning the error. Such input is now rejected withCANNOT_EXTRACT_TABLE_STRUCTURE, andDESCRIBEno longer silently reports zero columns. The structure published to the schema cache is filtered the same way, so a later read of the same file is no longer served an unnamed column.Description
The emptiness guard in
readSchemaFromFormatImplruns before the filter that drops empty-named columns, so a result whose names are all empty returns a zero-column structure, andRowInputFormatWithNamesAndTypes::readPrefix()then evaluatesdata_types.at(0)on an empty vector. Onmaster, #126591 skips that call under header detection, so the read fails withEMPTY_LIST_OF_COLUMNS_PASSEDandDESCRIBEstill reports zero columns.Header detection causes it:
readNamesFromFieldsunescapes the first row, and both CSV""and TSV\Nunescape to"".On stable 26.8.6.5:
std::out_of_rangeis astd::logic_error, which debug and sanitizer builds treat as an assertion failure; that is how CI hit it (report).The check goes after the erase, at the producer not the crash site, so one hunk covers all seven
RowInputFormatWithNamesAndTypesinstantiations.The cache was written before the erase, so a second read of the same
file()returned one unnamed column, which aborted the server inASTIdentifier. #125134 now filters a default-mode hit, but a hit still skips the new check andunionmode uses cached columns as is, so both cache writes now publish the filtered list.unionmode now merges the filtered list too, so files disagreeing on an empty-named column's type no longer fail withTYPE_MISMATCH.Five callers (
StorageFile,StorageURL, their*Clustertwins andStorageObjectStorage) run inference only to learn the format and already have an explicit structure, so they now ask for the format only.Validation: the new test fails on
master(before #126591 it killed a debug server) and passes with the fix; 50/50 randomized green; 249 related tests show no difference frommaster.Workflow [PR]
Sync PR [sync-upstream/pr/120509]