Repository navigation
Conversation
|
Workflow [PR], commit [9f00d92] Summary: ❌
AI ReviewSummaryThis PR restores monotonic-function Iceberg partition pruning and re-enables Findings❌ Blockers
Tests
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit 9f00d92.
Changed lines: Changed C/C++ lines covered: 161/202 (79.70%) · Uncovered code |
| if (!own_unit) | ||
| return {}; | ||
|
|
||
| const auto & utc = DateLUT::instance("UTC"); |
There was a problem hiding this comment.
day / month / year are not always UTC transforms in this codebase. When ClickHouse writes an Iceberg table, ChunkPartitioner executes toRelativeDayNum, toMonthNumSinceEpoch, or toYearNumSinceEpoch on the source column type, and those functions use that DateTime / DateTime64 type's DateLUT. Hard-coding UTC here shifts the reconstructed preimage for non-UTC columns and can make mayBeTrueInRange prune a matching file.
Concrete trace: for a DateTime('Europe/Berlin') column partitioned by toRelativeDayNum(ts), the row 1969-12-31 23:30:00 UTC belongs to partition 0 (1970-01-01 locally). The true preimage of partition 0 is [1969-12-31 23:00:00, 1970-01-01 23:00:00) UTC, but this code reconstructs [1970-01-01 00:00:00, 1970-01-02 00:00:00), so a predicate like ts < toDateTime('1970-01-01 00:00:00', 'UTC') would incorrectly prune the file. Please derive the calendar from source_type instead of hard-coding UTC, and add a non-UTC regression test.
Build profile diff (arm_release)Comparing commit See the job log for details. |
…it is An Iceberg partition field summary keeps its bounds in the single-value serialization of the partition field's own type, and for the `day`, `month`, `year` and `hour` transforms that type is a signed `int` counting units from 1970. ClickHouse models those transforms in the partition key with `toRelativeDayNum`, `toMonthNumSinceEpoch`, `toYearNumSinceEpoch` and `toRelativeHourNum`, whose result types are unsigned, so `ManifestListPruner::canBePruned` read a bound from before 1970 as a huge unsigned number. For a manifest that spans 1969 and 2024 the lower bound then came out above the upper bound, and `KeyCondition::checkInRange` hit `chassert(key_order.compareTuples(left_keys, right_keys, used_key_size) <= 0)`, which aborts a build with assertions. That is why `test_storage_iceberg_with_spark/test_partition_pruning_with_functions.py::test_partition_pruning_with_functions_before_epoch` started failing on master in `Integration tests (amd_tsan, 3/6)` and `Integration tests (amd_msan, 8/8)`: the `toDate32` monotonicity that #118606 gave a `Nullable` column made the filter of that test reach the pruner. A bound of an unsigned key column is now read as the signed number Iceberg wrote, and a negative one leaves the whole field unknown: the ClickHouse functions that stand for those transforms cannot return a negative number - they map every point before 1970 to zero - so nothing about the key's value space follows from such a bound and no range of it may be pruned on. A pair of bounds that comes out inverted now drops the field with a warning instead of being pruned on, the same as `ManifestFileIterator` already does for the min/max bounds of a data file. Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=290309210c5b2f0e01c13fd0fbae6577fb5cb9cd&name_0=MasterCI&name_1=Integration%20tests%20%28amd_tsan%2C%203%2F6%29 Related: #118606 Related: #116499 Related: #116604 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The `day`, `month` and `year` transforms of the Iceberg specification count from 1970-01-01 with no timezone applied, so inverting one of their values back into a range of the source column must use the `UTC` calendar and must ignore the timezone declared on the `DateTime64` that an Iceberg `timestamp` is read into. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Includes the revert of the pre-epoch partition pruning regression that failed the integration shard. The PR patch is unchanged. ClickHouse#110957 Related: ClickHouse#119298 Related: ClickHouse#119302 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=110957&sha=b7f8a58559a910e414fe5a2e9de7852ab6f46a3c&name_0=PR&name_1=Integration%20tests%20(amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%203%2F6)
…n shape `EXPLAIN indexes = 1` prints two lines that contain `Granules:`: the `Parts: 1 | Granules: 2` summary of the `ReadFromMergeTree` step and the `Granules: 2/10` of the primary key index analysis. The test grepped for both and stripped the indentation with `trimLeft`, which made it depend on the shape of the plan around them: - with `make_distributed_plan = 1` the step summary is not printed at all, so the test lost three lines; - with parallel replicas the whole subtree is printed under a `│` prefix, which `trimLeft` does not strip, so all six lines came out prefixed. The granule count is now read with `extract(explain, 'Granules: \d+/\d+')`, which picks the index analysis line out of any indentation or prefix and does not match the step summary at all. That is also the line the test is about: it says the index analysis narrowed ten granules down to two. Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119302&sha=323a1976ae947f4c28bca9cea92d08d6913e4f86&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 Related: #118606 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Triage of the four checks that were red on 1. 2. SET session_timezone = 'UTC';
CREATE TABLE t (x DateTime64(3)) ENGINE = MergeTree ORDER BY x SETTINGS index_granularity = 1;
INSERT INTO t VALUES (toDateTime64('2100-01-01 00:00:00', 3)), (toDateTime64('2250-01-01 00:00:00', 3));
SELECT count() FROM t WHERE toDateTime(x) = toDateTime('2100-01-01 00:00:00'); -- 0
SELECT countIf(toDateTime(x) = toDateTime('2100-01-01 00:00:00')) FROM t; -- 1With 3. 4. |
| std::optional<Range> rangeOfPartitionValue(const String & transform_name, const Field & partition_value, const IDataType & source_type) | ||
| { | ||
| const auto value = partitionValueAsInt64(partition_value); | ||
| if (!value) | ||
| return {}; | ||
|
|
||
| const PartitionTransformKind kind = parsePartitionTransformKind(transform_name); | ||
| const WhichDataType which(source_type); | ||
|
|
||
| if (which.isDateOrDate32()) | ||
| return closedRange(dayIntervalOfPartitionValue(kind, *value), std::nullopt); | ||
|
|
||
| if (which.isDateTime()) | ||
| return closedRange(secondIntervalOfPartitionValue(kind, *value), std::nullopt); | ||
|
|
||
| if (which.isDateTime64()) | ||
| { | ||
| const UInt32 scale = getDecimalScale(source_type); | ||
| return closedRange( | ||
| refineInterval(secondIntervalOfPartitionValue(kind, *value), DecimalUtils::scaleMultiplier<Int64>(scale)), scale); |
There was a problem hiding this comment.
This inversion assumes a day / month / year / hour partition value has a single source-column preimage, but that is not true for tables ClickHouse writes itself. ChunkPartitioner uses the standard toRelativeDayNum / toMonthNumSinceEpoch / toYearNumSinceEpoch / toRelativeHourNum functions, and for Date32 / DateTime64 those clamp every pre-1970 value to 0 (src/Functions/DateTimeTransforms.h:2638, 2649, 2715, 2737, 2751).
Concrete trace: write an Iceberg table partitioned by days(ts) with ts DateTime64, insert 1969-12-31 23:00:00 and 1970-01-01 00:30:00. Both rows land in partition 0, but rangeOfPartitionValue("day", 0, ...) reconstructs only [1970-01-01, 1970-01-02). A filter like toDate32(ts) < toDate32('1970-01-01') then makes mayBeTrueInRange return false and this path prunes the file even though it contains a matching row.
Please either stop inverting the clamped value 0 here, or fix the write/read transform contract together and add a ClickHouse-written pre-1970 regression test.
| static IFunction::Monotonicity get(const IDataType & type_with_wrappers, const Field & left, const Field & right) | ||
| { | ||
| const IDataType * type_without_wrappers = &type_with_wrappers; | ||
| if (const auto * low_cardinality_type = typeid_cast<const DataTypeLowCardinality *>(type_without_wrappers)) | ||
| type_without_wrappers = low_cardinality_type->getDictionaryType().get(); | ||
| if (const auto * nullable_type = typeid_cast<const DataTypeNullable *>(type_without_wrappers)) | ||
| type_without_wrappers = nullable_type->getNestedType().get(); | ||
| const IDataType & type = *type_without_wrappers; |
There was a problem hiding this comment.
Unwrapping Nullable / LowCardinality here re-enables is_always_monotonic on wrapped Date32 / DateTime64 sources, but the transform is still not monotonic on the whole domain under the default date_time_overflow_behavior = 'ignore'. The comment right above getPreimage already calls this out for toDate, and the same underlying bug is what #116946 reproduces for plain DateTime64 keys.
Before this patch, a Nullable(Date32) or LowCardinality(Nullable(DateTime64)) key stayed non-monotonic and queries were still correct. After the unwrap, those wrapped keys take the same wrong optimization as the plain type and can now return wrong results. A MergeTree key on Nullable(DateTime64(3)) with values such as 2100-01-01 and 2250-01-01 is enough: WHERE toDateTime(x) = toDateTime('2100-01-01 00:00:00') can prune away the matching row once the key analyzer starts trusting this monotonicity.
Please do not spread this optimization to wrapped Date32 / DateTime64 until the overflow-aware monotonicity/preimage logic is fixed; the same issue applies to the ToDateTimeMonotonicity hunk below.
Backport #119302 to 26.9: Revert "Revert "Proper partition pruning with dates""
…pruning with dates""
Resolve the cherry-pick of #119302 against 26.3. The original #118606 was never backported to 26.3 (its backport #119251 was closed after the revert), so this is effectively the full backport of the Iceberg partition pruning: - `ManifestListPruning.cpp` does not exist on 26.3 (there is no manifest list pruning there), so its part of the reland, which fixed the pre-1970 bound bug in `ManifestListPruner`, is dropped. - `IcebergFieldParseHelpers` stays as on 26.3: the new `deserializeDecimalFromBinaryRepr` is only used by the decimal partition decoding and `ManifestListPruner`, neither of which exists on 26.3. - `FunctionsConversion.h`, `ManifestFile.h` (`tuple_index`), `ManifestFileIterator.cpp` and `ManifestFilesPruning.cpp` take the 26.3 adaptation from the earlier backport #119251, with the helpers in `ManifestFilesPruning.cpp` updated to the form of the reland. - The tests come from the reland; `05054` there extracts only the `Granules: N/M` part of `EXPLAIN`, which is what failed on #119251. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Cherry pick #119302 to 26.3: Revert "Revert "Proper partition pruning with dates""
Resolve the conflicts of the cherry-pick of #119302 to 26.7. 26.7 had the original backport of #118606 merged and then reverted (#119253, #119431), so the resolution reapplies that 26.7 backport (reverts `d10ac36aeab8`) and then applies the follow-up commits of #119302 on top of it. 26.7 has no `ManifestListPruning.cpp` (manifest-list level pruning is not on this branch), so the hunks of #119302 for that file are dropped, and with them the `deserializeDecimalFromBinaryRepr` refactoring of `213367fdc76a`, which only existed to share the decimal decoding with that file; 26.7 keeps its own `decodePartitionDecimalByType`. The `ManifestFilesPruning.cpp` interval helpers, the `05054` test and the `test_partition_pruning_with_functions.py` integration test match master. Related: #119302 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Cherry pick #119302 to 26.7: Revert "Revert "Proper partition pruning with dates""
Resolve the cherry-pick of #119302 onto 26.8. The resolution starts from the earlier 26.8 backport of #118606 (ff6b795), which already adapted `FunctionsConversion.h` and `ManifestFilesPruning.cpp` to 26.8, and then applies the follow-up commits of the reland that touch those files (323a197, bad2875, 9bb3a34) plus the updated tests. Dropped, because 26.8 does not have the code they modify: - `ManifestListPruning.cpp` (manifest-list pruning is not on 26.8), which carried the pre-1970 summary-bound fix of 039006e; - the `deserializeDecimalFromBinaryRepr` helper of 213367f in `IcebergFieldParseHelpers`: that commit only deduplicated the decimal decoding, 26.8 keeps the equivalent local `decodePartitionDecimal` in `ManifestFilesPruning.cpp`; - the `getPreimage` of `ToDateMonotonicity`, which is master-only. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Cherry pick #119302 to 26.8: Revert "Revert "Proper partition pruning with dates""
Backport #119302 to 26.3: Revert "Revert "Proper partition pruning with dates""
Backport #119302 to 26.8: Revert "Revert "Proper partition pruning with dates""
Backport #119302 to 26.7: Revert "Revert "Proper partition pruning with dates""
Reverts #119298, so the Iceberg partition pruning of #118606 comes back, together with the fix for the failure that #119298 was reverting it for.
#118606taughttoDateandtoDateTimemonotonicity to look through aNullablecolumn, which is what every Iceberg column is, and that made a filter such asWHERE toDate32(ts) = toDate32('1969-11-15')reach the Iceberg pruners for the first time.ManifestListPruner::canBePrunedthen read a pre-1970 partition field summary bound of adayoryeartransform - a negativeint- through the unsigned result type of thetoRelativeDayNumandtoYearNumSinceEpochthat model those transforms, so the bound came out as a huge unsigned number. For a manifest that spans 1969 and 2024 the lower bound landed above the upper one andKeyCondition::checkInRangehitchassert(key_order.compareTuples(left_keys, right_keys, used_key_size) <= 0), which is the exceptiontest_partition_pruning_with_functions_before_epochwas failing with.Such a bound is now read as the signed number Iceberg wrote, and a negative one leaves the whole partition field unknown instead of being pruned on: the ClickHouse functions that stand for those transforms cannot return a negative number - they map every point before 1970 to zero - so nothing about the key's value space follows from it. A pair of bounds that still comes out inverted drops the field with a warning, the same as
ManifestFileIteratoralready does for the min/max bounds of a data file.A new
test_partition_pruning_with_functions_before_epoch_separate_commitscovers the manifest-list level directly, with one manifest whose partition summaries are negative on both sides and one whose summaries are positive on both.The other failure of the previous run,
05141_time_series_select_join_settings, was a breakage ofmasteritself between 2026-09-10 16:00 and 21:00 UTC, unrelated to this pull request and fixed by #119334;masteris merged in to pick that up.Related: #118606
Related: #119298
Related: #119292
Related: #103433
Related: #116499
Report of the failure this fixes: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119302&sha=a134a445a3ca3065c01ac1b32aaa52db19a88033&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Iceberg partition pruning now uses the partition value of a
day,month,yearorhourtransform for a filter that wraps the partition source column in a monotonic function, such asWHERE toDate(ts) = '2024-01-20', including for partition values from before 1970.Workflow [PR]
Sync PR [sync-upstream/pr/119302]
🤖 Generated with Claude Code
Version info
26.10.1.6-master(included in26.10and later)26.9.1.1628,26.8.12.52,26.7.15.52,26.3.34.136