theoxu31 commented on code in PR #6742:
URL: https://github.com/apache/iceberg/pull/6742#discussion_r1098092626


##########
aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java:
##########
@@ -437,6 +439,44 @@ public void renameTable(TableIdentifier from, 
TableIdentifier to) {
     LOG.info("Successfully renamed table from {} to {}", from, to);
   }
 
+  @Override
+  public org.apache.iceberg.Table registerTable(TableIdentifier identifier, 
String metadataFileLocation) {
+    Preconditions.checkArgument(isValidIdentifier(identifier),
+        "Table identifier to register is invalid: " + identifier);
+    Preconditions.checkArgument(metadataFileLocation != null && 
!metadataFileLocation.isEmpty(),
+        "Cannot register an empty metadata file location as a table");
+
+    Map<String, String> tableParameters = ImmutableMap.of(
+        BaseMetastoreTableOperations.TABLE_TYPE_PROP,
+        
BaseMetastoreTableOperations.ICEBERG_TABLE_TYPE_VALUE.toLowerCase(Locale.ENGLISH),
+        BaseMetastoreTableOperations.METADATA_LOCATION_PROP,
+        metadataFileLocation);
+
+    TableInput tableInput = TableInput.builder()
+        .name(IcebergToGlueConverter.getTableName(identifier, 
awsProperties.glueCatalogSkipNameValidation()))
+        .tableType(GlueTableOperations.GLUE_EXTERNAL_TABLE_TYPE)
+        .parameters(tableParameters)
+        .build();
+
+    try {
+      glue.createTable(CreateTableRequest.builder()
+          .databaseName(IcebergToGlueConverter.getDatabaseName(identifier,
+              awsProperties.glueCatalogSkipNameValidation()))
+          .tableInput(tableInput)
+          .build());
+    } catch (software.amazon.awssdk.services.glue.model.AlreadyExistsException 
e) {
+      glue.updateTable(UpdateTableRequest.builder()
+          .databaseName(IcebergToGlueConverter.getDatabaseName(identifier,
+              awsProperties.glueCatalogSkipNameValidation()))
+          .tableInput(tableInput)
+          .build());

Review Comment:
   I think glue catalog already handle this internally?
   
   If we call glue.getTable to get the table version first then call 
glue.updateTable with nextVersionId it will cause 
concurrentModificationException.



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