Skip to content

Support more flexible data paths validation in iceberg - #99935

Merged
alesapin merged 12 commits into
ClickHouse:masterfrom
alesapin:fix_weird_pathes_in_iceberg
Apr 8, 2026
Merged

alesapin merged 12 commits into
ClickHouse:masterfrom
alesapin:fix_weird_pathes_in_iceberg

Conversation

@alesapin

@alesapin alesapin commented Mar 18, 2026 •

Copy link
Copy Markdown
Member

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

Now ClickHouse should properly handle spark-style tables (where we have full absolute path for each file or relative path to common table path). Fixes #92348.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

This PR is written with help of Claude Code.

Version info

  • Merged into: 26.4.1.658

@clickhouse-gh

clickhouse-gh Bot commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1744b5e]

Summary: ❌

job_name test_name status info comment
BuzzHouse (amd_tsan) failure
Logical error: Queries with distributed_group_by_no_merge=1 should be processed to Complete stage (STID: 4653-55af) FAIL cidb, issue ISSUE CREATED

AI Review

Summary

This PR hardens Iceberg path resolution and metadata filename parsing to avoid exceptions on malformed Spark-style metadata, and adds focused regression tests. The core fix is directionally correct and test coverage is good. I found one remaining user-facing issue: one validation error message still advertises only one accepted metadata filename pattern even though the parser accepts two patterns.

Findings

💡 Nits

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp:168] The non-digit version-token error still says Expected vN.metadata.json where N is a number, but the parser accepts both vN.metadata.json and N-<uuid>.metadata.json. This can mislead users during debugging.
    • Suggested fix: align this throw message with the two-pattern wording used at lines 150/161.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ✅
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Update the remaining misleading error message in getMetadataFileAndVersion to mention both accepted metadata filename formats.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Mar 18, 2026

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

The newly added test has been found to be flaky.

@alesapin

Copy link
Copy Markdown
Member Author

@alexey-milovidov our "Summary" message is really good #99935 (comment), the fact that test is flaky is not a sacred knowledge, it's visible to everyone. Please stop abusing review button.

/// Case 1: data_path starts with table_location (common for Spark-created tables where
/// table_location uses a different scheme/bucket than ClickHouse's path).
/// Extract the relative suffix and prepend common_path.
if (data_path.starts_with(table_location))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This branch now accepts any data_path that has table_location as a raw string prefix, but it does not enforce a path boundary. For example, table_location = s3://bucket/table and data_path = s3://bucket/table2/data/file.parquet will match and be rewritten as if the file belonged to table.

That can silently resolve to an incorrect object key instead of rejecting invalid metadata.

Please add a boundary check before entering this branch (e.g. require data_path.size() == table_location.size() or data_path[table_location.size()] == '/').

auto dash_pos = file_name.find_first_of('-');
if (dash_pos == String::npos || dash_pos == 0)
throw Exception(
ErrorCodes::BAD_ARGUMENTS, "Bad metadata file name: '{}'. Expected vN.metadata.json where N is a number", file_name);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This new validation branch handles names of the form <V>-<random-uuid>.metadata.json, but the thrown message says only Expected vN.metadata.json where N is a number.

That is misleading for users debugging invalid metadata names in this branch. Please update the message to mention both accepted patterns (for example: vN.metadata.json or N-<uuid>.metadata.json).


if (raw_path.starts_with(table_location) && table_location.ends_with(table_root))
if (raw_path.starts_with(table_location)
&& (raw_path.size() == table_location.size() || raw_path[table_location.size()] == '/'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change explicitly broadens accepted layouts (table_location may differ from table_root), but the fallback branch below still assumes the old invariant:

table_location.substr(0, table_location.size() - table_root.size())

If raw_path does not contain table_root and table_location does not actually end with table_root, we trim by unrelated string length and return a garbage key instead of rejecting unresolvable metadata.

Please guard the second-branch fallback with a real suffix check (for example table_location.ends_with(table_root)), and throw BAD_ARGUMENTS when that invariant is not satisfied.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeap, the change seems radical, though very logical by its nature

@divanik divanik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One question about athena use case, which I didn't get.As far as I understand that use case in #97234 is not only having metadata and data in different locations, but traversing subdirectories for finding metadata.json files. If we don't want to address it here - it is fine, but if so let's not closing 97234 by this Pr

OLD_PATH="${BASE_PATH}/${UUID_OLD}"
NEW_PATH="${BASE_PATH}/${UUID_NEW}"

NORMALIZE="replaceRegexpAll(replaceRegexpAll(replaceOne(replaceOne(replaceOne(_path, '${BASE_PATH}', '<base>'), '${UUID_OLD}', '<uuid_old>'), '${UUID_NEW}', '<uuid_new>'), '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}', '<uuid>'), 'snap-[0-9]+-[0-9]+-', 'snap-<id>-')"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is unreadable, to be honest, could you add a comment about what it is doing?


if (raw_path.starts_with(table_location) && table_location.ends_with(table_root))
if (raw_path.starts_with(table_location)
&& (raw_path.size() == table_location.size() || raw_path[table_location.size()] == '/'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeap, the change seems radical, though very logical by its nature

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default and removed pr-improvement Pull request with some product improvements labels Apr 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 83.90% -0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.50% 76.40% -0.10%

Changed lines: 82.76% (24/29) | lost baseline coverage: 1 line(s) · Uncovered code

Full report · Diff report

@alesapin
alesapin added this pull request to the merge queue Apr 8, 2026
Merged via the queue into ClickHouse:master with commit b823e72 Apr 8, 2026
160 of 161 checks passed
@alesapin
alesapin deleted the fix_weird_pathes_in_iceberg branch April 8, 2026 15:04
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 8, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

@clickgapai

Copy link
Copy Markdown
Contributor

Hi — this PR may need backporting to 26.3 (LTS), 26.2, 26.1, 25.8 (LTS), but no backport label was found.

Affected code: getMetadataFileAndVersion in Utils.cpp — find_first_of result used without npos check — core code present in all supported branches.

Why: The getMetadataFileAndVersion crash (std::out_of_range on malformed metadata filenames) exists in all supported branches — git log shows the function was introduced in commit ccd419e (2025-06-25), predating all supported releases. The IcebergPathResolver changes only apply to master (file added 2026-03-10). Only the Utils.cpp fix portion is relevant for backport.

If this should be backported, consider adding pr-must-backport or a version-specific label (e.g. v26.3-must-backport). Ignore this if backporting is not applicable.

zvonand added a commit to Altinity/ClickHouse that referenced this pull request May 18, 2026
Antalya 26.3 Backport of ClickHouse#99935 - Support more flexible data paths validation in iceberg
il9ue pushed a commit to il9ue/ClickHouse that referenced this pull request May 20, 2026
…_iceberg

Support more flexible data paths validation in iceberg
subkanthi pushed a commit to Altinity/ClickHouse that referenced this pull request May 26, 2026
…_iceberg

Support more flexible data paths validation in iceberg
subkanthi pushed a commit to Altinity/ClickHouse that referenced this pull request May 26, 2026
Antalya 26.3 Backport of ClickHouse#99935 - Support more flexible data paths validation in iceberg
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @alesapin @divanik @alexey-milovidov — while reviewing this PR I found the following:

Happy to discuss — close anything that's wrong or already addressed.

pull Bot pushed a commit to AnotherGenZ/ClickHouse that referenced this pull request Aug 31, 2026
…able path

Reading an Iceberg table through a path that is a parent of the table
directory, with the metadata document named by iceberg_metadata_file_path,
failed on every data and manifest file with a 404.

IcebergPathResolver is constructed with table_location (the metadata
`location` field) and table_root (the path the user queried), and
resolve() re-roots each metadata path from the first onto the second.
That is sound only while both name the same directory.
iceberg_metadata_file_path lets the queried path be an ancestor of the
table directory, and the re-rooting then silently deletes the components
in between: location s3://warehouse/tbl/UUIDDIR with queried path tbl
yields tbl/data/data-<uuid>.parquet.

The condition that used to reject this, table_location.ends_with(common_path),
was swapped for a component-boundary check in ClickHouse#99935 (merge b823e72,
26.4.1.658). That swap fixed a substr out_of_range (ClickHouse#92348) and is what
lets the cross-bucket Spark layout of 04034 resolve, so restoring it is
not an option; 04034 would regress.

Instead the resolver is now given the table's root directory, derived
from where the metadata document actually sits (<root>/metadata/<file>)
and adopted only if the location the document declares names that same
directory. Two independent sources have to agree, nothing parses a URI
scheme, and the derivation falls back to the queried path whenever they
cannot be shown to agree, so a table whose metadata is discovered under
<queried>/metadata/ is bit-for-bit unaffected. resolve() and its call
sites are untouched and fixed through the single construction site.

Operations scoped to the queried path would write and delete across the
sibling tables under it in this layout, so INSERT, ALTER, mutations,
OPTIMIZE, OPTIMIZE ... MANIFEST, expire_snapshots and remove_orphan_files
are refused while the root had to be derived. Deleting data on DROP is
skipped with a warning rather than refused: drop() runs from
DatabaseCatalog::dropTableFinally after the table is already marked as
dropped, so throwing there does not refuse anything, it makes the catalog
retry the drop every two seconds indefinitely and leaves the table
undroppable. Reads 404 today in exactly this state, so no configuration
that works today is refused.

Closes: ClickHouse#116985

Co-Authored-By: Claude Opus 5 <[email protected]>
@PedroTadim

Copy link
Copy Markdown
Member

This should be backported to merge #119203

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore labels Sep 11, 2026
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-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg std::out_of_range

7 participants