You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "dramaticlly (via GitHub)" <gi...@apache.org> on 2023/08/02 22:24:39 UTC

[GitHub] [iceberg] dramaticlly commented on a diff in pull request #8194: Core: check table location for uniqueness before creation

dramaticlly commented on code in PR #8194:
URL: https://github.com/apache/iceberg/pull/8194#discussion_r1282471881


##########
core/src/main/java/org/apache/iceberg/BaseMetastoreCatalog.java:
##########
@@ -192,6 +192,14 @@ public Table create() {
 
       String baseLocation = location != null ? location : defaultWarehouseLocation(identifier);
       tableProperties.putAll(tableOverrideProperties());
+
+      if (Boolean.parseBoolean(tableProperties.get(TableProperties.UNIQUE_LOCATION))) {
+        boolean alreadyExists = ops.io().newInputFile(baseLocation).exists();
+        if (alreadyExists) {
+          throw new AlreadyExistsException("Table location already in use: %s", baseLocation);

Review Comment:
   thank you @RussellSpitzer for your feedback. I totally agree that checking for directory or location is empty would be awesome, but based on the methods available in [FileIO](https://github.com/apache/iceberg/blob/master/api/src/main/java/org/apache/iceberg/io/FileIO.java). I dont find anything useful for that purpose. The closest one I get is [SupportsPrefixOperations::listPrefix](https://github.com/apache/iceberg/blob/master/api/src/main/java/org/apache/iceberg/io/SupportsPrefixOperations.java#L36) which is subclass of fileIO. 
   
   Do you think it make sense for us to do conditional check based on io?
   
   ```java
   boolean alreadyExists =
     (ops.io() instanceof SupportsPrefixOperations) ?
         Iterables.isEmpty(
             ((SupportsPrefixOperations) ops.io()).listPrefix(baseLocation)
         )
         : ops.io().newInputFile(baseLocation).exists();
   ```



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org