World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#8037] improvement(validateFieldExistence): throw exception if nested fieldName in validateFieldExistence (#8075)
Sambhavi Pandeyfa39be02c242
diff --git a/common/src/main/java/org/apache/gravitino/dto/rel/PartitionUtils.java b/common/src/main/java/org/apache/gravitino/dto/rel/PartitionUtils.javaindex e7655d45fe..a9aa5bf3a9 100644--- a/common/src/main/java/org/apache/gravitino/dto/rel/PartitionUtils.java+++ b/common/src/main/java/org/apache/gravitino/dto/rel/PartitionUtils.java@@ -41,10 +41,16 @@ public class PartitionUtils {Preconditions.checkArgument(ArrayUtils.isNotEmpty(fieldName), "fieldName cannot be null or empty");+ // Check if nested fields are supported (currently not supported)+ Preconditions.checkArgument(+ fieldName.length == 1,+ "Nested fields are not supported yet. Field name array must contain exactly one element, but got: %s",+ Arrays.toString(fieldName));+List<ColumnDTO> partitionColumn =Arrays.stream(columns)// (TODO) Need to consider the case sensitivity issues.- // To be optimized.+ // To be optimized..filter(c -> c.name().equalsIgnoreCase(fieldName[0])).collect(Collectors.toList());Preconditions.checkArgument(diff --git a/common/src/test/java/org/apache/gravitino/dto/rel/TestPartitionUtils.java b/common/src/test/java/org/apache/gravitino/dto/rel/TestPartitionUtils.javaindex 840cfd7bbf..618e1f4d58 100644--- a/common/src/test/java/org/apache/gravitino/dto/rel/TestPartitionUtils.java+++ b/common/src/test/java/org/apache/gravitino/dto/rel/TestPartitionUtils.java@@ -72,4 +72,60 @@ public class TestPartitionUtils {() -> PartitionUtils.validateFieldExistence(columns, new String[] {"c"}));Assertions.assertEquals("Field 'c' not found in table", ex.getMessage());}++ @Test+ void testValidateFieldExistence_nestedFieldsNotSupported() {+ ColumnDTO[] columns = new ColumnDTO[] {column("a"), column("b")};+ IllegalArgumentException ex =+ Assertions.assertThrows(+ IllegalArgumentException.class,+ () -> PartitionUtils.validateFieldExistence(columns, new String[] {"a", "b"}));+ Assertions.assertEquals(+ "Nested fields are not supported yet. Field name array must contain exactly one element, but got: [a, b]",+ ex.getMessage());+ }++ @Test+ void testValidateFieldExistence_singleElementArray() {+ ColumnDTO[] columns = new ColumnDTO[] {column("a"), column("b")};+ String[] field = new String[] {"a"};++ Assertions.assertDoesNotThrow(() -> PartitionUtils.validateFieldExistence(columns, field));+ }++ @Test+ void testValidateFieldExistence_multipleNestedFieldsNotSupported() {+ ColumnDTO[] columns = new ColumnDTO[] {column("a"), column("b")};+ IllegalArgumentException ex =+ Assertions.assertThrows(+ IllegalArgumentException.class,+ () -> PartitionUtils.validateFieldExistence(columns, new String[] {"a", "b", "c"}));+ Assertions.assertEquals(+ "Nested fields are not supported yet. Field name array must contain exactly one element, but got: [a, b, c]",+ ex.getMessage());+ }++ @Test+ void testValidateFieldExistence_emptyFieldNameArray() {+ ColumnDTO[] columns = new ColumnDTO[] {column("a"), column("b")};+ IllegalArgumentException ex =+ Assertions.assertThrows(+ IllegalArgumentException.class,+ () -> PartitionUtils.validateFieldExistence(columns, new String[] {}));+ Assertions.assertEquals("fieldName cannot be null or empty", ex.getMessage());+ }++ @Test+ void testValidateFieldExistence_nestedFieldValidationOrder() {+ ColumnDTO[] columns = new ColumnDTO[] {column("a"), column("b")};+ IllegalArgumentException ex =+ Assertions.assertThrows(+ IllegalArgumentException.class,+ () ->+ PartitionUtils.validateFieldExistence(+ columns, new String[] {"nonexistent", "field"}));+ Assertions.assertEquals(+ "Nested fields are not supported yet. Field name array must contain exactly one element, but got: [nonexistent, field]",+ ex.getMessage());+ }}