adutra commented on code in PR #3682:
URL: https://github.com/apache/polaris/pull/3682#discussion_r2773498080


##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java:
##########
@@ -330,6 +357,80 @@ public Table registerTable(TableIdentifier identifier, 
String metadataFileLocati
     return new BaseTable(ops, fullTableName(name(), identifier), 
metricsReporter());
   }
 
+  private Table overwriteRegisteredTable(
+      TableIdentifier identifier, String metadataFileLocation, String 
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 parent namespace path that was authorized for this catalog.
+    PolarisResolvedPathWrapper resolvedParent =
+        resolvedEntityView.getResolvedPath(identifier.namespace());
+    if (resolvedParent == null) {
+      throw new IllegalStateException(
+          String.format("Failed to fetch resolved parent for TableIdentifier 
'%s'", identifier));
+    }
+
+    // Validate the supplied metadata file location against the resolved 
storage.
+    validateLocationForTableLike(identifier, metadataFileLocation, 
resolvedParent);
+
+    // Configure FileIO for the resolved storage and read the metadata file.
+    FileIO fileIO =
+        loadFileIOForTableLike(
+            identifier,
+            Set.of(locationDir),
+            resolvedParent,
+            new HashMap<>(tableDefaultProperties),
+            Set.of(PolarisStorageActions.READ, PolarisStorageActions.LIST));
+
+    TableMetadata metadata = TableMetadataParser.read(fileIO, 
metadataFileLocation);
+    validateLocationForTableLike(identifier, metadata.location(), 
resolvedParent);
+    validateMetadataFileInTableDir(identifier, metadata);
+
+    // Find the passthrough-resolved entity so we can update the stored record.
+    PolarisResolvedPathWrapper resolvedPath =
+        resolvedEntityView.getPassthroughResolvedPath(
+            identifier, PolarisEntityType.TABLE_LIKE, 
PolarisEntitySubType.ANY_SUBTYPE);
+    if (resolvedPath == null || resolvedPath.getRawLeafEntity() == null) {
+      throw new NoSuchTableException("Table does not exist: %s", identifier);
+    }
+
+    // Ensure the raw entity is an Iceberg table-like entity (not a 
view/generic table).
+    PolarisEntity rawEntity = resolvedPath.getRawLeafEntity();
+    if (rawEntity.getSubType() == PolarisEntitySubType.ICEBERG_VIEW) {
+      throw new AlreadyExistsException("View with same name already exists: 
%s", identifier);
+    } else if (rawEntity.getSubType() == PolarisEntitySubType.GENERIC_TABLE) {
+      throw new AlreadyExistsException(
+          "Generic table with same name already exists: %s", identifier);
+    }
+
+    IcebergTableLikeEntity existingEntity = 
IcebergTableLikeEntity.of(rawEntity);
+    if (existingEntity == null) {
+      throw new NoSuchTableException("Table does not exist: %s", identifier);
+    }
+
+    // Build updated entity from parsed metadata and persist the update.
+    Map<String, String> storedProperties = 
buildTableMetadataPropertiesMap(metadata);
+    IcebergTableLikeEntity updatedEntity =
+        new IcebergTableLikeEntity.Builder(existingEntity)
+            .setInternalProperties(storedProperties)
+            .setMetadataLocation(metadataFileLocation)
+            .build();
+
+    updateTableLike(identifier, updatedEntity);

Review Comment:
   Are we keeping the old table UUID here, or switching to the new UUID? I 
think the expected semantics is to switch to the new one.



##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/CatalogHandlerUtils.java:
##########
@@ -348,7 +349,21 @@ public LoadTableResponse registerTable(
     request.validate();
 
     TableIdentifier identifier = TableIdentifier.of(namespace, request.name());
-    Table table = catalog.registerTable(identifier, 
request.metadataLocation());
+    // Determine whether the client requested overwrite semantics. For 
catalogs that

Review Comment:
   This class is copied from Iceberg, I'm not sure it's a good idea to modify 
it. I would move the Polaris-specific logic to `IcebergCatalog` or 
`IcebergCatalogHandler`.



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