This is an automated email from the ASF dual-hosted git repository.
emaynard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new adcf160a Fix: check for slashless metadata paths (#968)
adcf160a is described below
commit adcf160acff099279fc215a034ce3c03c10a2744
Author: Richard Liu <[email protected]>
AuthorDate: Mon Feb 17 10:19:58 2025 -0800
Fix: check for slashless metadata paths (#968)
* add check for slashless metadata paths
* update error message
---
.../polaris/service/quarkus/catalog/BasePolarisCatalogTest.java | 9 +++++++++
.../org/apache/polaris/service/catalog/BasePolarisCatalog.java | 8 +++++++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git
a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java
b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java
index 97741176..821126ab 100644
---
a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java
+++
b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java
@@ -1583,4 +1583,13 @@ public class BasePolarisCatalogTest extends
CatalogTests<BasePolarisCatalog> {
handler.handleTask(taskEntity, realmContext);
Assertions.assertThat(measured.getNumDeletedFiles()).as("A table was
deleted").isGreaterThan(0);
}
+
+ @Test
+ public void testRegisterTableWithSlashlessMetadataLocation() {
+ BasePolarisCatalog catalog = catalog();
+ Assertions.assertThatThrownBy(
+ () -> catalog.registerTable(TABLE,
"metadata_location_without_slashes"))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("Invalid metadata file location");
+ }
}
diff --git
a/service/common/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java
b/service/common/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java
index 743749bc..59f16cc8 100644
---
a/service/common/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java
+++
b/service/common/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java
@@ -309,12 +309,18 @@ public class BasePolarisCatalog extends
BaseMetastoreViewCatalog
metadataFileLocation != null && !metadataFileLocation.isEmpty(),
"Cannot register an empty metadata file location as a table");
+ int lastSlashIndex = metadataFileLocation.lastIndexOf("/");
+ Preconditions.checkArgument(
+ lastSlashIndex != -1,
+ "Invalid metadata file location; metadata file location must be
absolute and contain a '/': %s",
+ metadataFileLocation);
+
// Throw an exception if this table already exists in the catalog.
if (tableExists(identifier)) {
throw new AlreadyExistsException("Table already exists: %s", identifier);
}
- String locationDir = metadataFileLocation.substring(0,
metadataFileLocation.lastIndexOf("/"));
+ String locationDir = metadataFileLocation.substring(0, lastSlashIndex);
TableOperations ops = newTableOps(identifier);