Skip to content

Build the hive partition strategy read glob from the format's registered file extensions - #120319

Merged
alexey-milovidov merged 29 commits into
ClickHouse:masterfrom
zatchet:fix-hive-strategy-format-extension-glob
Oct 2, 2026
Merged

alexey-milovidov merged 29 commits into
ClickHouse:masterfrom
zatchet:fix-hive-strategy-format-extension-glob

Conversation

@zatchet

@zatchet zatchet commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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 a JSONEachRow table at a lake of .json / .jsonl files — or a CSVWithNames table at .csv files — read zero rows with no error or warning. The glob is now built from every file extension registered for the format (and for its WithNames/WithNamesAndTypes base format), plus additionally registered read extensions: JSONEachRow matches .json/.jsonl/.ndjson files and TabSeparated matches .tsv. Files written by ClickHouse itself keep matching.

Description

HiveStylePartitionStrategy::getPathForRead used prefix + "**." + Poco::toLower(file_format) — the format's name, not a file extension. For Parquet the 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:

Format argument Glob built Over real files Result
CSV **.csv .csv works
TSV **.tsv .tsv works
TabSeparated **.tabseparated .tsv silently empty
CSVWithNames **.csvwithnames .csv silently empty
JSONEachRow **.jsoneachrow .json / .jsonl silently empty

Repro (any S3-compatible endpoint):

INSERT INTO FUNCTION s3('http://minio:11111/test/lake/key=1/data.jsonl', 'test', 'testtest', 'JSONEachRow') SELECT 1 AS id;

CREATE TABLE t (id UInt64, key UInt64)
ENGINE = S3('http://minio:11111/test/lake', 'test', 'testtest', format = 'JSONEachRow', partition_strategy = 'hive')
PARTITION BY key;

SELECT * FROM t;  -- 0 rows; rename the file to `.jsoneachrow` and it returns 1 row

The fix adds FormatFactory::getFileExtensionsForFormat: all extensions registered for the format, or for its WithNames/WithNamesAndTypes base 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 as JSON), or that TabSeparated and TSV are independent spellings of the same format — so registerFileExtension gains a used_for_format_inference flag: every registered extension joins a new format → extensions map that getFileExtensionsForFormat reads, and only inference-visible extensions go to the extension → format map. .json is registered for JSONEachRow and .tsv for TabSeparated with the flag off, leaving format-from-file-name inference untouched. getPathForRead builds a brace-alternation glob from the set: JSONEachRow → **.{json,jsoneachrow,jsonl,ndjson}, CSVWithNames → **.{csv,csvwithnames}.

Several formats are registered under interchangeable spellings (JSONLines, JSONL, NDJSON for JSONEachRow; TSV for TabSeparated; TSVRaw and Raw for TabSeparatedRaw), each as an independent format, and the extensions are registered for the canonical spelling only — so format = 'JSONLines' would have stayed on the silent-empty path. FormatFactory::registerFormatAlias records these spellings and getFileExtensionsForFormat resolves them (both for the name as typed and for the name left after stripping a WithNames/WithNamesAndTypes suffix, so TSVWithNames reaches the TabSeparated set). The alias is a format of its own everywhere else and format inference is untouched. .tsv is also registered for TabSeparatedRaw, 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 .jsonl file plus a file written through the table), as well as .json, .csv and .tsv lakes.

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

  • Merged into: 26.10.1.1309-master (included in 26.10 and later)

…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).
@clickhouse-gh clickhouse-gh Bot added comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. external Author is not a member of the ClickHouse organization labels Sep 16, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Sep 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [87be10d]

Summary: ✅


AI Review

Summary

This PR fixes hive object-storage reads to build their glob from registered format extensions, alias spellings, and accepted compression suffixes, and it also tightens the row-count/schema cache behavior for explicit compression_method hints. I still see one blocker in the explicit-codec path: the new .<format>.* pattern treats arbitrary siblings after the format extension as data, so a valid lake can start throwing on metadata sidecars such as *.parquet.crc.

Findings
  • ❌ Blockers
    • [src/Storages/IPartitionStrategy.cpp:410] [dismissed by author -- https://github.com/Build the hive partition strategy read glob from the format's registered file extensions #120319#discussion_r4078915291] HiveStylePartitionStrategy::getPathForRead widens every explicit-codec extension to <extension>.*. That keeps custom-suffix data readable, but it also pulls in foreign sidecars that share the same base name, e.g. data.parquet.crc next to data.parquet. ReadBufferIterator then trusts the explicit codec and opens those sidecars as data, so a correctly configured table can fail with exceptions even though every real data file is valid. The earlier “explicit codecs are name-agnostic” argument does not require treating arbitrary metadata siblings as rows.
    • Suggested fix: keep explicit-codec matching format-scoped instead of unconditional .*, or add a second filter that drops non-data siblings before ReadBufferIterator opens them; in either case add a focused regression case with a real data file plus a .crc-style sibling.
Final Verdict
  • Status: ❌ Block
  • Minimum required actions: stop the explicit-codec hive glob from selecting foreign sidecars, and cover that case with a focused regression test.

LLVM Coverage Report

Measured on commit 87be10d.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 236/243 (97.12%) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 19, 2026
Comment thread src/Formats/FormatFactory.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). and removed comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. labels Sep 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 87be10d2e with master 38c3aeff5 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

146 object files changed (+77.91 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Formats/FormatFactory.cpp.o 481.48 KiB 524.07 KiB +42.59 KiB (+8.84%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

395 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.
The matched translation units cost +144.8 s (+5%) in total before that adjustment.

Job report

alexey-milovidov and others added 3 commits September 19, 2026 18:03
…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]>
Comment thread src/Formats/FormatFactory.cpp Resolved
alexey-milovidov and others added 2 commits September 20, 2026 16:16
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed c77130284ad6: merged master (52 behind, clean) and adopted the AI Review blocker — the alias lookup in getFileExtensionsForFormat now walks in both directions, so a lake written through one spelling of a format (JSONLines → .jsonlines, TSVWithNames → .tsvwithnames) is readable through any other spelling of it. 05233_hive_partition_strategy_format_extensions covers both new directions and passes against a real MinIO; a control proved the glob stays format-scoped (JSONStringsEachRow still reads 0 rows from the same .jsonlines lake).

The only red on the previous head was 05227_storage_settings_unknown_name, which fails fleet-wide on master and is unrelated to this PR — the fix is in flight in #121163. The Finish Workflow / new_tests_check.py red is a cascade of it: the Bugfix validation jobs were dropped because the stateless job failed on 05227.

Comment thread src/Storages/IPartitionStrategy.cpp Resolved
alexey-milovidov and others added 2 commits September 20, 2026 19:33
`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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed 4b7131375e3b, which adopts the AI Review blocker: the hive read glob is now compression-aware.

GlobIterator filters the listing by the object key, and only ReadBufferIterator derives the compression method from the matched file name afterwards, so a lake of key=1/data.jsonl.gz objects was filtered out entirely — the same silent-empty misread this pull request fixes for uncompressed lakes. The configured compression method is now threaded into HiveStylePartitionStrategy, and getPathForRead spells out the file name suffixes the reader would accept: every suffix for auto (the default), the suffixes of that one method for an explicit method, none for none. The bare extensions are always kept as well, because an explicit method also applies to files named without any suffix — and that is exactly what getPathForWrite produces.

The suffix list now lives in a single place in CompressionMethod.cpp, and chooseCompressionMethod matches against it too, so the glob and the reader cannot drift apart. Every accepted spelling (gz, gzip, deflate, br, brotli, xz, lzma, zst, zstd, lz4, bz2, snappy, none, auto) round-trips unchanged through s3 locally, and an unknown method still raises the same NOT_IMPLEMENTED message.

Both required actions are covered: 05233_hive_partition_strategy_format_extensions now reads a gzipped lake with the default auto and with an explicit compression_method = 'gzip', and passes against a real MinIO together with the rest of the partition_strategy family. Control: the same gzipped lake read with none or with zstd returns 0 rows, so the glob stays scoped to the compression actually in effect.

The only red on the previous head was Build profile diff, which is the fleet-wide CI-infrastructure failure tracked in #120462 and unrelated to this change.

Comment thread src/IO/CompressionMethod.cpp Resolved
alexey-milovidov and others added 2 commits September 21, 2026 11:43
…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]>
Comment thread src/Storages/IPartitionStrategy.cpp Resolved
…` 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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed 19586ff695f6, which covers the two edge cases from the latest AI Review:

  • Adopted: ATTACH / startup compatibility. The unknown-codec check now runs only on CREATE (initPartitionStrategy, is_create_query). Old metadata still loads, and reading it reports Unknown compression method. 05233 gained an ATTACH case.
  • Not changed, left for a maintainer to decide: sidecar files under an explicit codec. .<ext>.* is the only glob that satisfies both earlier Blockers (explicit codec ignores the name, and the match stops at the format boundary). The reasoning is in the thread.

alexey-milovidov and others added 2 commits September 28, 2026 06:33
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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed 256c2d13b6eb: merged master (3841 behind, clean) and fixed the 05233_hive_partition_strategy_format_extensions flaky-check red.

The ATTACH case ran SELECT count() on the misspelled-codec table. The earlier reads of the same gz_lake had cached per-file row counts, and that cache key does not include the compression method, so count() was answered from the cache without opening the files, and the codec was never looked at. The CI server log shows it: SELECT count() FROM test_n4i5a3o7v1t4_attach.bad_codec → Read 3 rows with 0.00 B aggregated. The test now reads real columns. 05233 passes 16/16 locally with --flaky-check and randomized settings, against MinIO.

The other reds are unrelated: Stress test (arm_release) GroupingAggregatedTransform pushed bucket A twice is #115986, and the perf slowdown in optimize_time_filter_with_preimage #6 is in a query path this PR does not touch.

One review thread is still open: the .parquet.crc sidecar under an explicit codec. The finding contradicts the earlier Blocker that asked for name-agnostic matching under an explicit codec, so it needs a human decision.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @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 (MemorySanitizer: use-of-uninitialized-value in the std::variant<PostingListBuilder::Inline, Large, Filtered> destructor, reached from MergeTreeDataPartWriterCompact::writeDataBlockPrimaryIndexAndSkipIndices while destroying a text-index aggregator) and provide a fix in a separate PR. If the fix is already in progress, link it here. This PR only changes the hive partition strategy read glob, format extension registration and glob parsing; it does not touch the text index.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is in progress in #122699.

Root cause, from #113856: with support_phrase_search = 1, addToken inserts the token into the map before constructBuilder constructs its posting list builder in the cell, and that constructor allocates. When the allocation throws, the builder is destroyed while the map still owns the cell, and destroying the text index aggregator later destroys it a second time, which is what MSan catches. #122699 constructs an empty Filtered builder in the cell before rethrowing.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed a7bc31423cad: merged master (1943 commits behind, clean). This pulls in #122699 (thanks @groeneai), which fixes the previous Stress test (amd_msan) red in the PostingListBuilder destructor. clickhouse and unit_tests_dbms rebuilt with 0 errors. The glob gtests (31/31) and 05233_hive_partition_strategy_format_extensions pass locally against MinIO.

…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]>
alexey-milovidov and others added 3 commits October 1, 2026 20:04
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/PRs/120319/2bb9fbb5b60a28741c09e95cfacae6cfd6973eb4/pr/result_pr.json (flaky checks of 05233) and provide a fix in a separate PR. If the fix is already in progress, link it here.

The cause is unrelated to this PR. With use_hive_partitioning = 1 (the default) and optimize_count_from_files = 0, count() over an s3 object under a hive-style path returns 0. Compressed and plain files are both affected, and with use_hive_partitioning = 0 the result is correct. The wrong 0 is also stored in the row-count cache, so later count() queries with default settings return 0 too. Reproduced on the current build against minio:

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

05233 no longer goes through this path (d4d06ce), so this PR is not blocked by it.

@groeneai

groeneai commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Acknowledged. I found no fix in progress for this; I'm investigating why count() over a hive-style s3 path returns 0 with optimize_count_from_files = 0 (and why that 0 lands in the row-count cache). I'll follow up here with a PR (or my findings) shortly.

…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]>
@groeneai

groeneai commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

The fix is in #123381.

When a query needs no column of the data file, prepareReadingFromFormat reads the smallest column, and the candidates included the Hive partition columns. The Int64 key won over Nullable(Int64) and was then dropped from the format header (partition columns are never read from the file since #87528), so the row format returned no rows and the 0 went into the row-count cache. The fallback now picks the smallest non-partition column. The same path serves file and url, and released 26.3 and 26.8 return 0 too.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Thanks @groeneai, #123381 is the right place for the hive-path count() = 0 fix. This PR does not depend on it, because 05233 no longer goes through that path (d4d06ceaa79). CI on the current head 87be10d2e8b is still running and nothing has failed yet, so I am not pushing anything now. One review thread is still open: whether an explicit-codec hive glob should also match .<ext>.<anything> siblings such as .parquet.crc. Two earlier AI Review findings contradict each other there, so a maintainer needs to decide.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 2, 2026
Merged via the queue into ClickHouse:master with commit 782be4d Oct 2, 2026
149 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 2, 2026
alexey-milovidov pushed a commit to Onyx2406/ClickHouse that referenced this pull request Oct 3, 2026
…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]>
groeneai pushed a commit to groeneai/ClickHouse that referenced this pull request Oct 10, 2026
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-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants