henrib commented on code in PR #6812:
URL: https://github.com/apache/hive/pull/6812#discussion_r4169752235


##########
iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/ScopedDeleteFileIO.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.iceberg.hive;
+
+import java.util.Map;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.metastore.utils.FileUtils;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.io.OutputFile;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A {@link FileIO} decorator used by {@link 
HiveCatalog#dropTable(org.apache.iceberg.catalog.TableIdentifier,
+ * boolean)} to fence purge deletions to files under a table's own location, 
regardless of what a table's
+ * metadata or manifests actually reference.
+ *
+ * <p>This does not implement {@link 
org.apache.iceberg.io.SupportsBulkOperations} or
+ * {@link org.apache.iceberg.io.SupportsPrefixOperations} even when the 
delegate does, so that
+ * {@code CatalogUtil.dropTableData} is forced to route every deletion through 
{@link #deleteFile(String)}.
+ */
+class ScopedDeleteFileIO implements FileIO {
+  private static final Logger LOG = 
LoggerFactory.getLogger(ScopedDeleteFileIO.class);
+
+  private final FileIO delegate;
+  private final Path location;
+
+  ScopedDeleteFileIO(FileIO delegate, String location) {
+    this.delegate = delegate;
+    this.location = new Path(location);
+  }
+
+  @Override
+  public InputFile newInputFile(String path) {
+    return delegate.newInputFile(path);
+  }
+
+  @Override
+  public OutputFile newOutputFile(String path) {
+    return delegate.newOutputFile(path);
+  }
+
+  @Override
+  public void deleteFile(String path) {
+    var candidate = new Path(path);
+    if (!FileUtils.isPathWithinSubtree(qualify(candidate, location), 
qualify(location, candidate))) {
+      LOG.debug("Skipping delete outside table location {}: {}", location, 
path);
+      return;
+    }
+    delegate.deleteFile(path);
+  }
+
+  /**
+   * A path with no scheme refers to the same filesystem location as an 
otherwise-identical path
+   * that does carry one, whichever side that happens to be: manifests can 
hold data file paths
+   * written without a scheme, and a table's own location can equally be 
scheme-less (e.g. when a
+   * caller supplies one explicitly). {@link org.apache.hadoop.fs.Path#equals} 
is scheme-sensitive,
+   * so without this a schemeless path would never match its scheme-qualified 
counterpart in
+   * {@link FileUtils#isPathWithinSubtree} even when it is nested directly 
under it. When both (or
+   * neither) sides carry a scheme, {@code path} is returned unchanged, so a 
genuine mismatch (e.g.
+   * a different scheme or authority) is still correctly treated as outside 
the table location.
+   */
+  private static Path qualify(Path path, Path other) {
+    var pathUri = path.toUri();
+    var otherUri = other.toUri();
+    if (pathUri.getScheme() == null && otherUri.getScheme() != null) {
+      return new Path(otherUri.getScheme(), otherUri.getAuthority(), 
pathUri.getPath());

Review Comment:
   Qualifying a scheme-less path against whatever scheme the other side 
happened to carry wasn't quite right — a scheme-less path refers to a location 
on the cluster's default filesystem (`fs.defaultFS`), not to the comparison 
target's filesystem. `ScopedDeleteFileIO` now takes the Hadoop `Configuration` 
and qualifies both the candidate and the table location via 
`FileSystem.getDefaultUri(conf)` instead.



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