Repository navigation
Build the hive partition strategy read glob from the format's registered file extensions - #120319
Conversation
…tensions With partition_strategy='hive', the read path glob was built from the lowercased format name. For any format whose name is not the extension real files carry (JSONEachRow over .jsonl / .ndjson, CSVWithNames over .csv, TabSeparated over .tsv, ...), the glob matched no files and the table was silently empty: the listing succeeded and the glob filter dropped every file, with no error or warning. The glob also depended on the user's spelling of the format: format='TSV' read .tsv files while format='TabSeparated' read nothing over the same lake. Build the glob from every file extension registered for the format in FormatFactory (or for its WithNames/WithNamesAndTypes base format) instead. The lowercased format name is always a part of the set, so the files written by ClickHouse itself keep matching.
…r TabSeparated The extension-to-format registry maps every extension to a single format for format-from-file-name inference, so it cannot express that NDJSON lakes commonly name their files .json (which infers as JSON), or that TabSeparated and TSV are independent spellings of the same format. Add registerAdditionalFileExtension for extensions that carry data readable as the format without participating in inference, and register the two cases above.
…egistry Keep a single registerFileExtension method and give it a used_for_format_inference flag instead of a second method: the extension always joins the new format -> extensions map that getFileExtensionsForFormat reads, and only inference-visible extensions go to the extension -> format map. Alias spellings now also keep their extension claims where the inference mapping was overwritten (e.g. format JSONL still claims .jsonl).
|
Workflow [PR], commit [87be10d] Summary: ✅
AI ReviewSummaryThis PR fixes Findings
Final Verdict
LLVM Coverage ReportMeasured on commit 87be10d.
Changed lines: Changed C/C++ lines covered: 236/243 (97.12%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes146 object files changed (+77.91 KiB total), 0 added.
719 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 units395 translation units recompiled, 2967 s compile time in total, 395 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.05 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
…ormat-extension-glob
…xtension lookup `getFileExtensionsForFormat` consulted only the exact format name (plus its `WithNames`/`WithNamesAndTypes` base), so the extra extensions registered for one spelling did not carry over to the interchangeable ones: a hive table declared as `format = 'JSONLines'` still built `**.jsonlines` and missed ordinary NDJSON files, and the same applied to `JSONL`, `NDJSON`, `TSV`, `TSVRaw` and `Raw`. Add `FormatFactory::registerFormatAlias`, which records that a format name is an interchangeable spelling of another one. It is consulted by `getFileExtensionsForFormat` only - the alias stays a format of its own everywhere else, and format inference is untouched. `.tsv` is now registered for `TabSeparatedRaw` as well, because the raw flavour reads the same files. Also renumber the test to `05233` (`05219` is taken on master) and cover the `JSONLines` and `TSVRaw` spellings in it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ormat-extension-glob
…ad glob
Every interchangeable spelling of a format is a format of its own and carries
its own name as a file extension, so a hive lake written as `JSONLines` is a
lake of `.jsonlines` files. Resolving the requested spelling to its canonical
name was therefore not enough: reading that lake back as `JSONEachRow` still
globbed only `{jsoneachrow,json,jsonl}` and returned nothing. The same
asymmetry applied to `Raw` / `TSVRaw` against `TabSeparatedRaw`, and to the
`WithNames` flavours of those spellings.
`registerFormatAlias` now also records the reverse mapping, and
`getFileExtensionsForFormat` collects the whole group of spellings - the
canonical name plus all of its aliases - for the requested format and for its
`WithNames`/`WithNamesAndTypes` base, adding the suffixed spellings as well.
`05233_hive_partition_strategy_format_extensions` covers both new directions:
a `.jsonlines` lake read as `JSONEachRow` and a `.tsvwithnames` lake read as
`TabSeparatedWithNames`. A control proved the glob stays format-scoped:
`JSONStringsEachRow` still reads 0 rows from the same `.jsonlines` lake.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 Pushed The only red on the previous head was |
`HiveStylePartitionStrategy::getPathForRead` built the glob from the bare file extensions registered for the format, but `GlobIterator` matches that glob against the object key as it is listed, long before `ReadBufferIterator` derives the compression method from the file name. A hive table over a lake of `key=1/data.jsonl.gz` objects therefore filtered every object out and stayed silently empty - the very bug this pull request fixes for uncompressed lakes. The configured compression method is now passed down to the strategy and the glob spells out the file name suffixes the reader would accept: all of them for `auto`, the suffixes of that one method for an explicit method, none for `none`. The bare extensions are always kept, because an explicit method also applies to files named without any suffix - and that is what `getPathForWrite` produces. The suffixes now live in a single place in `CompressionMethod.cpp`, shared with `chooseCompressionMethod`, so the glob and the reader cannot drift apart. `05233` gains a gzipped lake read with the default `auto` and with an explicit `compression_method = 'gzip'`. Control: the same lake read with `none` or with `zstd` returns 0 rows, so the glob stays scoped to the compression in effect. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 Pushed
The suffix list now lives in a single place in Both required actions are covered: The only red on the previous head was |
…ormat-extension-glob
…g a suffix-less glob `getFileSuffixesForCompressionMethodHint` returned an empty list for any hint it did not recognize, which is indistinguishable from `none`. On the `hive` path the glob is then built without compression suffixes, and because table reads set `throw_on_zero_files_match = false`, a table over `key=1/data.jsonl.gz` declared with `compression_method = 'not_a_codec'` read zero rows instead of reporting the invalid codec. The helper now throws the same `Unknown compression method` exception as `chooseCompressionMethod` (both share a single `throwUnknownCompressionMethod`), so the error surfaces when the strategy is initialized. `none`, `auto` and the empty hint keep their meanings. `05233` covers the misspelled codec. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…` loadable `HiveStylePartitionStrategy::getPathForRead` runs from `initPartitionStrategy` on `ATTACH` and at server startup too, so throwing `Unknown compression method` there made an existing `partition_strategy = 'hive'` table with a misspelled codec unloadable after upgrade. The glob builder no longer validates: any explicit hint other than `none` gets the suffix alternatives, so reads of such an attached table reach `chooseCompressionMethod` and fail loudly instead of matching nothing. `initPartitionStrategy` rejects the codec when `is_create_query`, so new DDL keeps the early error. `05233` gains an `ATTACH` case. Addresses review: ClickHouse#120319 (comment) (clickhouse-gh) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Pushed
|
The flaky check failed on the misspelled-codec `ATTACH` case: `SELECT count()` printed `0` matches of `Unknown compression method`. Earlier reads of the same `gz_lake` cache per-file row counts, the cache key does not include the compression method, and `count()` is answered from it without opening the files, so the misspelled codec is never looked at. Read real columns instead. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120319&sha=19586ff695f61dafca7db79c013bbdf2f129c733&name_0=PR&name_1=Stateless%20tests%20(amd_debug%2C%20flaky%20check) ClickHouse#120319 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ormat-extension-glob
|
🕵 Pushed The The other reds are unrelated: One review thread is still open: the |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120319&sha=256c2d13b6eb62d207bdf619104186595f5b3366&name_0=PR&name_1=Stress%20test%20%28amd_msan%29 ( |
|
The fix is in progress in #122699. Root cause, from #113856: with |
…ormat-extension-glob
|
🕵 Pushed |
…nt()` from the row-count cache The per-file row-count cache is keyed by path, format and format settings, but not by `compression_method`, and answering `count()` from it never opens the object. A `hive` table loaded by `ATTACH` with a misspelled codec (not rejected there, so that startup cannot fail) therefore returned a row count cached through another, valid definition of the same objects, instead of `Unknown compression method`. The codec is now checked with `chooseCompressionMethod` before the cache is consulted, as the actual read would. `05233` warms the cache through a valid `gzip` definition (after waiting for the lake to age past the second of its last write, since a row count cached in the same second as the file was modified is not trusted) and then checks `count()` on the attached table. Without the fix it returns the cached count. ClickHouse#120319 (comment) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…licit compression method The per-file row-count cache is keyed by path, format and format settings, but not by the compression method. Under an explicit `compression_method` the codec does not follow from the object name, so a row count cached through a `gzip` definition could answer `count()` for an `auto` or `none` definition of the same objects, which would fail (or decode differently) on a real read. Row counts are now neither cached nor looked up unless the compression method is derived from the path (an empty hint or `auto`), which also covers schema inference (`ReadBufferIterator::setNumRowsToLastFile`). This supersedes the earlier explicit validation of the codec before the cache lookup: a misspelled codec is explicit, so `count()` now reads the object and throws `Unknown compression method` as a real read does. ClickHouse#120319 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
The warm-up `count()` went through a `key=N/` path, where `use_hive_partitioning` together with a randomized `optimize_count_from_files = 0` returns `0` instead of the row count (an unrelated existing bug), which made the flaky checks fail. It also mixed positional and key-value arguments of `s3`, which the parallel-replicas run rejects with `Expected positional arguments to go before key-value arguments`. Since explicit compression methods no longer use the row-count cache at all, the warm-up through an explicit `gzip` definition proved nothing anymore. The cache is now warmed through autodetection on a plain file outside of any hive-style path, with positional `s3` arguments, and `count()` with an explicit `gzip` codec over the same file must fail instead of returning the cached count. https://s3.amazonaws.com/clickhouse-test-reports/PRs/120319/2bb9fbb5b60a28741c09e95cfacae6cfd6973eb4/pr/result_pr.json Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/PRs/120319/2bb9fbb5b60a28741c09e95cfacae6cfd6973eb4/pr/result_pr.json (flaky checks of The cause is unrelated to this PR. With INSERT INTO FUNCTION s3('http://localhost:11111/test/x/key=9/b.jsonl', 'test', 'testtest', 'JSONEachRow') SELECT 11 AS id;
SELECT count() FROM s3('http://localhost:11111/test/x/key=9/b.jsonl', 'test', 'testtest', 'JSONEachRow') SETTINGS optimize_count_from_files = 0; -- 0, expected 1
SELECT count() FROM s3('http://localhost:11111/test/x/key=9/b.jsonl', 'test', 'testtest', 'JSONEachRow') SETTINGS optimize_count_from_files = 0, use_hive_partitioning = 0; -- 1
|
|
Acknowledged. I found no fix in progress for this; I'm investigating why |
…sion method The schema cache key does not include the compression method, and a cache hit never opens the object. A schema cached through autodetection could be reused by schema inference under an explicit `compression_method` (or a misspelled one on an attached table), even though a real read would throw. Gate schema-cache reads and writes in `ReadBufferIterator` on `isCompressionMethodHintAuto`, the same as the row-count cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The fix is in #123381. When a query needs no column of the data file, |
|
🕵 Thanks @groeneai, #123381 is the right place for the hive-path |
…f the data file When a query needs no column of the data file (count() without the count-from-files shortcut, only Hive partition or virtual columns, `_row_number`), `prepareReadingFromFormat` falls back to reading the smallest column of the data file. The candidates still contained the Hive partition columns, and an integer or Date key is smaller than any Nullable or String data column, so a partition column was chosen. Since ClickHouse#87528 partition columns are never put into the format header, so the header became empty: row formats then return no rows (and the 0 is stored in the row-count cache), Native throws LOGICAL_ERROR. Pick the smallest non-partition column instead, as 5b4e7ed did for Delta Lake. A structure that lists only partition columns has no other column, so the previous choice is kept for it: the count-from-files path and Parquet already read such a structure correctly. Found by the flaky check of ClickHouse#120319 (05233 with a randomized optimize_count_from_files = 0). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix object storage tables with
partition_strategy = 'hive'being silently empty for formats whose name is not the file extension real files carry. The read glob was built from the lowercased format name (**.jsoneachrow,**.csvwithnames), so pointing aJSONEachRowtable at a lake of.json/.jsonlfiles — or aCSVWithNamestable at.csvfiles — read zero rows with no error or warning. The glob is now built from every file extension registered for the format (and for itsWithNames/WithNamesAndTypesbase format), plus additionally registered read extensions:JSONEachRowmatches.json/.jsonl/.ndjsonfiles andTabSeparatedmatches.tsv. Files written by ClickHouse itself keep matching.Description
HiveStylePartitionStrategy::getPathForReadusedprefix + "**." + Poco::toLower(file_format)— the format's name, not a file extension. ForParquetthe two coincide and everything works, which is presumably how this survived. For most other formats they don't, and the failure is a silent data-correctness trap: the listing succeeds, the glob filter rejects every file, and the table returns zero rows.The outcome even depends on the user's spelling of the same format:
CSV**.csv.csvTSV**.tsv.tsvTabSeparated**.tabseparated.tsvCSVWithNames**.csvwithnames.csvJSONEachRow**.jsoneachrow.json/.jsonlRepro (any S3-compatible endpoint):
The fix adds
FormatFactory::getFileExtensionsForFormat: all extensions registered for the format, or for itsWithNames/WithNamesAndTypesbase format, plus always the lowercased format name (every format's name is registered as its own extension). The inference registry maps each extension to a single format, so it cannot express that NDJSON lakes commonly name their files.json(which infers asJSON), or thatTabSeparatedandTSVare independent spellings of the same format — soregisterFileExtensiongains aused_for_format_inferenceflag: every registered extension joins a new format → extensions map thatgetFileExtensionsForFormatreads, and only inference-visible extensions go to the extension → format map..jsonis registered forJSONEachRowand.tsvforTabSeparatedwith the flag off, leaving format-from-file-name inference untouched.getPathForReadbuilds a brace-alternation glob from the set:JSONEachRow→**.{json,jsoneachrow,jsonl,ndjson},CSVWithNames→**.{csv,csvwithnames}.Several formats are registered under interchangeable spellings (
JSONLines,JSONL,NDJSONforJSONEachRow;TSVforTabSeparated;TSVRawandRawforTabSeparatedRaw), each as an independent format, and the extensions are registered for the canonical spelling only — soformat = 'JSONLines'would have stayed on the silent-empty path.FormatFactory::registerFormatAliasrecords these spellings andgetFileExtensionsForFormatresolves them (both for the name as typed and for the name left after stripping aWithNames/WithNamesAndTypessuffix, soTSVWithNamesreaches theTabSeparatedset). The alias is a format of its own everywhere else and format inference is untouched..tsvis also registered forTabSeparatedRaw, whose files carry that extension too.The write path (
<snowflake id>.<lowercased format name>) is unchanged, and since the format name is always in the extension set, data written by ClickHouse itself keeps being read back — the added test covers a mixed lake (a pre-existing.jsonlfile plus a file written through the table), as well as.json,.csvand.tsvlakes.Verified the new stateless test fails before the fix (official 26.9.1.1560 binary with minio via
clickhouse-test) and passes with it.Workflow [PR]
Sync PR [sync-upstream/pr/120319]
Version info
26.10.1.1309-master(included in26.10and later)