World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#13680] fix: accept PascalCase ExistOk as a Lance create mode (#13681)
Burak Kalaycıd429c341b54a
diff --git a/docs/lance-rest-service.md b/docs/lance-rest-service.mdindex f8c6ed5b89..7ca123d86e 100644--- a/docs/lance-rest-service.md+++ b/docs/lance-rest-service.md@@ -88,8 +88,9 @@ More details, refer to the [Lance REST API specification](https://lance.org/formSome operations have specific behaviors and modes. Below are important details to consider:-Mode values are parsed case-insensitively. The examples below use lowercase values as the-REST-style canonical form.+Mode values are parsed case-insensitively. The underscore-free PascalCase spelling `ExistOk`+is accepted as `exist_ok`. The examples below use lowercase snake_case as the REST-style+canonical form.#### Namespace Operationsdiff --git a/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/CommonUtil.java b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/CommonUtil.javaindex 76b5593995..2c7f628a7c 100644--- a/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/CommonUtil.java+++ b/lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/CommonUtil.java@@ -37,13 +37,28 @@ public class CommonUtil {** <p>Authorization relies on this: a mode that reaches the operation as {@code OVERWRITE} has to* be recognized as an overwrite while the request is being authorized, whatever spacing or case- * the client sent.+ * the client sent. A single-word token is not split on internal capitals, so {@code OverWrite}+ * stays {@code OVERWRITE}.+ *+ * <p>{@code ExistOk} is the only multi-word token in the Lance mode vocabulary. The PascalCase+ * form and the underscore-free form are accepted as {@code EXIST_OK}, matching snake_case {@code+ * exist_ok}.** @param value the raw token, may be null- * @return the trimmed, upper-cased token, or an empty string when the value is null+ * @return the trimmed, upper-cased token, with {@code ExistOk} mapped to {@code EXIST_OK}, or an+ * empty string when the value is null*/public static String normalizeToken(String value) {- return value == null ? "" : value.trim().toUpperCase(Locale.ROOT);+ if (value == null) {+ return "";+ }+ String normalized = value.trim().toUpperCase(Locale.ROOT);+ // Only ExistOk is multi-word. Splitting every capital would turn OverWrite into OVER_WRITE+ // and authorization would no longer recognize an overwrite.+ if ("EXISTOK".equals(normalized)) {+ return "EXIST_OK";+ }+ return normalized;}static <E extends Enum<E>> E parseEnumToken(diff --git a/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestGravitinoLanceModeParsing.java b/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestGravitinoLanceModeParsing.javaindex f2c390add5..ee144208a2 100644--- a/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestGravitinoLanceModeParsing.java+++ b/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestGravitinoLanceModeParsing.java@@ -56,14 +56,26 @@ class TestGravitinoLanceModeParsing {void testNormalizeTokenPreservesSpecialCharacters() {Assertions.assertEquals("CREATE", CommonUtil.normalizeToken(" create "));Assertions.assertEquals("EXIST_OK", CommonUtil.normalizeToken("exist_ok"));+ Assertions.assertEquals("OVERWRITE", CommonUtil.normalizeToken(" OverWrite "));Assertions.assertEquals("#CREATE$", CommonUtil.normalizeToken("#create$"));}+ @Test+ void testNormalizeTokenMapsPascalCaseExistOk() {+ Assertions.assertEquals("EXIST_OK", CommonUtil.normalizeToken("ExistOk"));+ Assertions.assertEquals("EXIST_OK", CommonUtil.normalizeToken(" ExistOk "));+ Assertions.assertEquals("EXIST_OK", CommonUtil.normalizeToken("existOk"));+ Assertions.assertEquals("EXIST_OK", CommonUtil.normalizeToken("EXISTOK"));+ }+@Testvoid testParseEnumTokenRejectsMalformedValues() {Assertions.assertEquals(TestMode.EXIST_OK,CommonUtil.parseEnumToken(TestMode.class, "exist_ok", "Unknown mode: ", "table"));+ Assertions.assertEquals(+ TestMode.EXIST_OK,+ CommonUtil.parseEnumToken(TestMode.class, "ExistOk", "Unknown mode: ", "table"));InvalidInputException exception =Assertions.assertThrows(@@ -111,12 +123,16 @@ class TestGravitinoLanceModeParsing {GravitinoLanceTableOperations operations = newTableOperations(tableCatalog);operations.createTable("catalog.schema.table", " exist_ok ", ".", null, Map.of(), null);+ operations.createTable("catalog.schema.table", "ExistOk", ".", null, Map.of(), null);ArgumentCaptor<Map<String, String>> propertiesCaptor = propertiesCaptor();- Mockito.verify(tableCatalog)+ Mockito.verify(tableCatalog, Mockito.times(2)).createTable(any(NameIdentifier.class), any(Column[].class), isNull(), propertiesCaptor.capture());- Assertions.assertEquals("EXIST_OK", propertiesCaptor.getValue().get(LANCE_CREATION_MODE));+ Assertions.assertEquals(+ "EXIST_OK", propertiesCaptor.getAllValues().get(0).get(LANCE_CREATION_MODE));+ Assertions.assertEquals(+ "EXIST_OK", propertiesCaptor.getAllValues().get(1).get(LANCE_CREATION_MODE));}@Test