Skip to content

Make hive partition strategy a default under compatibility setting - #86746

Merged
alexey-milovidov merged 23 commits into
masterfrom
hive-partitioning-small-changes
May 30, 2026
Merged

alexey-milovidov merged 23 commits into
masterfrom
hive-partitioning-small-changes

Conversation

@kssenii

@kssenii kssenii commented Sep 5, 2025 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Make hive partition strategy a default under compatibility setting file_like_engine_default_partition_strategy.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Note

Medium Risk
Changes default partitioned-write behavior for file-like engines based on compatibility/new setting, which can alter generated object paths or flip errors for existing PARTITION BY definitions without explicit partition_strategy. The change is scoped but affects widely used S3/AzureBlobStorage engines and is therefore moderately risky.

Overview
Makes Hive-style partitioning the default for file-like engines (e.g. S3, AzureBlobStorage) when PARTITION BY is used and no partition_strategy is provided, controlled by a new setting file_like_engine_default_partition_strategy and flipped to hive by default starting with compatibility >= 26.5.

Updates object-storage configuration parsing to track whether partition_columns_in_data_file was explicitly set and recompute its default after the effective strategy is chosen, and adds coverage to ensure compatibility and explicit setting overrides produce the expected create-table success/error behavior. Documentation is updated to describe the new defaulting rules and (in some places) normalize strategy names to wildcard/hive.

Reviewed by Cursor Bugbot for commit 16f89eb. Bugbot is set up for automated code reviews on this repo. Configure here.

Version info

  • Merged into: 26.6.1.270

@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [eeee746]

Summary: ✅


AI Review

Summary

This PR makes hive the implicit partition_strategy for file-like object-storage engines when PARTITION BY is present and no explicit strategy is provided, controlled by file_like_engine_default_partition_strategy and compatibility history (effective boundary at 26.6). It also fixes strategy/validation edge cases and aligns integration tests plus docs with the compatibility-driven behavior. After reviewing the current diff and all prior discussion threads, I did not find any remaining correctness, compatibility, or safety issues.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Sep 5, 2025
@jkartseva jkartseva self-assigned this Sep 8, 2025

@jkartseva jkartseva left a comment

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.

03363_hive_style_partition needs to be aligned with the new default, otherwise looks good.

@clickhouse-gh

clickhouse-gh Bot commented Oct 14, 2025

Copy link
Copy Markdown
Contributor

Dear @jkartseva, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@alexey-milovidov

Copy link
Copy Markdown
Member

@kssenii, could you also please check these data lake tests?

@clickhouse-gh

clickhouse-gh Bot commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

Dear @jkartseva, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

…mall-changes

# Conflicts:
#	docs/en/sql-reference/table-functions/s3.md
#	src/Core/Settings.h
#	src/Core/SettingsEnums.cpp
#	src/Core/SettingsEnums.h
@alexey-milovidov

Copy link
Copy Markdown
Member

This was fixed by #105146. Let's update the branch.

alexey-milovidov and others added 5 commits May 17, 2026 21:02
The new `file_like_engine_default_partition_strategy` default of `hive`
was being applied even to data lake engines (`Iceberg`, `DeltaLake`,
etc.), which manage partitioning themselves and rejected an explicit
`partition_strategy` argument. Applying the default `hive` strategy
caused `CREATE TABLE` for `IcebergLocal` with a `PARTITION BY` clause to
fail validation, breaking inserts referenced by tests such as
`04201_iceberg_manifest_per_file_stats` and
`04061_iceberg_update_partition_key_empty_block`.

Skip the default selection when `isDataLakeConfiguration` is true so
data lakes continue to use their own partitioning path.

CI report: #86746

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Two issues with `file_like_engine_default_partition_strategy`:

1. With `wildcard` and a path missing the `{_partition_id}` placeholder,
   `partition_strategy_type` stayed at `NONE`, so `PARTITION BY` was
   silently ignored instead of raising `BAD_ARGUMENTS`. Now set the
   strategy unconditionally and let `PartitionStrategyFactory::get`
   enforce the placeholder check. This also fixes the failing
   `test_file_pruning_with_hive_style_partitioning` integration test.

2. With `hive`, `partition_columns_in_data_file` was left at the
   parse-time default `true` (computed when the strategy was still
   `NONE`), so implicit `hive` behaved differently from explicit
   `partition_strategy='hive'` (which defaults it to `false`). Track
   whether the user provided `partition_columns_in_data_file` and
   recompute the default after the effective strategy is known.

Addresses unresolved AI-reviewer threads on PR #86746.
The default `partition_strategy` for `S3` / `AzureBlobStorage` table
engines and the `s3` table function is now setting-driven via
`file_like_engine_default_partition_strategy`: `wildcard` only under
`compatibility` settings older than `26.5`, `hive` otherwise.

The "(default)" marker under the `Partition Strategy` sections still
hardcoded `wildcard` as the default, which contradicts the parameter
table just above. Spell out the setting-based default instead.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
alexey-milovidov and others added 2 commits May 23, 2026 20:02
…ages

Thread 5 and 6 on PR #86746 — the `S3` engine page
(`docs/en/engines/table-engines/integrations/s3.md`) and the
`azureBlobStorage` table-function page
(`docs/en/sql-reference/table-functions/azureBlobStorage.md`) still
described `WILDCARD` as the partition-strategy default, contradicting
the `s3` table-function and `AzureBlobStorage` engine docs that were
already updated in 69fe2af.

Spell out the same setting-driven phrasing in both pages: defaults to
the `file_like_engine_default_partition_strategy` setting (`WILDCARD`
under `compatibility` settings older than `26.5`, `HIVE` otherwise).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Thread 7 on PR #86746 — `test_file_pruning_with_hive_style_partitioning`
only verified the explicit `file_like_engine_default_partition_strategy`
override; the `SettingsChangesHistory` wiring (`wildcard` for
`compatibility` older than `26.5`, `hive` from `26.5` onwards) was not
covered.

Add two focused assertions: the same `CREATE TABLE ... PARTITION BY`
without `{_partition_id}` must raise the `wildcard` error under
`compatibility = '26.4'`, and must succeed under `compatibility = '26.5'`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
After picking up master, the `02995` baseline is the `26.5.1` release which
does not include this newly-added setting, and the test filter for
`system.settings_changes` requires version > 26.5. Move the registration to
the 26.6 block so the upgrade-detection query accepts the new name.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/86746/16f89ebfb974bf71b94cd595d892ecb234ee9ad4/fast_test/job.log
Previously `initPartitionStrategy` returned early as soon as it saw
`partition_strategy_type == NONE && !partition_by`, which bypassed
`PartitionStrategyFactory::get` and its `BAD_ARGUMENTS` guard for the
inconsistent `partition_columns_in_data_file = 0` + implicit `none` strategy
combination. Move the `partition_by` check into the outer condition so the
default-strategy mapping is skipped but the factory call (and its
consistency checks) still runs.

Addresses AI Review thread `PRRT_kwDOA5dJV86EVRQS` on
`StorageObjectStorageConfiguration.cpp:192`.
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
alexey-milovidov and others added 2 commits May 25, 2026 17:58
`ff135725524` moved the `SettingsChangesHistory` entry for
`file_like_engine_default_partition_strategy` from `26.5` to `26.6`, but
the docs and `test_file_pruning_with_hive_style_partitioning` were not
updated to match. As a result, the test's `compatibility = '26.5'` case
still resolves the setting to `wildcard` (since `applyCompatibilitySetting`
reverts entries from versions strictly newer than the requested value),
and the `CREATE TABLE ... PARTITION BY (b, c)` statement raises
`Partition strategy wildcard can not be used without a '_partition_id'
wildcard` instead of succeeding — the failure mode reported across all
seven `Integration tests` shards on the PR run.

Bump the boundary in the docs and the test to `26.6` so the wildcard /
hive split matches where the change is actually registered. Caught by
the unresolved review thread from `clickhouse-gh` on `f0975cfab95`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.20% 84.20% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.60% 76.70% +0.10%

Changed lines: 85.94% (55/64) | lost baseline coverage: 4 line(s) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov self-assigned this May 30, 2026
@alexey-milovidov
alexey-milovidov merged commit 17c5796 into master May 30, 2026
165 of 166 checks passed
@alexey-milovidov
alexey-milovidov deleted the hive-partitioning-small-changes branch May 30, 2026 08:38
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 30, 2026
@alexbakharew

Copy link
Copy Markdown
Contributor

Hi there,
quick follow-up question. Why this query doesn't fail?

SET compatibility = '26.6';
CREATE TABLE old_export
(
    d Date,
    x UInt64
)
ENGINE = S3(
    's3://bucket/export/data_{_partition_id}.parquet',
    'Parquet'
)
PARTITION BY d;

Checked on head: https://fiddle.clickhouse.com/a0ca16c2-d2f2-47bb-bd1c-824c3519b0f7

I assume that with compatibility = '26.6'; the default partition strategy is 'hive' and {_partition_id} placeholder can't be accepted here?

With explicit partition strategy the error is visible though:

SET compatibility = '26.6';
CREATE TABLE old_export
(
    d Date,
    x UInt64
)
ENGINE = S3(
    's3://bucket/export/data_{_partition_id}.parquet',
    'Parquet',
    partition_strategy='hive'
)
PARTITION BY d;

Error message:


Received exception from server (version 26.6.1):
Code: 36. DB::Exception: Received from localhost:9000. DB::Exception: Partition strategy hive can not be used with a '_partition_id' wildcard in the path. (BAD_ARGUMENTS)
(query: CREATE TABLE old_export
(
    d Date,
    x UInt64
)
ENGINE = S3(
    's3://bucket/export/data_{_partition_id}.parquet',
    'Parquet',
    partition_strategy='hive'
)
PARTITION BY d;)

https://fiddle.clickhouse.com/b64487ad-c378-4ea1-b2db-0d3bacbffacd

cc: @clickgapai @groeneai

@groeneai

Copy link
Copy Markdown
Collaborator

Hi @alexbakharew,

Short answer: it does not fail because the {_partition_id} placeholder in the path makes ClickHouse pick the wildcard strategy at parse time, before the compatibility-driven default is ever consulted. The table effectively uses partition_strategy='wildcard', for which the placeholder is valid, so there is no error.

It is not a compatibility-mapping problem. The file_like_engine_default_partition_strategy change (wildcard -> hive) is registered at version 26.6, and applyCompatibilitySetting only reverts changes for versions strictly newer than the requested value (if (version >= it->first) break;). So at exactly compatibility='26.6' the setting keeps its new value hive. The default really is hive: drop the placeholder from your path and the same statement is created as a hive table. And the placeholder query also succeeds with no compatibility set at all (default is hive on head), which shows the placeholder, not the version, is what selects wildcard here.

Mechanism:

  • StorageObjectStorageConfiguration::initialize() runs first. When partition_strategy is unset and the path contains {_partition_id}, it promotes the strategy to wildcard (comment: "Promote to wildcard in case it is not data lake to make it backwards compatible"). This happens before any setting is read.
  • initPartitionStrategy() only applies the file_like_engine_default_partition_strategy default when the strategy is still NONE. After the promotion it is already WILDCARD, so the hive default is skipped and the hive placeholder check in IPartitionStrategy.cpp never runs.

Your explicit case fails because partition_strategy='hive' sets the type to HIVE directly. That skips the parse-time promotion, so createHivePartitionStrategy reaches the contains_partition_wildcard guard and rejects the {_partition_id} placeholder.

So this is working as designed: a path that literally contains {_partition_id} is treated as unambiguous wildcard intent and overrides the default, which keeps pre-26.6 wildcard CREATE statements working after upgrade. Explicit partition_strategy='hive' together with the placeholder is contradictory and is rejected.

If you think the implicit-default path should instead resolve to hive and then reject the placeholder (to match the explicit case), that is a design call for the PR author rather than a defect in the current code.

Reproduced locally on 26.6.1.1.

(session cron:clickhouse-worker-slot-28:20260610-184200)

pull Bot pushed a commit to peijunlin2008/ClickHouse that referenced this pull request Jul 25, 2026
After ClickHouse#107437, a CREATE
statement with a `{_partition_id}` placeholder in the path and no
explicit `partition_strategy` was rejected with `BAD_ARGUMENTS` whenever
the effective `file_like_engine_default_partition_strategy` default was
`hive` (the default since 26.6). This broke pre-26.6 DDL and DDL
generators that rely on the implicit wildcard strategy.

A `{_partition_id}` placeholder is valid only under the `wildcard`
strategy, so when no explicit strategy is given the path alone
determines the only strategy that can work. `initPartitionStrategy` now
infers `wildcard` from the path shape on CREATE, the same way it already
does on ATTACH / server startup / RESTORE. The default setting only
applies to paths without the placeholder, and an explicit
`partition_strategy = 'hive'` still rejects such paths.

Related: ClickHouse#106465
Related: ClickHouse#86746
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
After ClickHouse#107437, a CREATE
statement with a `{_partition_id}` placeholder in the path and no
explicit `partition_strategy` was rejected with `BAD_ARGUMENTS` whenever
the effective `file_like_engine_default_partition_strategy` default was
`hive` (the default since 26.6). This broke pre-26.6 DDL and DDL
generators that rely on the implicit wildcard strategy.

A `{_partition_id}` placeholder is valid only under the `wildcard`
strategy, so when no explicit strategy is given the path alone
determines the only strategy that can work. `initPartitionStrategy` now
infers `wildcard` from the path shape on CREATE, the same way it already
does on ATTACH / server startup / RESTORE. The default setting only
applies to paths without the placeholder, and an explicit
`partition_strategy = 'hive'` still rejects such paths.

Related: ClickHouse#106465
Related: ClickHouse#86746
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

6 participants