diff --git a/core/src/main/java/org/apache/iceberg/LocationProviders.java b/core/src/main/java/org/apache/iceberg/LocationProviders.java index 56dce3fad79e..33e411791125 100644 --- a/core/src/main/java/org/apache/iceberg/LocationProviders.java +++ b/core/src/main/java/org/apache/iceberg/LocationProviders.java @@ -68,13 +68,15 @@ public static LocationProvider locationsFor(String location, Map } } + private static String defaultDataLocation(String tableLocation, Map properties) { + return properties.getOrDefault(TableProperties.WRITE_NEW_DATA_LOCATION, String.format("%s/data", tableLocation)); + } + static class DefaultLocationProvider implements LocationProvider { private final String dataLocation; DefaultLocationProvider(String tableLocation, Map properties) { - this.dataLocation = stripTrailingSlash(properties.getOrDefault( - TableProperties.WRITE_NEW_DATA_LOCATION, - String.format("%s/data", tableLocation))); + this.dataLocation = stripTrailingSlash(defaultDataLocation(tableLocation, properties)); } @Override @@ -96,7 +98,8 @@ static class ObjectStoreLocationProvider implements LocationProvider { private final String context; ObjectStoreLocationProvider(String tableLocation, Map properties) { - this.storageLocation = stripTrailingSlash(properties.get(OBJECT_STORE_PATH)); + this.storageLocation = stripTrailingSlash(properties.getOrDefault(OBJECT_STORE_PATH, + defaultDataLocation(tableLocation, properties))); this.context = pathContext(tableLocation); } diff --git a/core/src/test/java/org/apache/iceberg/TestLocationProvider.java b/core/src/test/java/org/apache/iceberg/TestLocationProvider.java index a07407f0dadc..bbbb65b22ebc 100644 --- a/core/src/test/java/org/apache/iceberg/TestLocationProvider.java +++ b/core/src/test/java/org/apache/iceberg/TestLocationProvider.java @@ -212,4 +212,30 @@ public void testInvalidArgTypesDynamicallyLoadedLocationProvider() { () -> table.locationProvider() ); } + + @Test + public void testObjectStorageLocationProviderPathResolution() { + table.updateProperties() + .set(TableProperties.OBJECT_STORE_ENABLED, "true") + .commit(); + + Assert.assertTrue("default data location should be used when object storage path not set", + table.locationProvider().newDataLocation("file").contains(table.location() + "/data")); + + String folderPath = "s3://random/folder/location"; + table.updateProperties() + .set(TableProperties.WRITE_NEW_DATA_LOCATION, folderPath) + .commit(); + + Assert.assertTrue("folder storage path should be used when set", + table.locationProvider().newDataLocation("file").contains(folderPath)); + + String objectPath = "s3://random/object/location"; + table.updateProperties() + .set(TableProperties.OBJECT_STORE_PATH, objectPath) + .commit(); + + Assert.assertTrue("object storage path should be used when set", + table.locationProvider().newDataLocation("file").contains(objectPath)); + } }