flyrain commented on code in PR #3719:
URL: https://github.com/apache/polaris/pull/3719#discussion_r2893291321


##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java:
##########
@@ -330,6 +380,153 @@ public Table registerTable(TableIdentifier identifier, 
String metadataFileLocati
     return new BaseTable(ops, fullTableName(name(), identifier), 
metricsReporter());
   }
 
+  private Table overwriteRegisteredTable(
+      TableIdentifier identifier, String metadataFileLocation, String 
locationDir) {
+    LOGGER.debug(
+        "overwriteRegisteredTable called with identifier={}, 
metadataFileLocation={}, locationDir={}",
+        identifier,
+        metadataFileLocation,
+        locationDir);
+
+    /*
+     * High-level overview:
+     * - Resolve the authorized parent for the table so we know the storage 
context.
+     * - Validate and read the provided metadata file using a FileIO tied to 
that
+     *   storage context.
+     * - Ensure the target entity exists and is the correct table-like subtype.
+     * - Replace the stored entity properties (including metadata-location) 
with
+     *   values derived from the parsed TableMetadata and persist the change.
+     */
+
+    // Resolve the table path to obtain storage context for overwrite 
validation.
+    PolarisResolvedPathWrapper resolvedPath =
+        resolvedEntityView.getPassthroughResolvedPath(
+            identifier, PolarisEntityType.TABLE_LIKE, 
PolarisEntitySubType.ANY_SUBTYPE);
+    if (resolvedPath == null || resolvedPath.getRawLeafEntity() == null) {
+      LOGGER.debug("No resolved path or leaf entity found for identifier={}", 
identifier);
+      throw new NoSuchTableException("Table does not exist: %s", identifier);
+    }
+    LOGGER.debug(
+        "Resolved path for identifier={} -> leafEntityId={}, 
leafEntityName={}",
+        identifier,
+        resolvedPath.getRawLeafEntity().getId(),
+        resolvedPath.getRawLeafEntity().getName());
+
+    // Validate the supplied metadata file location against the resolved 
storage.
+    LOGGER.debug(
+        "Validating supplied metadataFileLocation={} against resolved storage 
for identifier={}",
+        metadataFileLocation,
+        identifier);
+    validateLocationForTableLike(identifier, metadataFileLocation, 
resolvedPath);
+
+    // Configure FileIO for the resolved storage and read the metadata file.
+    LOGGER.debug(
+        "Loading FileIO for identifier={} to read metadata at {}", identifier, 
locationDir);
+    FileIO fileIO =
+        loadFileIOForTableLike(
+            identifier,
+            Set.of(locationDir),
+            resolvedPath,
+            new HashMap<>(tableDefaultProperties),
+            Set.of(PolarisStorageActions.READ, PolarisStorageActions.LIST));
+
+    LOGGER.debug(
+        "Reading TableMetadata from metadataFileLocation={} using resolved 
FileIO",
+        metadataFileLocation);
+    TableMetadata metadata = TableMetadataParser.read(fileIO, 
metadataFileLocation);
+    LOGGER.debug(
+        "Parsed TableMetadata for identifier={} -> uuid={}, location={}",
+        identifier,
+        metadata.uuid(),
+        metadata.location());
+
+    LOGGER.debug(
+        "Validating metadata.location()={} for identifier={}", 
metadata.location(), identifier);
+    validateLocationForTableLike(identifier, metadata.location(), 
resolvedPath);
+    validateMetadataFileInTableDir(identifier, metadata);
+    LOGGER.debug(
+        "Metadata file validated to be within table directory for 
identifier={}", identifier);
+
+    List<PolarisEntity> resolvedNamespace = resolvedPath.getRawParentPath();
+    Set<String> dataLocations =
+        StorageUtil.getLocationsUsedByTable(metadata.location(), 
metadata.properties());

Review Comment:
   ```suggestion
       Set<String> tableLocations = 
StorageUtil.getLocationsUsedByTable(metadata);
   ```



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

Reply via email to