Skip to content

Honor cast_string_to_date_time_mode for hive partition values - #105584

Merged
alesapin merged 8 commits into
masterfrom
fix-hive-partitioning-datetime-tz
May 24, 2026
Merged

alesapin merged 8 commits into
masterfrom
fix-hive-partitioning-datetime-tz

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented May 21, 2026 •

Copy link
Copy Markdown
Member

Hive partition value extraction is conceptually a string-to-type cast, but 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.

This thread the existing format_settings and context through addPartitionColumnsToChunk and centralizes 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) now read without an exception.

Fixes #105368.

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):

Hive partition value extraction now honors the cast_string_to_date_time_mode setting 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

  • Documentation is written (mandatory for new features)

Note

Medium Risk
Touches hive partition value parsing and threads FormatSettings through 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 strict Basic parsing) so ISO-8601 timestamps with timezone suffixes like +0000, +00:00, and Z are accepted by default.

This centralizes hive-specific parsing in buildHiveFormatSettings, threads optional FormatSettings/Context through HivePartitioningUtils::addPartitionColumnsToChunk and 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

  • Merged into: 26.6.1.117
  • Backported to: 26.5.2.24, 26.4.4.26, 26.3.13.24

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]>
@clickhouse-gh

clickhouse-gh Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8decbe0]

Summary: ✅


AI Review

Summary

This 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 Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 21, 2026
Comment thread src/Storages/HivePartitioningUtils.cpp Resolved
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]>
Comment thread src/Storages/HivePartitioningUtils.cpp Outdated
/// 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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Ergus Ergus self-assigned this May 22, 2026
@Ergus

Ergus commented May 22, 2026 •

Copy link
Copy Markdown
Member

The failing test test_mysql_protocol/test.py::test_mysql_dotnet_client seems unrelated
Ans 01910_view_dictionary_check_refresh is flaky

@Ergus Ergus added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label May 22, 2026
alesapin and others added 2 commits May 22, 2026 17:35
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);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assumeMutableRef()

I hate this.

Comment thread src/Storages/HivePartitioningUtils.cpp Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread src/Storages/VirtualColumnUtils.cpp Resolved
…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.
@alesapin

Copy link
Copy Markdown
Member
image

@alexey-milovidov

Copy link
Copy Markdown
Member Author

We can't merge it with broken CI.

@clickhouse-gh

clickhouse-gh Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 93.94% (93/99) | lost baseline coverage: 6 line(s) · Uncovered code

Full report · Diff report

@alesapin
alesapin added this pull request to the merge queue May 24, 2026
Merged via the queue into master with commit fac6aa2 May 24, 2026
327 of 328 checks passed
@alesapin
alesapin deleted the fix-hive-partitioning-datetime-tz branch May 24, 2026 11:32
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label May 24, 2026
robot-clickhouse added a commit that referenced this pull request May 24, 2026
robot-ch-test-poll added a commit that referenced this pull request May 24, 2026
Cherry pick #105584 to 26.5: Honor cast_string_to_date_time_mode for hive partition values
robot-clickhouse added a commit that referenced this pull request May 24, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label May 24, 2026
@pamarcos pamarcos added v25.12-must-backport and removed pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels May 25, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label May 25, 2026
robot-ch-test-poll3 added a commit that referenced this pull request May 27, 2026
Cherry pick #105584 to 26.3: Honor cast_string_to_date_time_mode for hive partition values
robot-clickhouse added a commit that referenced this pull request May 27, 2026
DavidHe-2008 pushed a commit to DavidHe-2008/ClickHouse that referenced this pull request Jun 1, 2026
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]>
DavidHe-2008 pushed a commit to DavidHe-2008/ClickHouse that referenced this pull request Jun 1, 2026
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]>
DavidHe-2008 pushed a commit to DavidHe-2008/ClickHouse that referenced this pull request Jun 1, 2026
… 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.
DavidHe-2008 pushed a commit to DavidHe-2008/ClickHouse that referenced this pull request Jun 1, 2026
…oning-datetime-tz

Honor cast_string_to_date_time_mode for hive partition values
Ergus added a commit that referenced this pull request Jun 2, 2026
Backport #105584 to 26.4: Honor cast_string_to_date_time_mode for hive partition values
Ergus added a commit that referenced this pull request Jun 2, 2026
Backport #105584 to 26.5: Honor cast_string_to_date_time_mode for hive partition values
Ergus added a commit that referenced this pull request Jun 2, 2026
Backport #105584 to 26.3: Honor cast_string_to_date_time_mode for hive partition values
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 2, 2026
nickitat added a commit that referenced this pull request Jun 5, 2026
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]>
alexey-milovidov added a commit that referenced this pull request Jun 6, 2026
…3/105584

Revert "Backport #105584 to 26.3: Honor cast_string_to_date_time_mode for hive partition values"
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Jun 12, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…5584

Backport ClickHouse#105584 to 26.4: Honor cast_string_to_date_time_mode for hive partition values
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v25.12-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hive partitioning fails to parse ISO 8601 timestamps with timezone suffixes (e.g. +0000, Z)

6 participants