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 7dc0a0e41d [#7707] Improvement(client-cli): Fix the parsing of 
whitespace correctly in list and map types in the CLI. (#7756)
7dc0a0e41d is described below

commit 7dc0a0e41d536bdfddffe807f1c51d88ad132bd6
Author: Reuben George <[email protected]>
AuthorDate: Mon Jul 21 04:56:21 2025 +0530

    [#7707] Improvement(client-cli): Fix the parsing of whitespace correctly in 
list and map types in the CLI. (#7756)
    
    ### What changes were proposed in this pull request?
    Fix the parsing of whitespace correctly in list and map types in the
    CLI.
    
    ### Why are the changes needed?
    Fix: #7707
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    Added a unit test
---
 .../main/java/org/apache/gravitino/cli/ParseType.java  | 10 +++++-----
 .../java/org/apache/gravitino/cli/TestParseType.java   | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 5 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 9442175ef8..caa62807af 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
@@ -73,21 +73,21 @@ public class ParseType {
   }
 
   private static Type toListType(String datatype) {
-    Pattern pattern = Pattern.compile("^list\\((.+)\\)$");
+    Pattern pattern = Pattern.compile("^list\\s*\\(\\s*(.+?)\\s*\\)$");
     Matcher matcher = pattern.matcher(datatype);
     if (matcher.matches()) {
-      Type elementType = toBasicType(matcher.group(1));
+      Type elementType = toBasicType(matcher.group(1).trim());
       return Types.ListType.of(elementType, false);
     }
     throw new IllegalArgumentException("Malformed list type: " + datatype);
   }
 
   private static Type toMapType(String datatype) {
-    Pattern pattern = Pattern.compile("^map\\((.+),(.+)\\)$");
+    Pattern pattern = 
Pattern.compile("^map\\s*\\(\\s*(.+?)\\s*,\\s*(.+?)\\s*\\)$");
     Matcher matcher = pattern.matcher(datatype);
     if (matcher.matches()) {
-      Type keyType = toBasicType(matcher.group(1));
-      Type valueType = toBasicType(matcher.group(2));
+      Type keyType = toBasicType(matcher.group(1).trim());
+      Type valueType = toBasicType(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 6c9132dbf4..7b8d504c11 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
@@ -100,4 +100,22 @@ public class TestParseType {
     assertThrows(IllegalArgumentException.class, () -> 
ParseType.toType("varchar(-10)"));
     assertThrows(IllegalArgumentException.class, () -> 
ParseType.toType("decimal(10,abc)"));
   }
+
+  @Test
+  public void testParseTypeListWithSpaces() {
+    Type type = ParseType.toType("list( integer )");
+    assertThat(type, instanceOf(Types.ListType.class));
+    Type elementType = ((Types.ListType) type).elementType();
+    assertThat(elementType, instanceOf(Types.IntegerType.class));
+  }
+
+  @Test
+  public void testParseTypeMapWithSpaces() {
+    Type type = ParseType.toType("map( string , 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.IntegerType.class));
+  }
 }

Reply via email to