This is an automated email from the ASF dual-hosted git repository.
jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 5178f5c72f [#8159] improvement(cli): Use toType() instead of
toBasicType() for support more complex types (#8227)
5178f5c72f is described below
commit 5178f5c72fda7577468215f47ec3399ad58cb976
Author: keepConcentration <[email protected]>
AuthorDate: Thu Aug 21 09:01:17 2025 +0900
[#8159] improvement(cli): Use toType() instead of toBasicType() for support
more complex types (#8227)
### What changes were proposed in this pull request?
This PR updates the `ParseType` class to support parsing of nested
complex types (e.g. `list(list(integer))`, `map(string,list(integer))`).
### Why are the changes needed?
Currently, the CLI only supports simple types or single-level
lists/maps.
It fails for more complex definitions like `list(list(integer))` or
`map(string,list(integer))`.
Fix: #8159
### Does this PR introduce _any_ user-facing change?
Users can now define more complex schemas in the CLI, such as:
- `list(list(integer))`
- `map(string,list(integer))`
### How was this patch tested?
- Added new unit tests:
- `testParseTypeNestedList`
- `testParseTypeMapWithNestedValue`
- Executed existing unit tests
---
.../java/org/apache/gravitino/cli/ParseType.java | 6 +++---
.../org/apache/gravitino/cli/TestParseType.java | 22 ++++++++++++++++++++++
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/ParseType.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/ParseType.java
index caa62807af..afeb924653 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/ParseType.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/ParseType.java
@@ -76,7 +76,7 @@ public class ParseType {
Pattern pattern = Pattern.compile("^list\\s*\\(\\s*(.+?)\\s*\\)$");
Matcher matcher = pattern.matcher(datatype);
if (matcher.matches()) {
- Type elementType = toBasicType(matcher.group(1).trim());
+ Type elementType = toType(matcher.group(1).trim());
return Types.ListType.of(elementType, false);
}
throw new IllegalArgumentException("Malformed list type: " + datatype);
@@ -86,8 +86,8 @@ public class ParseType {
Pattern pattern =
Pattern.compile("^map\\s*\\(\\s*(.+?)\\s*,\\s*(.+?)\\s*\\)$");
Matcher matcher = pattern.matcher(datatype);
if (matcher.matches()) {
- Type keyType = toBasicType(matcher.group(1).trim());
- Type valueType = toBasicType(matcher.group(2).trim());
+ Type keyType = toType(matcher.group(1).trim());
+ Type valueType = toType(matcher.group(2).trim());
return Types.MapType.of(keyType, valueType, false);
}
throw new IllegalArgumentException("Malformed map type: " + datatype);
diff --git
a/clients/cli/src/test/java/org/apache/gravitino/cli/TestParseType.java
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestParseType.java
index 7b8d504c11..7587f85aef 100644
--- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestParseType.java
+++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestParseType.java
@@ -118,4 +118,26 @@ public class TestParseType {
assertThat(keyType, instanceOf(Types.StringType.class));
assertThat(valueType, instanceOf(Types.IntegerType.class));
}
+
+ @Test
+ public void testParseTypeNestedList() {
+ Type type = ParseType.toType("list(list(integer))");
+ assertThat(type, instanceOf(Types.ListType.class));
+ Type innerList = ((Types.ListType) type).elementType();
+ assertThat(innerList, instanceOf(Types.ListType.class));
+ Type elementType = ((Types.ListType) innerList).elementType();
+ assertThat(elementType, instanceOf(Types.IntegerType.class));
+ }
+
+ @Test
+ public void testParseTypeMapWithNestedValue() {
+ Type type = ParseType.toType("map(string,list(integer))");
+ assertThat(type, instanceOf(Types.MapType.class));
+ Type keyType = ((Types.MapType) type).keyType();
+ Type valueType = ((Types.MapType) type).valueType();
+ assertThat(keyType, instanceOf(Types.StringType.class));
+ assertThat(valueType, instanceOf(Types.ListType.class));
+ Type elementType = ((Types.ListType) valueType).elementType();
+ assertThat(elementType, instanceOf(Types.IntegerType.class));
+ }
}