rdblue commented on code in PR #4946:
URL: https://github.com/apache/iceberg/pull/4946#discussion_r889718763


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java:
##########
@@ -246,11 +246,26 @@ public org.apache.iceberg.Table 
registerTable(TableIdentifier identifier, String
     TableOperations ops = newTableOps(identifier);
     InputFile metadataFile = fileIO.newInputFile(metadataFileLocation);
     TableMetadata metadata = TableMetadataParser.read(ops.io(), metadataFile);
+
+    if (!isMetastoreTable(metadataFileLocation)) {
+      // Metastore table and filesystem tables will have different naming 
conventions as per the spec.
+      // So, to support importing filesystem tables to metastore catalog,
+      // create a new metadata file with contents of filesystem table but with 
a metastore table naming convention.
+      BaseMetastoreTableOperations baseOps = (BaseMetastoreTableOperations) 
ops;
+      String newFileName = baseOps.writeNewMetadata(metadata, 
baseOps.currentVersion() + 1);
+      metadataFile = fileIO.newInputFile(newFileName);
+      metadata = TableMetadataParser.read(ops.io(), metadataFile);
+    }
+
     ops.commit(null, metadata);
 
     return new BaseTable(ops, identifier.toString());
   }
 
+  private boolean isMetastoreTable(String metadataFileLocation) {
+    return 
metadataFileLocation.substring(metadataFileLocation.lastIndexOf("/") + 
1).contains("-");

Review Comment:
   I think this should be more specific. Why not confirm that there's a number 
using a regex?



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