krvikash commented on code in PR #6512:
URL: https://github.com/apache/iceberg/pull/6512#discussion_r1065103623
##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -351,7 +354,35 @@ public void invalidateTable(SessionContext context,
TableIdentifier ident) {}
@Override
public Table registerTable(
SessionContext context, TableIdentifier ident, String
metadataFileLocation) {
- throw new UnsupportedOperationException("Register table is not supported");
+ Preconditions.checkArgument(
+ ident != null && isValidIdentifier(ident), "Invalid identifier: %s",
ident);
+ Preconditions.checkArgument(
+ metadataFileLocation != null && !metadataFileLocation.isEmpty(),
+ "Cannot register an empty metadata file location as a table");
+
+ // Throw an exception if this table already exists in the catalog.
+ if (tableExists(context, ident)) {
+ throw new AlreadyExistsException("Table already exists: %s", ident);
+ }
+
+ TableMetadata metadata = TableMetadataParser.read(io,
metadataFileLocation);
+ Map<String, String> tableProperties =
+ ImmutableMap.<String, String>builder()
+ .putAll(metadata.properties())
+ .put(BaseMetastoreTableOperations.METADATA_LOCATION_PROP,
metadataFileLocation)
+ .build();
+
+ return buildTable(context, ident, metadata.schema())
+ .withLocation(metadata.location())
+ .withProperties(tableProperties)
+ .withPartitionSpec(metadata.spec())
+ .withSortOrder(metadata.sortOrder())
+ .create();
+ }
+
+ private boolean isValidIdentifier(TableIdentifier tableIdentifier) {
Review Comment:
Yes, I have copied `isValidIdentifier` from `BaseMetastoreCatalog`
implementation. Thanks for the input. I will use `checkIdentifierIsValid` over
here.
--
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]