Repository navigation
Honor cast_string_to_date_time_mode for hive partition values - #105584
Conversation
Hive partition value extraction is conceptually a string-to-type cast, but the code in `HivePartitioningUtils` was building a fresh `FormatSettings` with only `allow_number_leading_zeros = true` and ignoring the user's settings. As a result, parsing of `DateTime` and `DateTime64` partition values defaulted to the strict `Basic` parser and rejected ISO 8601 timestamps with timezone suffixes such as `+0000`, `+00:00`, or `Z`. Setting either `cast_string_to_date_time_mode = 'best_effort'` or `date_time_input_format = 'best_effort'` had no effect. Thread `format_settings` and the context through `addPartitionColumnsToChunk`, and centralize the construction of hive-specific `FormatSettings` in a helper that overrides `date_time_input_format` with `cast_string_to_date_time_mode`. The setting defaults to `best_effort`, so by default Hive-partitioned data lakes with ISO 8601 timestamp keys (including Python `pandas` `isoformat` output and similar) now read without an exception. Fixes #105368. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Workflow [PR], commit [8decbe0] Summary: ✅ AI ReviewSummaryThis PR centralizes hive partition parsing settings and applies them consistently for schema-backed columns, virtual columns, and path-filter evaluation. After reviewing the current diff and all prior thread replies against current code, I did not find new unresolved correctness, safety, or performance issues. Final VerdictStatus: ✅ Approve |
The flaky check runs each query with a random `session_timezone` (e.g. `Mexico/BajaSur`). For the inferred-type case the column type is `DateTime` with no explicit timezone, so the displayed value depends on the session timezone and the reference would not match when the session timezone is shifted. Pin `session_timezone = 'UTC'` so the output is deterministic across configurations. See #105584 CI flaky-check failures on commit be09afa. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
| /// allow leading zeros in numeric values. | ||
| static FormatSettings buildHiveFormatSettings(const std::optional<FormatSettings> & format_settings, const ContextPtr & context) | ||
| { | ||
| FormatSettings hive_format_settings = format_settings ? *format_settings : getFormatSettings(context); |
There was a problem hiding this comment.
Better if we can use the "or_else" function instead of manual check.
The operator* is not recommended in optionals because it is "unsafe"
Also the boolean operator overload is less explicit that the "has_value" function in case you want to keep the ? operator.
There was a problem hiding this comment.
The current code uses format_settings.value_or(getFormatSettings(context)) (from the suggestion in commit 1b969c5), which avoids both operator* on a possibly-empty optional and the implicit bool conversion you flagged.
| SELECT id, ts | ||
| FROM file('$DATA_DIR/ts=*/data.csv', 'CSV', 'id UInt64, ts DateTime64(0, ''UTC'')') | ||
| ORDER BY id | ||
| SETTINGS use_hive_partitioning = 1, cast_string_to_date_time_mode = 'best_effort', session_timezone = 'UTC'; |
There was a problem hiding this comment.
I see this, but not any tests with:
SETTINGS use_hive_partitioning = 1, date_time_input_format = 'best_effort'
as referenced in the PR description
There was a problem hiding this comment.
Added a new test case in 04259_hive_partitioning_datetime_timezones.sh that explicitly sets date_time_input_format = best_effort, matching the wording in the PR description. Note that hive partition value parsing is conceptually a cast, so buildHiveFormatSettings overrides date_time_input_format with cast_string_to_date_time_mode; since the latter defaults to best_effort the test demonstrates that the default behavior is correct in both formulations.
|
The failing test |
Address review comment #105584 (comment). The previous commit made `HivePartitioningUtils` honour `cast_string_to_date_time_mode` for schema-backed hive partition columns, but the same invariant was still broken for hive keys materialized as virtual columns. In `prepareReadingFromFormat`, missing schema columns are classified as `requested_virtual_columns`, and then `VirtualColumnUtils::addRequestedFileLikeStorageVirtualsToChunk` parsed them with a fresh `FormatSettings` that only set `allow_number_leading_zeros`. The path filter evaluation in `addPathAndFileToVirtualColumns` had the same problem. Expose `HivePartitioningUtils::buildHiveFormatSettings` as a public helper and route both `addRequestedFileLikeStorageVirtualsToChunk` and `getFilterByPathAndFileIndexes` through it, threading the storage's `format_settings` from all call sites so all hive partition value conversions honour `cast_string_to_date_time_mode` consistently. Extend `04259_hive_partitioning_datetime_timezones.sh` with two new cases covering the virtual-column path (schema declares only `id`) and a `WHERE` filter on the virtual column. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
| auto hive_format_settings = format_settings; | ||
| hive_format_settings.allow_number_leading_zeros = true; | ||
| column->type->getDefaultSerialization()->deserializeWholeText(column->column->assumeMutableRef(), buf, hive_format_settings); | ||
| column->type->getDefaultSerialization()->deserializeWholeText(column->column->assumeMutableRef(), buf, format_settings); |
There was a problem hiding this comment.
assumeMutableRef()
I hate this.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1b969c5. Configure here.
…rtualsToChunk` loop `buildHiveFormatSettings` was constructed once per matched hive virtual column, but the result is identical for every iteration and the `getFormatSettings(context)` fallback reads many settings. This matches the hoisting pattern already used by `addPartitionColumnsToChunk` in `HivePartitioningUtils.cpp` and `getFilterByPathAndFileIndexes` in `VirtualColumnUtils.cpp`, and addresses the Cursor Bugbot review on commit 1b969c5.
… test The PR description notes that prior to this fix, neither `cast_string_to_date_time_mode` nor `date_time_input_format` had any effect on hive partition value parsing. Test coverage existed for `cast_string_to_date_time_mode` but not for the `date_time_input_format` variant referenced in the description. Hive partition value extraction is conceptually a cast, so `cast_string_to_date_time_mode` is the authoritative setting and overrides `date_time_input_format` inside `buildHiveFormatSettings`. The new query exercises the setting referenced in the PR description; since `cast_string_to_date_time_mode` defaults to `best_effort`, the timezone-suffixed paths parse successfully. Addresses review feedback from @Ergus on PR #105584.
|
We can't merge it with broken CI. |
LLVM Coverage Report
Changed lines: 93.94% (93/99) | lost baseline coverage: 6 line(s) · Uncovered code |
Cherry pick #105584 to 26.5: Honor cast_string_to_date_time_mode for hive partition values
Cherry pick #105584 to 26.3: Honor cast_string_to_date_time_mode for hive partition values
The flaky check runs each query with a random `session_timezone` (e.g. `Mexico/BajaSur`). For the inferred-type case the column type is `DateTime` with no explicit timezone, so the displayed value depends on the session timezone and the reference would not match when the session timezone is shifted. Pin `session_timezone = 'UTC'` so the output is deterministic across configurations. See ClickHouse#105584 CI flaky-check failures on commit be09afa. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Address review comment ClickHouse#105584 (comment). The previous commit made `HivePartitioningUtils` honour `cast_string_to_date_time_mode` for schema-backed hive partition columns, but the same invariant was still broken for hive keys materialized as virtual columns. In `prepareReadingFromFormat`, missing schema columns are classified as `requested_virtual_columns`, and then `VirtualColumnUtils::addRequestedFileLikeStorageVirtualsToChunk` parsed them with a fresh `FormatSettings` that only set `allow_number_leading_zeros`. The path filter evaluation in `addPathAndFileToVirtualColumns` had the same problem. Expose `HivePartitioningUtils::buildHiveFormatSettings` as a public helper and route both `addRequestedFileLikeStorageVirtualsToChunk` and `getFilterByPathAndFileIndexes` through it, threading the storage's `format_settings` from all call sites so all hive partition value conversions honour `cast_string_to_date_time_mode` consistently. Extend `04259_hive_partitioning_datetime_timezones.sh` with two new cases covering the virtual-column path (schema declares only `id`) and a `WHERE` filter on the virtual column. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… test The PR description notes that prior to this fix, neither `cast_string_to_date_time_mode` nor `date_time_input_format` had any effect on hive partition value parsing. Test coverage existed for `cast_string_to_date_time_mode` but not for the `date_time_input_format` variant referenced in the description. Hive partition value extraction is conceptually a cast, so `cast_string_to_date_time_mode` is the authoritative setting and overrides `date_time_input_format` inside `buildHiveFormatSettings`. The new query exercises the setting referenced in the PR description; since `cast_string_to_date_time_mode` defaults to `best_effort`, the timezone-suffixed paths parse successfully. Addresses review feedback from @Ergus on PR ClickHouse#105584.
…oning-datetime-tz Honor cast_string_to_date_time_mode for hive partition values
Backport #105584 to 26.4: Honor cast_string_to_date_time_mode for hive partition values
Backport #105584 to 26.5: Honor cast_string_to_date_time_mode for hive partition values
Backport #105584 to 26.3: Honor cast_string_to_date_time_mode for hive partition values
After removing the `storage_id` initializer, the `26.3` build hit a second error from the same #105584 backport: src/Storages/HivePartitioningUtils.cpp:70:26: error: no member named 'allow_number_leading_zeros' in 'DB::FormatSettings' `buildHiveFormatSettings` sets `allow_number_leading_zeros`, but that `FormatSettings` field was introduced by a separate prerequisite, "Fix for hive partitioning with leading zeros" (master commit `1d9caa0d168`), which — like #101409 — was never backported to `26.3`. Drop the assignment. `26.3` keeps its existing leading-zeros parsing behavior (consistent with that prerequisite not being backported), while the actual point of #105584 — honoring `cast_string_to_date_time_mode` for hive partition values — is preserved. A full scan of the #105584 backport diff confirms these were the only two symbols absent on `26.3`; all other referenced symbols (`convertFieldToType` with `FormatSettings`, `cast_string_to_date_time_mode`, `buildHiveFormatSettings`) exist on the branch. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106612&sha=5d9df59d9052889a5665790edc4851f56f2fd9e4&name_0=BackportPR Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…3/105584 Revert "Backport #105584 to 26.3: Honor cast_string_to_date_time_mode for hive partition values"
…_time_mode for hive partition values"
…de for hive partition values
…5584 Backport ClickHouse#105584 to 26.4: Honor cast_string_to_date_time_mode for hive partition values
The `26.3` build was broken with:
src/Storages/StorageFile.cpp:1658:22: error: field designator
'storage_id' does not refer to any field in type
'VirtualsForFileLikeStorage'
This was introduced by the backport of ClickHouse#105584 ("Honor
`cast_string_to_date_time_mode` for hive partition values"), which
cherry-picked a `.storage_id = storage->getStorageID()` initializer for
`VirtualsForFileLikeStorage`. On `master` that field exists because it
was added by ClickHouse#101409 ("Native Common Virtuals for File-Like"), but
ClickHouse#101409 was never backported to `26.3`, so the struct here has no
`storage_id` member and the designated initializer fails to compile.
`addRequestedFileLikeStorageVirtualsToChunk` on `26.3` never reads
`storage_id`, so removing the initializer is behavior-preserving and
restores the build for the whole release branch.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106498&sha=b7c045c7bd5bb605b946fe1d77092a02ccef89bb&name_0=BackportPR
Surfaced on PR: ClickHouse#106498
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
After removing the `storage_id` initializer, the `26.3` build hit a second error from the same ClickHouse#105584 backport: src/Storages/HivePartitioningUtils.cpp:70:26: error: no member named 'allow_number_leading_zeros' in 'DB::FormatSettings' `buildHiveFormatSettings` sets `allow_number_leading_zeros`, but that `FormatSettings` field was introduced by a separate prerequisite, "Fix for hive partitioning with leading zeros" (master commit `1d9caa0d168`), which — like ClickHouse#101409 — was never backported to `26.3`. Drop the assignment. `26.3` keeps its existing leading-zeros parsing behavior (consistent with that prerequisite not being backported), while the actual point of ClickHouse#105584 — honoring `cast_string_to_date_time_mode` for hive partition values — is preserved. A full scan of the ClickHouse#105584 backport diff confirms these were the only two symbols absent on `26.3`; all other referenced symbols (`convertFieldToType` with `FormatSettings`, `cast_string_to_date_time_mode`, `buildHiveFormatSettings`) exist on the branch. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106612&sha=5d9df59d9052889a5665790edc4851f56f2fd9e4&name_0=BackportPR Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>


Hive partition value extraction is conceptually a string-to-type cast, but
HivePartitioningUtilswas building a freshFormatSettingswith onlyallow_number_leading_zeros = trueand ignoring the user's settings. As a result, parsing ofDateTimeandDateTime64partition values defaulted to the strictBasicparser and rejected ISO 8601 timestamps with timezone suffixes such as+0000,+00:00, orZ. Setting eithercast_string_to_date_time_mode = 'best_effort'ordate_time_input_format = 'best_effort'had no effect.This thread the existing
format_settingsand context throughaddPartitionColumnsToChunkand centralizes the construction of hive-specificFormatSettingsin a helper that overridesdate_time_input_formatwithcast_string_to_date_time_mode. The setting defaults tobest_effort, so by default Hive-partitioned data lakes with ISO 8601 timestamp keys (including Pythonpandasisoformatoutput) now read without an exception.Fixes #105368.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Hive partition value extraction now honors the
cast_string_to_date_time_modesetting and accepts ISO 8601 timestamps with timezone suffixes (e.g.+0000,+00:00,Z) in partition keys by default.Documentation entry for user-facing changes
Note
Medium Risk
Touches hive partition value parsing and threads
FormatSettingsthrough multiple file-like storage read paths, which could subtly change partition/virtual column casting behavior for existing setups.Overview
Fixes hive partition value parsing to honor
cast_string_to_date_time_mode(instead of always using strictBasicparsing) so ISO-8601 timestamps with timezone suffixes like+0000,+00:00, andZare accepted by default.This centralizes hive-specific parsing in
buildHiveFormatSettings, threads optionalFormatSettings/ContextthroughHivePartitioningUtils::addPartitionColumnsToChunkand virtual-column filtering/materialization paths, and adds a regression test covering inferred/schema-declared partition columns, virtual columns, and path-filter evaluation.Reviewed by Cursor Bugbot for commit 5fddd2d. Bugbot is set up for automated code reviews on this repo. Configure here.
Version info
26.6.1.11726.5.2.24,26.4.4.26,26.3.13.24