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 4ceea55014 [#8301] Improvement: Improve ParseType.parseBasicType so it 
accepts whitespace around numeric parameters (#8328)
4ceea55014 is described below

commit 4ceea55014d14099e72fa1cadac0685b4b17b49c
Author: MaAng <[email protected]>
AuthorDate: Thu Aug 28 17:24:07 2025 +0800

    [#8301] Improvement: Improve ParseType.parseBasicType so it accepts 
whitespace around numeric parameters (#8328)
    
    ### What changes were proposed in this pull request?
    Enhance Regex expression in ParseType.parseBasicType.
    Add `\s*` in regex exp so it will handle the whitespace.
    
    ### Why are the changes needed?
    
    It will throw IllegalArgumentException when type contains whiteSpace.
    
    Fix: #8301
    
    ### Does this PR introduce _any_ user-facing change?
    NO
    ### How was this patch tested?
    
    UT added.
---
 .../src/main/java/org/apache/gravitino/cli/ParseType.java |  2 +-
 .../test/java/org/apache/gravitino/cli/TestParseType.java | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

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 afeb924653..ee6bf3e079 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
@@ -38,7 +38,7 @@ public class ParseType {
    * @throws IllegalArgumentException if the data type format is unsupported 
or malformed
    */
   public static ParsedType parseBasicType(String datatype) {
-    Pattern pattern = Pattern.compile("^(\\w+)\\((\\d+)(?:,(\\d+))?\\)$");
+    Pattern pattern = 
Pattern.compile("^(\\w+)\\(\\s*(\\d+)\\s*(?:,\\s*(\\d+)\\s*)?\\)$");
     Matcher matcher = pattern.matcher(datatype);
 
     if (matcher.matches()) {
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 7587f85aef..c4ceac0a25 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
@@ -140,4 +140,19 @@ public class TestParseType {
     Type elementType = ((Types.ListType) valueType).elementType();
     assertThat(elementType, instanceOf(Types.IntegerType.class));
   }
+
+  @Test
+  public void testParseTypeDecimalWithSpaces() {
+    Type type = ParseType.toType("decimal(10, 5)");
+    assertThat(type, instanceOf(Types.DecimalType.class));
+    assertEquals(10, ((Types.DecimalType) type).precision());
+    assertEquals(5, ((Types.DecimalType) type).scale());
+  }
+
+  @Test
+  public void testParseTypeVarcharWithSpaces() {
+    Type type = ParseType.toType("varchar( 10 )");
+    assertThat(type, instanceOf(Types.VarCharType.class));
+    assertEquals(10, ((Types.VarCharType) type).length());
+  }
 }

Reply via email to