jerryshao commented on code in PR #15004: URL: https://github.com/apache/gravitino/pull/15004#discussion_r4596710113
########## iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/utils/IcebergTableLocationUtils.java: ########## @@ -0,0 +1,134 @@ +/* + * 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.gravitino.iceberg.common.utils; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import javax.annotation.Nullable; + +/** Location comparisons and JDBC lookup patterns for Iceberg's standard metadata layout. */ +public final class IcebergTableLocationUtils { + private static final String METADATA_DIRECTORY = "/metadata/"; + + private IcebergTableLocationUtils() {} + + /** + * Normalizes trailing separators, local URI forms and equivalent S3 schemes. + * + * @param location storage location, possibly absent + * @return normalized location, or an empty string for an absent location + */ + public static String normalize(@Nullable String location) { + if (location == null) { + return ""; + } + String value = location.trim(); + if (value.startsWith("s3a://") || value.startsWith("s3n://")) { + value = "s3://" + value.substring(6); + } else if (value.startsWith("file:")) { + String path = value.substring(5); + while (path.startsWith("//")) { + path = path.substring(1); + } + value = "file:" + (path.startsWith("/") ? path : "/" + path); + } else if (value.startsWith("/")) { + value = "file:" + value; + } + while (value.endsWith("/") && !value.endsWith(":/")) { + value = value.substring(0, value.length() - 1); + } + return value; Review Comment: [P1] An explicit location such as `file:/warehouse/./private` resolves to the same directory as an existing table at `file:/warehouse/private`, but the new normalization and JDBC patterns treat them as unrelated. The source-load check is therefore skipped. Please canonicalize or reject filesystem path aliases before both candidate lookup and overlap comparison, preserving object-store key semantics. Add an authorization regression covering dot segments and repeated separators. ########## iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java: ########## @@ -245,6 +246,19 @@ public UpdateNamespacePropertiesResponse updateNamespaceProperties( public LoadTableResponse registerTable(Namespace namespace, RegisterTableRequest request) { validateTableLocation(request.metadataLocation()); + Catalog loadedCatalog = getCatalog(); + // Subclasses can enforce additional registration invariants through the original API. + if (request instanceof RegisterTableRequestWithMetadata + && loadedCatalog.getClass() == JdbcCatalogWithMetadataLocationSupport.class) { Review Comment: [P1] For a remote-warehouse Hive or custom catalog, registering a remote metadata file containing `location: file:/tmp/table` or a local `write.metadata.path` skips these checks because they are inside the exact-JDBC optimization branch. Please validate the supplied metadata snapshot before selecting the backend registration path, while preserving custom registration hooks. Add a fallback-backend regression asserting rejection before registration. -- 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]
