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 895f6a770a [#8034] Improvement: Fully support nullable simpleStrings 
in Types.java (#8092)
895f6a770a is described below

commit 895f6a770ab04a1c52e8379f0e255a0ecdbf928b
Author: Ratnesh Rastogi <[email protected]>
AuthorDate: Fri Aug 15 08:00:10 2025 +0530

    [#8034] Improvement: Fully support nullable simpleStrings in Types.java 
(#8092)
    
    ### What changes were proposed in this pull request?
    
    This PR adds full support for nullable simpleStrings in
    `api/src/main/java/org/apache/gravitino/rel/types/Types.java`. More
    specifically, for the `simpleString()` method for the complex type
    `MapType`.
    Additionally, a couple of unit tests are added to cover the cases where
    `MapType` and `ListType` can have non-nullable fields in them.
    
    ### Why are the changes needed?
    
    It is important to indicate (in the human readable `simpleString()`
    output) whether an instantiated complex type like the `MapType` can or
    cannot have null values for its elements. In code, this is indicated by
    a `valueNullable` boolean field.
    For example, a `MapType` which maps each `IntegerType` to a `StringType`
    might not want to allow an `IntegerType->Null` mapping. In that case, a
    call to the `simpleString()` method should return the following string
    `map<integer,string, NOT NULL>` to indicate this behavior.
    
    
    Fix: #8034
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Locally, with the provided unit test in the original issue post.
    Additionally, since `ListType` also allows for a similar non-null
    behavior as indicated by the code, I've decided to add a test to cover
    it as well.
    Since the other two complex types either do not exhibit the behavior (in
    case of `UnionType`) or already have the behavior covered in a test (in
    case of `StructType`), no additional tests were added for the other
    complex types.
---
 .../main/java/org/apache/gravitino/rel/types/Types.java |  4 +++-
 .../test/java/org/apache/gravitino/rel/TestTypes.java   | 17 +++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/api/src/main/java/org/apache/gravitino/rel/types/Types.java 
b/api/src/main/java/org/apache/gravitino/rel/types/Types.java
index 61520f4220..8b7b78895d 100644
--- a/api/src/main/java/org/apache/gravitino/rel/types/Types.java
+++ b/api/src/main/java/org/apache/gravitino/rel/types/Types.java
@@ -1096,7 +1096,9 @@ public class Types {
 
     @Override
     public String simpleString() {
-      return "map<" + keyType.simpleString() + "," + valueType.simpleString() 
+ ">";
+      return valueNullable
+          ? "map<" + keyType.simpleString() + "," + valueType.simpleString() + 
">"
+          : "map<" + keyType.simpleString() + "," + valueType.simpleString() + 
", NOT NULL>";
     }
 
     @Override
diff --git a/api/src/test/java/org/apache/gravitino/rel/TestTypes.java 
b/api/src/test/java/org/apache/gravitino/rel/TestTypes.java
index ddf70541f0..75da38db6e 100644
--- a/api/src/test/java/org/apache/gravitino/rel/TestTypes.java
+++ b/api/src/test/java/org/apache/gravitino/rel/TestTypes.java
@@ -202,6 +202,13 @@ public class TestTypes {
     Assertions.assertEquals("list<integer>", listType.simpleString());
     Assertions.assertEquals(listType, 
Types.ListType.nullable(Types.IntegerType.get()));
 
+    Types.ListType listTypeNotNull = 
Types.ListType.notNull(Types.StringType.get());
+    Assertions.assertEquals(Type.Name.LIST, listTypeNotNull.name());
+    Assertions.assertFalse(listTypeNotNull.elementNullable());
+    Assertions.assertEquals(Types.StringType.get(), 
listTypeNotNull.elementType());
+    Assertions.assertEquals("list<string, NOT NULL>", 
listTypeNotNull.simpleString());
+    Assertions.assertEquals(listTypeNotNull, 
Types.ListType.notNull(Types.StringType.get()));
+
     Types.MapType mapType =
         Types.MapType.valueNullable(Types.IntegerType.get(), 
Types.StringType.get());
     Assertions.assertEquals(Type.Name.MAP, mapType.name());
@@ -211,6 +218,16 @@ public class TestTypes {
     Assertions.assertEquals(
         mapType, Types.MapType.valueNullable(Types.IntegerType.get(), 
Types.StringType.get()));
 
+    Types.MapType mapTypeNotNull =
+        Types.MapType.valueNotNull(Types.IntegerType.get(), 
Types.StringType.get());
+    Assertions.assertEquals(Type.Name.MAP, mapTypeNotNull.name());
+    Assertions.assertEquals(Types.IntegerType.get(), mapTypeNotNull.keyType());
+    Assertions.assertEquals(Types.StringType.get(), 
mapTypeNotNull.valueType());
+    Assertions.assertEquals("map<integer,string, NOT NULL>", 
mapTypeNotNull.simpleString());
+    Assertions.assertEquals(
+        mapTypeNotNull,
+        Types.MapType.valueNotNull(Types.IntegerType.get(), 
Types.StringType.get()));
+
     Types.UnionType unionType =
         Types.UnionType.of(
             Types.IntegerType.get(), Types.StringType.get(), 
Types.BooleanType.get());

Reply via email to