Repository navigation
Keep the leading separator in _path when the storage prefix is empty - #116252
PedroTadim merged 2 commits into
Conversation
For an object storage whose namespace is empty, `_path` came back without its
leading separator: `IcebergLocal('/var/lib/clickhouse/user_files/lakes/ice1/')`
reported `var/lib/.../data-x.parquet`, which is not absolute and names no file.
`_iceberg_metadata_file_path` reported the same file with the separator, so two
columns of one query disagreed, and `WHERE _path = '<the absolute path>'`
matched zero rows.
`getUniqueStoragePathIdentifier` stripped a leading separator unconditionally
before joining the path under the namespace. That strip is needed only when
there is a prefix to join under: `fs::path("bucket") / "/key"` discards the
prefix and yields `/key`, whereas `fs::path("") / "/abs"` preserves the
separator on its own. So the strip lost information exactly for the two
backends whose namespace is empty, Local and HDFS, and nothing put it back.
The same strip-then-join rule was also duplicated in the data lake listing
prefilter, which evaluates a `_path` predicate before an object is read. Fixing
only the column would have left that prefilter comparing against the
separator-less string and dropping the object, so the reported symptom would
have survived. Introduce the rule once as `joinPathUnderPrefix` and have both
sites call it.
A third site turns a `_path` value from a filter back into a storage key, so it
has to invert the same rule; with an empty prefix `fs::relative` of an absolute
path is the empty path, which would have discarded every value the fix makes
absolute. `relativizePathUnderPrefix` is that inverse, and it is what makes the
glob shortcut for `hdfs(...) WHERE _path = '/dir/file'` return the row rather
than nothing.
A path is returned unchanged when the prefix is empty rather than being given a
separator: a relative engine argument is legal, and `LocalObjectStorage`
resolves it against `user_files_path` (or the root under clickhouse-local) only
at read time, so prepending one would invent an unrelated root.
S3, Azure and Web have non-empty prefixes at all three sites and are byte
identical. For Local and HDFS this changes a user visible value, which is the
point of the fix: the HDFS integration expectations are updated accordingly.
Related: ClickHouse#116089
Internal second-model review (2 findings, both resolved without a code change)An independent model reviewed this branch cold against the frozen description. It read all seven
The suggested 💡 Use the full issue URL on its own visible line. The full URL is already present verbatim in |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20260825-053800 |
|
Workflow [PR], commit [78c2b8f] Summary: ✅
AI ReviewSummaryThis PR centralizes Findings❌ Blockers
Final Verdict❌ Changes required before merge: the touched LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 28/28 (100.00%) · Uncovered code |
|
cc @Michicosun @hanfei1991, could you review this? |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units40 translation units recompiled, 387 s compile time in total, 40 of them have a recent master baseline. |
The `_path` virtual column and the non-glob `getPaths()` listing prefilter composed the
same value two different ways. The column joined the object path under the namespace via
`getUniqueStoragePathIdentifier`, stripping a leading separator first; the prefilter joined
it raw with `fs::path(getNamespace()) / key`. `fs::path("cont") / "/blob"` discards the
prefix and yields `/blob`, so for a key that keeps a leading separator the prefilter
evaluated predicates against a different string than the column reported, and a filter on
`_path` dropped the only matching file before it was read.
Azure is the reachable backend: it applies no key validation, so a blob named `/slashed.csv`
reproduces it, while S3 rejects such a key outright in `S3::URI::validateKey`.
Reusing `joinPathUnderPrefix` here makes the prefilter agree with the column for both the
empty-prefix and the namespace-bearing case. Reported by review on ClickHouse#116252; this join is a
fourth carrier of the same defect, invisible to an idiom search because it contains neither
`starts_with("/")` nor `fs::relative`.
The new test arm compares `_path` against itself across the two spellings, so it pins them
agreeing rather than pinning either literal.
| const auto relative_path = fs::relative(path, configuration->getNamespace()).string(); | ||
| /// `path` is a `_path` column value, so it needs that column's formatter | ||
| /// inverted rather than a plain relative(). | ||
| const auto relative_path = relativizePathUnderPrefix(configuration->getNamespace(), path); |
There was a problem hiding this comment.
joinPathUnderPrefix is not actually invertible once configuration->getNamespace() is non-empty: both "blob" and "/blob" materialize as the same visible _path ("cont/blob"). This branch assumes a true inverse exists and reconstructs only "blob" via fs::relative, so the _path pushdown is still wrong for the reachable Azure case where the stored key keeps its leading slash (AzureStorageParsedArguments preserves "/..." in setPaths).
With azureBlobStorage(..., '/*') WHERE _path = 'cont/slashed.csv', extractPathValuesFromFilter yields "cont/slashed.csv", relativizePathUnderPrefix turns it into "slashed.csv", the glob validator rejects it against /*, and KeysIterator returns no rows even though GlobIterator would find the blob. This optimization needs to stay conservative for ambiguous _path values under a non-empty namespace, e.g. by falling back to GlobIterator or by validating both "blob" and "/blob" candidates instead of assuming _path -> key is one-to-one.
There was a problem hiding this comment.
Agreed on the mechanism, and this is the residual I flagged in my previous reply rather than a
new one: under a non-empty namespace the _path -> key map is not injective, so relativizing a
_path value back to a key cannot recover a leading separator, and a /-requiring pattern then
rejects the reconstruction. Not fixing it here, for a reason I can measure rather than assert.
The line you cite is unchanged in behaviour for a non-empty namespace. relativizePathUnderPrefix
returns path when the prefix is empty and otherwise evaluates fs::relative(path, prefix), which
is exactly what master already had at that site. getNamespace() is non-empty throughout your
scenario, so the early return cannot fire and the expression is master's.
Measured on Azurite, container holding both plain.csv and a blob named /slashed.csv, this head
against a pristine master build:
| arm | this PR | pristine master |
|---|---|---|
glob /*, WHERE _path = '<cont>/slashed.csv', extraction on |
0 | 0 |
same with s3_path_filter_limit = 0, so GlobIterator (ground truth) |
1 | 1 |
control: glob *, WHERE _path = '<cont>/plain.csv', extraction on |
1 | 1 |
The 0 against 1 confirms the pushdown drops a row the glob iterator finds. Identical in both
builds, so this change neither introduces nor widens it, and the control moving to 1 shows the
harness discriminates.
One correction to the reachability. I checked fillBlobsFromURLCommon and it does keep the
separator, blob_path = container_blob_path.substr(pos_blob_path) taken from the slash inclusive,
so a URL-form argument always yields a key starting /. I expected that to make the defect
reachable for ordinary blob names, which would be much broader than what you described. It does
not: asking which blob the pattern actually lists returns only <cont>/slashed.csv, never
<cont>/plain.csv. A /-requiring pattern matches only a key that really carries the separator,
which is why the control arm is unaffected.
On the two remedies. Every _path value is ambiguous under a non-empty namespace, since that is
the non-injectivity itself, so falling back to GlobIterator on ambiguity is not a narrow guard,
it retires the extraction for all namespace-bearing backends. Validating both candidates doubles
the candidate set of a validator whose stated job is to prevent scanning unallowed data, so it is
an access-control widening rather than a formatting fix. Both are decisions about the pushdown
optimization's contract, not about the path formatter this PR corrects, and neither is verifiable
as an increment on this branch. I would rather leave the optimization's owner a measured
description than pick one of those directions here.
Leaving the thread for a human at this point rather than continuing to trade rounds on it.
|
@scanhex12 @SmitaRKulkarni easy to review |
|
This PR is good to merge |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the
_pathvirtual column and the listing prefilters composing a path inconsistently, soWHERE _path = '<path>'could match no rows. Affected object storages with an empty namespace, such asIcebergLocaland HDFS, and keys that keep a leading separator onazureBlobStorage.Description
Related: #116089
getUniqueStoragePathIdentifierstripped a leading separator unconditionallybefore joining under the namespace. The strip is needed only when there is a
prefix to join under, because
fs::path("bucket") / "/key"would otherwisediscard the prefix, so it lost information exactly for the empty-namespace
backends, Local and HDFS.
Four sites share that rule. The data lake listing prefilter evaluates a
_pathpredicate before an object is read, so a column-only fix would have left it
dropping the object (confirmed with such a build). A third site inverts the rule,
mapping a filter's
_pathback to a storage key, wherefs::relativeagainst anempty prefix yields the empty path and would discard every value this fix makes
absolute. The fourth, the non-glob listing prefilter, joined raw and so diverged
in the opposite direction: with a namespace present, a key keeping a leading
separator lost the prefix, so
_pathreportedcont/blobwhile the prefiltersaw
/bloband filtered out the only file before reading it. Azure reaches it;S3 rejects such a key in
S3::URI::validateKey.Rule and inverse now live in one place each,
joinPathUnderPrefixandrelativizePathUnderPrefix, which also turnshdfs('.../dir/file*') WHERE _path = '/dir/file1'into the row it should return.An empty prefix returns the path unchanged rather than adding a separator: a
relative engine argument is legal and is resolved against
user_files_pathonlyat read time, so a separator would invent an unrelated root (test arm pins it).
S3, Azure and Web are byte identical at the first three sites, checked against
both builds. For Local and HDFS the value changes as intended; HDFS expectations
are updated and pass.
Note #90740 rewrites this function and repeats the strip; whichever merges second
should adopt the shared helper.
Workflow [PR]
Sync PR [sync-upstream/pr/116252]
Version info
26.9.1.202(included in26.9and later)