github-actions[bot] commented on code in PR #70869:
URL: https://github.com/apache/doris/pull/70869#discussion_r4665907568


##########
fe/fe-iceberg-common/src/main/java/org/apache/doris/connector/iceberg/IcebergV4FileIO.java:
##########
@@ -0,0 +1,170 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.connector.iceberg;
+
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.LoadingCache;
+import org.apache.iceberg.ContentFile;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.DeleteFile;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.InternalData;
+import org.apache.iceberg.ManifestFile;
+import org.apache.iceberg.ManifestListFile;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.avro.AvroIterable;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.io.OutputFile;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Map;
+import java.util.Objects;
+import java.util.regex.Pattern;
+
+/** Serializable, borrowed read view for table-relative format v4 locations. */
+public final class IcebergV4FileIO implements FileIO {
+    private static final long serialVersionUID = 1L;
+    private static final Pattern SCHEME = 
Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*:.*", Pattern.DOTALL);
+    private final FileIO delegate;
+    private final String tableLocation;
+    private transient LoadingCache<String, Integer> manifestVersions;
+
+    public IcebergV4FileIO(FileIO delegate, String tableLocation) {
+        this.delegate = Objects.requireNonNull(delegate, "delegate");
+        this.tableLocation = tableLocation;
+    }
+
+    public FileIO delegate() {
+        return delegate;
+    }
+
+    public static String resolve(String tableLocation, String path) {
+        Objects.requireNonNull(path, "path");
+        if (isAbsolute(path)) {
+            return path;
+        }
+        if (tableLocation == null || tableLocation.isEmpty()) {
+            throw new IllegalArgumentException("Relative Iceberg v4 path 
requires a table location: " + path);
+        }
+        // Duplicate separators are part of an object-store key, including at 
the concatenation boundary.
+        return tableLocation + "/" + path;
+    }
+
+    private static boolean isAbsolute(String path) {
+        return SCHEME.matcher(path).matches();
+    }
+
+    private static boolean isAbsoluteMetadataLocation(String path) {
+        // Upgrades retain filesystem-rooted write.metadata.path locations 
without a URI scheme.
+        // Content paths use their producing manifest's rules instead, so a V4 
"/data/file" stays relative.
+        return path.startsWith("/") || isAbsolute(path);

Review Comment:
   [P2] Resolve slash-leading V4 metadata references against the table. A 
leading slash is still relative in V4 when there is no URI scheme ([released 
specification](https://github.com/apache/iceberg/blob/apache-iceberg-1.12.0/format/spec.md#paths-in-metadata)).
 SDK 1.12 can commit this case: write a V4 manifest at `table.location() + 
"//metadata/m.avro"`, copy its descriptor with path `"/metadata/m.avro"`, then 
call `newFastAppend().appendManifest(copy).commit()`; snapshot-id inheritance 
preserves that path without reopening it. This helper classifies it as legacy 
absolute, so `newInputFile(ManifestFile)` opens filesystem `/metadata/m.avro` 
instead of the manifest under the table. A fresh V4 table therefore fails 
ordinary reads. Distinguish inherited legacy locations before bypassing V4 
resolution, and cover a leading-slash metadata reference alongside the existing 
content-path tests.



##########
fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergManifestCache.java:
##########
@@ -230,14 +235,23 @@ ManifestCacheValue getManifestCacheValue(ManifestFile 
manifest, Table table, Str
 
     /** Uses one stable statement identity while retaining only values 
classified as plaintext. */
     ManifestCacheValue readForStatement(ManifestFile manifest, Table table, 
Object loadScope, boolean privateRead) {
-        IcebergManifestEntryKey key = IcebergManifestEntryKey.of(manifest);
+        IcebergManifestEntryKey key = manifestKey(manifest, table);
         return privateRead ? IcebergManifestLoader.read(manifest, table, 
manifest.content(), false)
                 : entry.getForLoadScope(key, loadScope, k -> 
IcebergManifestLoader.read(
                         manifest, table, k.getContent(), 
entry.isWeightBounded()));
     }
 
-    void recordStatementAccess(ManifestFile manifest, String queryId, boolean 
allowCacheHit) {
-        recordAccess(IcebergManifestEntryKey.of(manifest), queryId, 
allowCacheHit);
+    void recordStatementAccess(ManifestFile manifest, Table table, String 
queryId, boolean allowCacheHit) {
+        recordAccess(manifestKey(manifest, table), queryId, allowCacheHit);
+    }
+
+    private static IcebergManifestEntryKey manifestKey(ManifestFile manifest, 
Table table) {
+        if (table instanceof BaseTable && ((BaseTable) 
table).operations().current().formatVersion() >= 4) {
+            // The same relative manifest name can describe different bytes in 
different table locations.
+            return new 
IcebergManifestEntryKey(IcebergV4FileIO.resolve(table.location(), 
manifest.path()),

Review Comment:
   [P2] Preserve manifest provenance across relative and absolute cache 
aliases. Let V4 table A at `s3://bucket/A` reference `metadata/shared.avro`, 
and table B at `s3://bucket/B` reference the same manifest as 
`s3://bucket/A/metadata/shared.avro`. These now share a cache key, but the 
cached SDK ContentFile copies retain A's raw `manifestLocation` 
(`metadata/shared.avro`; see [SDK 
inheritance](https://github.com/apache/iceberg/blob/apache-iceberg-1.12.0/core/src/main/java/org/apache/iceberg/InheritableMetadataFactory.java#L30-L80)).
 After A warms the cache, B's `isLegacyEntry` version probe opens 
`s3://bucket/B/metadata/shared.avro`, which need not exist; a 
cold/cache-disabled B read instead uses the correct absolute provenance. This 
occurs with a valid V4 Avro manifest containing ordinary relative data paths, 
and range normalization runs outside the SDK-fallback catch. Canonicalize 
cached provenance or distinguish the raw spelling/base in the key, and add a 
warm shared-manifest alia
 s test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to