Skip to content

Give a clear error when a Hive partition value does not fit the type of its partition column - #131202

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:hive-partition-value-out-of-range-131087
Nov 13, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:hive-partition-value-out-of-range-131087

Conversation

@groeneai

@groeneai groeneai commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #131087

Changelog category (leave one):

  • Improvement

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

A Hive partition value that does not fit the type of its partition column (for example k0=300 for k0 UInt8) now gives a TYPE_MISMATCH error that names the value, the path and the column, instead of BAD_GET (or a LOGICAL_ERROR for LowCardinality). Closes #131087.

Description

With use_hive_partitioning = 1, a path value that the declared type of its partition column cannot hold (k0=300 or k0=-1 for UInt8, k0=[256] for Array(UInt8)) failed with Bad get: has Null, requested UInt64 (BAD_GET), and for LowCardinality(UInt8) with the LOGICAL_ERROR ColumnUnique can't contain null values (an abort in a debug build).

convertFieldToType returns Null for a value outside the range of the type, and both places that materialize a Hive partition value passed it straight to createColumnConst: HivePartitioningUtils::addPartitionColumnsToChunk (the file, url, object storage and S3Queue/AzureQueue readers) and the Hive branch of VirtualColumnUtils::addRequestedFileLikeStorageVirtualsToChunk (a partition column that is not in the structure).

Both now call HivePartitioningUtils::convertPartitionValueToType, which throws TYPE_MISMATCH (Cannot convert '300' from the path <path> to type UInt8 for the Hive partition column k0) when the result is Null and the type cannot contain NULL, the same error class an unparsable value (k0=abc) already gets. Nullable and LowCardinality(Nullable) still read such a value as NULL; Variant and Dynamic are unchanged. Only queries that already failed change. The path pre-filter for WHERE on a partition column is unchanged: it parses the value with text deserialization, not convertFieldToType, so this error does not apply there (for such a value it can disagree with the reader, a separate problem not changed here).

Validation: the new test 05628_hive_partitioning_value_out_of_range covers the boundary value, both range ends, Array, LowCardinality, the NULL cases, the virtual column and the s3 reader. Every error line fails on master (BAD_GET, or the abort) and passes with the fix; 50/50 randomized runs pass.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.2211-master (included in 26.11 and later)

…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]>
@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; 2 rounds, 2 findings in round 1, none in round 2) plus my own review.

# Sev Finding Verdict Evidence / action
1 ⚠️ The description said Variant and Dynamic read an out-of-range value as NULL AGREE, fixed (text only) They read it as the value (k0=256 gives 256, same as master): convertFieldToType stores the String in Dynamic or a fitting Variant alternative, so no Null arises. The code already leaves them alone (canContainNull); the description and the commit message now say they are unchanged.
2 ⚠️ The test asserts only TYPE_MISMATCH, not the message text DISAGREE The change is the error class (BAD_GET / LOGICAL_ERROR to TYPE_MISMATCH); removing the check, dropping the canContainNull condition or reverting the virtual-column call each fails the test. The message was checked by hand on every error case. The existing Hive tests assert codes only (05353_hive_partitioning_path_without_partition_key.sql:10-11).
3 💡 "The pre-filter never produces Null" was imprecise (text deserialization reads \N as NULL for Nullable) AGREE, fixed (text only) Reworded: it does not use convertFieldToType, so this error does not apply there.

Round 2 (same code, corrected text): no findings.

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

Session id: cron:clickhouse-review-slot-11:20261113-064800

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SELECT c0, k0 FROM file('.../k0=256/data.jsonl', JSONEachRow, 'c0 Int32, k0 UInt8') SETTINGS use_hive_partitioning = 1 gives BAD_GET on every run on master; LowCardinality(UInt8) aborts a debug build every run.
b Root cause explained? convertFieldToType returns Null for a value outside the type's range; addPartitionColumnsToChunk and the Hive branch of addRequestedFileLikeStorageVirtualsToChunk passed it unchecked to createColumnConst, whose column cannot store Null (Field::safeGet -> BAD_GET; ColumnUnique::uniqueInsert -> LOGICAL_ERROR).
c Fix matches root cause? Yes. Both sites now convert through one helper that throws TYPE_MISMATCH when the result is Null and the type cannot contain NULL. convertFieldToType and createColumnConst are unchanged.
d Test intent preserved / new tests added? New test 05628_hive_partitioning_value_out_of_range: boundary 255, above and below range, Array, LowCardinality, the Nullable and LowCardinality(Nullable) NULL cases, the virtual column and the s3 reader. Removing the check, dropping the canContainNull condition, or reverting the virtual-column call each makes it fail.
e Both directions demonstrated? Yes. Per statement on master: BAD_GET x6 and a signal 6 for LowCardinality(UInt8); with the fix: TYPE_MISMATCH for each, unchanged output for the rest. The test fails without the check and passes with it; 50/50 randomized runs pass.
f Fix is general across code paths? Yes. Both places that materialize a Hive value from a path are fixed; the four reader call sites (file, url, object storage, S3Queue/AzureQueue) share the first. The WHERE path pre-filter parses with text deserialization, not convertFieldToType, so it does not hit this error; it is unchanged.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Measured: UInt8, Int8, UInt256, Array, nested Array, Array(Nullable), Tuple, LowCardinality now give TYPE_MISMATCH; Nullable, LowCardinality(Nullable), Variant, Dynamic keep NULL or the value; Bool, Date, Float32, Decimal, Enum, IPv4 behave exactly as before.
h Backward compatible? (maintainer-approved exception only) Yes. Only queries that already failed change their error; no setting, no format change.
i Invariants and contracts preserved? Yes. The helper returns convertFieldToType's result unchanged unless it is Null for a type that cannot hold it, and throws before any column is added to the chunk.

Session id: cron:clickhouse-impl-slot-7:20261113-052600

@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e47914a]

Summary: ✅


AI Review

Summary

PR #131202, reviewed at e47914a45dbfac425185ebf845547690eb747dfc, replaces internal BAD_GET / LOGICAL_ERROR exceptions with a contextual TYPE_MISMATCH when a Hive partition value cannot fit its column type. Both declared-column and virtual-column materialization use the same guard, preserving nullable conversions. No actionable findings.

Missing context / blind spots
  • ⚠️ No local ClickHouse binary or build was available, so I did not rerun the regression test. The available CI report has no per-test stateless results yet, and Fast test excludes the new S3-dependent test. The author records baseline failures, successful patched runs, and 50 successful randomized repetitions; a completed CI result for 05628_hive_partitioning_value_out_of_range would independently confirm those results.
Final Verdict

Status: ✅ Approve. No review changes required.

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements can be tested Allows running workflows for external contributors comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). labels Nov 13, 2026
@PedroTadim PedroTadim self-assigned this Nov 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e47914a45 with master 21809eaaa (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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.62, programs/clickhouse-keeper ×0.67 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.7 s 12.3 s +8.8 s (+254%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.3 s 7.3 s +5.2 s (+256%)
Compile time of recompiled translation units

20 translation units recompiled, 175 s compile time in total, 20 of them have a recent master baseline.

Job report

@PedroTadim
PedroTadim added this pull request to the merge queue Nov 13, 2026
Merged via the queue into ClickHouse:master with commit 3a97622 Nov 13, 2026
606 of 608 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 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-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). pr-improvement Pull request with some product improvements 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.

BAD_GET when a Hive partition value is out of range for the declared integer type of the partition column

3 participants