Repository navigation
Fix WHERE on a Hive partition column skipping files whose rows match it - #131256
PedroTadim merged 4 commits into
Conversation
…n type `convertFieldToType` returns `Null` for a value outside the range of the target type. The two places that materialize a Hive partition value from the path, `HivePartitioningUtils::addPartitionColumnsToChunk` and the Hive branch of `VirtualColumnUtils::addRequestedFileLikeStorageVirtualsToChunk`, passed that result straight to `createColumnConst`. For a type that cannot hold NULL the column insert then failed with `BAD_GET` (`UInt8` with `k0=300` or `k0=-1`, `Array(UInt8)` with `k0=[256]`, `Tuple`, ...), and for `LowCardinality(UInt8)` with the `LOGICAL_ERROR` "ColumnUnique can't contain null values". Both sites now call `HivePartitioningUtils::convertPartitionValueToType`, which throws `TYPE_MISMATCH` naming the value, the path, the type and the column when the result is `Null` and `canContainNull(type)` is false. That is the error class an unparsable value already gets. `Nullable` and `LowCardinality(Nullable)` keep reading such a value as NULL; `Variant` and `Dynamic` are unchanged. `convertFieldToTypeOrThrow` is not reused: it also throws for a `Nullable` target, and its message names neither the column nor the path. The path pre-filter (`addPathAndFileToVirtualColumns`) parses values with text deserialization rather than `convertFieldToType`, so it does not hit this error, and is left unchanged. Closes ClickHouse#131087 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With `use_hive_partitioning = 1`, a `WHERE` on a Hive partition column is first evaluated on the listed paths to skip files before reading (`getFilterByPathAndFileIndexes`). `addPathAndFileToVirtualColumns` built that block with text deserialization of the column type, while the readers convert the value with `convertFieldToType` (via `HivePartitioningUtils::convertPartitionValueToType`). Text parsing wraps an out-of-range integer (`300` -> 44 for `UInt8`), rejects `-1` for an unsigned type and reads the text `NULL` as SQL NULL for `Nullable(String)`, where the readers give NULL, NULL and the string 'NULL'. So the filter evaluated the condition on a value the query never sees and skipped matching files: `WHERE k0 IS NULL` over `k0=300` with `Nullable(UInt8)` returned no rows, and `WHERE a IS NOT NULL` dropped the `a=NULL` directory of a `Nullable(String)` column (ClickHouse#127133). Use the readers' conversion in the filter. A value the column type cannot hold now fails a filter on that column with the reader's TYPE_MISMATCH, as reading the column already does. Closes ClickHouse#127133 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus a separate cold review (1 finding).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261113-102100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261113-093600 |
|
Workflow [PR], commit [172fdbe] Summary: ✅
AI ReviewSummaryReviewed head The earlier stored-table format-settings discrepancy remains in the current code, but the author supplied the requested dedicated follow-up in PR #131571. That addresses the tracking alternative in the previous finding; the agreed deferral is accepted and the thread is left resolved. The deliberate conversion error during filtering is also accepted, and the storage-name consistency change is present in the current code. Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 19 s compile time in total, 7 of them have a recent master baseline. |
|
🕵️ Review — The core fix is correct: the path-filter now materializes partition values with the same 1. Eager The filter column is now built by This is asserted as intended by 2. The new filter call passes |
The path filter now takes the value of a Hive partition column from the path by `getNameInStorage()`, the name the readers use, instead of the filter block's column name, and prints the same name in the conversion error. The filter block columns carry no storage name, so the filter keeps the partition columns as `NameAndTypePair`s while building the block. No output changes: every Hive partition column is a plain `(name, type)` pair today, so both names are equal. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the review.
|
Closes: #127133
Related: #131202
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
WHEREcondition on a Hive partition column (use_hive_partitioning = 1) skipping files whose rows match it when the path filter parsed the partition value differently from the reader, for examplek0=300for aNullable(UInt8)column (read as NULL) ora=NULLfor aNullable(String)column (read as the string'NULL'). Closes #127133.Description
On 26.10.2.103 (and 26.3.33.24, 26.8.21.12),
SELECT count() FROM file('d/k0=300/data.jsonl', JSONEachRow, 'c0 Int32, k0 Nullable(UInt8)') WHERE k0 IS NULL SETTINGS use_hive_partitioning = 1returns 0, while the file's only row readsk0as NULL.A
WHEREon a partition column is first evaluated on the listed paths to skip files.VirtualColumnUtils::addPathAndFileToVirtualColumnsbuilt that filter block with text deserialization, while the readers convert withconvertFieldToType: text parsing wraps300to 44 forUInt8, rejects-1(Code: 632) and reads the textNULLas SQL NULL, so the condition was evaluated on a value the query never sees.The filter now calls
HivePartitioningUtils::convertPartitionValueToType, the readers' conversion (added by #131202; this PR is stacked on it, only the last commit is new). For the table functions it sees every value as the column reads it. A path value the reader rejects (k0=300forUInt8, or the textNULLforNullable(Int64)) now fails a filter on that column with the reader'sTYPE_MISMATCH, as reading it already does; before, such a path was skipped or not depending on how the filter parsed it. Tables with stored format settings (ENGINE = File(...) SETTINGS bool_true_representation = 'si') still convert in the filter with the query's format settings, unchanged here.Validation: the new test fails on the base and passes with the fix (100/100 randomized runs); the existing Hive tests pass, including the
s3ones. Filtering 20000 paths costs about 9 ms more in a debug build (0.203 -> 0.212 s median).🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/131256]
Version info
26.11.1.2446-master(included in26.11and later)