Repository navigation
Support more flexible data paths validation in iceberg - #99935
Conversation
|
Workflow [PR], commit [1744b5e] Summary: ❌
AI ReviewSummaryThis 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
ClickHouse Rules
Final Verdict
|
alexey-milovidov
left a comment
There was a problem hiding this comment.
The newly added test has been found to be flaky.
|
@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)) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()] == '/')) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yeap, the change seems radical, though very logical by its nature
divanik
left a comment
There was a problem hiding this comment.
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>-')" |
There was a problem hiding this comment.
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()] == '/')) |
There was a problem hiding this comment.
Yeap, the change seems radical, though very logical by its nature
LLVM Coverage Report
Changed lines: 82.76% (24/29) | lost baseline coverage: 1 line(s) · Uncovered code |
b823e72
|
This PR was merged with a broken BuzzHouse (amd_tsan) CI check: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99935&sha=1744b5eab84a5f177462c30caa27abc25746e98c&name_0=PR&name_1=BuzzHouse%20%28amd_tsan%29 Fix: #102112 |
|
Hi — this PR may need backporting to Affected code: Why: The If this should be backported, consider adding |
Antalya 26.3 Backport of ClickHouse#99935 - Support more flexible data paths validation in iceberg
…_iceberg Support more flexible data paths validation in iceberg
…_iceberg Support more flexible data paths validation in iceberg
Antalya 26.3 Backport of ClickHouse#99935 - Support more flexible data paths validation in iceberg
|
Hi @alesapin @divanik @alexey-milovidov — while reviewing this PR I found the following:
Happy to discuss — close anything that's wrong or already addressed. |
…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]>
|
This should be backported to merge #119203 |
Changelog category (leave one):
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
This PR is written with help of Claude Code.
Version info
26.4.1.658