Skip to content

Add {_schema_hash} placeholder for S3 table engine - #98265

Merged
mstetsyuk merged 10 commits into
masterfrom
schema-hash-placeholder-s3-table-engine
Mar 11, 2026
Merged

mstetsyuk merged 10 commits into
masterfrom
schema-hash-placeholder-s3-table-engine

Conversation

@mstetsyuk

@mstetsyuk mstetsyuk commented Feb 27, 2026 •

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

Add a {_schema_hash} placeholder for the S3 table engine that inserts a hash of the table's column definitions into the S3 path.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Note

Medium Risk
Touches core object-storage path resolution (including glob/placeholder detection) and changes TRUNCATE behavior for partitioned paths, which could affect existing S3/Azure/HDFS/Local table configurations at runtime.

Overview
Adds support for a new {_schema_hash} placeholder in object-storage paths, computing a SipHash from the table’s physical column definitions and substituting it into the configured read/write paths (rejecting use without explicit columns, with DataLake engines, or with partition_strategy='hive').

Updates configuration implementations (S3/Azure/HDFS/Local) to allow mutating the raw path after initialization, refines glob detection to ignore {_partition_id}/{_schema_hash} placeholders, and makes TRUNCATE explicitly fail for partitioned tables (paths containing {_partition_id}) instead of silently succeeding. Tests are extended to cover the new placeholder, validation errors, and the updated truncate semantics.

Written by Cursor Bugbot for commit 9b46f0a. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.3.1.581

@clickhouse-gh

clickhouse-gh Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9b46f0a]

Summary: ❌

job_name test_name status info comment
Stress test (amd_tsan) failure
Logical error: 'assertHasValidVersionMetadata()' (STID: 2508-3f62) FAIL cidb

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Feb 27, 2026
@bharatnc bharatnc self-assigned this Feb 28, 2026
@divanik divanik self-assigned this Feb 28, 2026
@mstetsyuk
mstetsyuk requested a review from divanik March 4, 2026 15:42
@bharatnc

bharatnc commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

Related to #98265 (comment): I think we need to disallow {_schema_path} for hive partitioning. Look at the initPartitionStrategy code below. Having {_schema_path} in path will make hasGlobs return true.

void StorageObjectStorageConfiguration::initPartitionStrategy(ASTPtr partition_by, const ColumnsDescription & columns, ContextPtr context)
{
partition_strategy = PartitionStrategyFactory::get(
partition_strategy_type,
partition_by,
columns.getOrdinary(),
context,
format,
getRawPath().hasGlobs(),
getRawPath().hasPartitionWildcard(),
partition_columns_in_data_file);
if (partition_strategy)
{

It'll probably never happen with {_partition_id} because if a path contains {_partition_id} and the user didn't explicitly specify a partition strategy, ClickHouse forces partition_strategy_type = WILDCARD. So initPartitionStrategy is then called with WILDCARD, never reaching the HIVE branch in PartitionStrategyFactory::get - see below:

else if (configuration_to_initialize.partition_strategy_type == PartitionStrategyFactory::StrategyType::NONE)
{
if (configuration_to_initialize.getRawPath().hasPartitionWildcard())
{
// Promote to wildcard in case it is not data lake to make it backwards compatible
configuration_to_initialize.partition_strategy_type = PartitionStrategyFactory::StrategyType::WILDCARD;
}

On the other hand, from what I can see, {_schema_hash} has no equivalent logic in initialize() so there's no code that changes partition_strategy_type based on its presence. So if a user explicitly sets partition_strategy='hive' and the path contains {_schema_hash}, initPartitionStrategy is called with HIVE, reaches createHivePartitionStrategy, and hasGlobs() returning true for {_schema_hash}. This will trigger a rather misleading "globbed path" error.

I think the simplest solution would be to explicitly disallow the combination by adding a check in the new {_schema_hash} block in StorageObjectStorage.cpp alongside the existing DataLake check. Something similar to:

 if (configuration->getRawPath().hasSchemaHashWildcard())                                                                                                                                                                                                                                                                    
  {               
      if (configuration->isDataLakeConfiguration())
          throw Exception(ErrorCodes::BAD_ARGUMENTS, "The `_schema_hash` placeholder is not supported for DataLake engines");

      if (configuration->partition_strategy_type == PartitionStrategyFactory::StrategyType::HIVE)
          throw Exception(ErrorCodes::BAD_ARGUMENTS, "The `_schema_hash` placeholder is not supported with hive partition strategy");
      ...
  }

Also, maybe good to add a test for this.

@mstetsyuk
mstetsyuk requested a review from bharatnc March 5, 2026 18:31
In `{ echo }` mode, queries expecting `serverError` are still echoed
to stdout. The reference file was missing these lines, causing CI to
fail with a diff mismatch.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
const S3::S3AuthSettings & getAuthSettings() const { return s3_settings->auth_settings; }

Path getRawPath() const override { return url.key; }
void setRawPath(const Path & path) override { url.key = path.path; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

S3 setRawPath doesn't update uri_str, causing URI inconsistency

Medium Severity

The S3 setRawPath implementation sets url.key = path.path but doesn't update url.uri_str. After setSchemaHash calls setRawPath, url.key contains the resolved path (with the actual hash) while url.uri_str still contains the {_schema_hash} placeholder. Since getRawURI() returns url.uri_str and is documented as being used for permission checks, this inconsistency means permission checks evaluate against a stale URI containing the literal {_schema_hash} text rather than the resolved path. This differs from {_partition_id} behavior, where the raw path and URI remain consistently unresolved.

Additional Locations (1)

Fix in Cursor Fix in Web

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.

URI is only used in the permission check (checkAccessWithFilter), which runs in ITableFunction::execute before setSchemaHash is ever called.

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

@clickhouse-gh

clickhouse-gh Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.20% 83.80% +0.60%
Functions 20.40% 23.90% +3.50%
Branches 75.30% 76.40% +1.10%

PR changed lines: PR changed-lines coverage: 87.07% (101/116)
Diff coverage report
Uncovered code

@mstetsyuk
mstetsyuk added this pull request to the merge queue Mar 11, 2026
Merged via the queue into master with commit 9d062ca Mar 11, 2026
158 of 159 checks passed
@mstetsyuk
mstetsyuk deleted the schema-hash-placeholder-s3-table-engine branch March 11, 2026 14:14
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 11, 2026
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.

4 participants