jackye1995 commented on code in PR #4423:
URL: https://github.com/apache/iceberg/pull/4423#discussion_r856525069


##########
aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java:
##########
@@ -264,15 +266,24 @@ private boolean isGlueIcebergTable(Table table) {
 
   @Override
   public boolean dropTable(TableIdentifier identifier, boolean purge) {
+    TableOperations ops = newTableOps(identifier);
+    TableMetadata lastMetadata;
+    try {
+      lastMetadata = ops.current();
+    } catch (NoSuchKeyException ex) {
+      // S3 files already deleted, can not get S3 object through metadata 
location
+      lastMetadata = null;
+    }
     try {
-      TableOperations ops = newTableOps(identifier);
-      TableMetadata lastMetadata = ops.current();
       glue.deleteTable(DeleteTableRequest.builder()
           .catalogId(awsProperties.glueCatalogId())
           .databaseName(IcebergToGlueConverter.getDatabaseName(identifier))
           .name(identifier.name())
           .build());
       LOG.info("Successfully dropped table {} from Glue", identifier);
+      ValidationException.check(!purge || 
!awsProperties.glueLakeFormationEnabled() || lastMetadata == null,
+          "Can not delete table S3 files, should call deleteTable first " +

Review Comment:
   The error message is a bit unclear from user perspective, my understanding 
is that "Cannot purge table with LakeFormation enabled because S3 access is 
lost after table is dropped. Please purge table data first before dropping the 
table"



##########
aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java:
##########
@@ -264,15 +266,24 @@ private boolean isGlueIcebergTable(Table table) {
 
   @Override
   public boolean dropTable(TableIdentifier identifier, boolean purge) {
+    TableOperations ops = newTableOps(identifier);
+    TableMetadata lastMetadata;
+    try {
+      lastMetadata = ops.current();
+    } catch (NoSuchKeyException ex) {
+      // S3 files already deleted, can not get S3 object through metadata 
location
+      lastMetadata = null;
+    }
     try {
-      TableOperations ops = newTableOps(identifier);
-      TableMetadata lastMetadata = ops.current();
       glue.deleteTable(DeleteTableRequest.builder()
           .catalogId(awsProperties.glueCatalogId())
           .databaseName(IcebergToGlueConverter.getDatabaseName(identifier))
           .name(identifier.name())
           .build());
       LOG.info("Successfully dropped table {} from Glue", identifier);
+      ValidationException.check(!purge || 
!awsProperties.glueLakeFormationEnabled() || lastMetadata == null,
+          "Can not delete table S3 files, should call deleteTable first " +

Review Comment:
   The error message is a bit unclear from user perspective, my understanding 
is that "Cannot purge table with LakeFormation enabled because S3 access is 
lost after table is dropped. Please purge table data first before dropping the 
table"



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