This is an automated email from the ASF dual-hosted git repository.

william pushed a commit to branch branch-1.7
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/branch-1.7 by this push:
     new 49d922cef ORC-1228: Fix `setAttribute` to handle null value
49d922cef is described below

commit 49d922cefc7e16de44587a8b4b6d5d28d29e8c26
Author: William Hyun <[email protected]>
AuthorDate: Mon Jul 25 22:36:16 2022 -0700

    ORC-1228: Fix `setAttribute` to handle null value
    
    ### What changes were proposed in this pull request?
    This PR aims to fix `setAttribute` to handle null value.
    
    ### Why are the changes needed?
    In case of clearing the value with null, we should remove the corresponding 
key also to save memory.
    
    ### How was this patch tested?
    Pass the CIs with the new test case.
    
    Closes #1196 from williamhyun/setattributenull.
    
    Authored-by: William Hyun <[email protected]>
    Signed-off-by: William Hyun <[email protected]>
    (cherry picked from commit fbcbac57dc1297616b2ce2c61998b83ae25eae6e)
    Signed-off-by: William Hyun <[email protected]>
---
 java/core/src/java/org/apache/orc/TypeDescription.java     | 6 +++++-
 java/core/src/test/org/apache/orc/TestTypeDescription.java | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/java/core/src/java/org/apache/orc/TypeDescription.java 
b/java/core/src/java/org/apache/orc/TypeDescription.java
index 7b20a0e78..a94a15488 100644
--- a/java/core/src/java/org/apache/orc/TypeDescription.java
+++ b/java/core/src/java/org/apache/orc/TypeDescription.java
@@ -247,7 +247,11 @@ public class TypeDescription
    */
   public TypeDescription setAttribute(@NotNull String key,
                                       String value) {
-    attributes.put(key, value);
+    if (value == null) {
+      attributes.remove(key);
+    } else {
+      attributes.put(key, value);
+    }
     return this;
   }
 
diff --git a/java/core/src/test/org/apache/orc/TestTypeDescription.java 
b/java/core/src/test/org/apache/orc/TestTypeDescription.java
index 5f16742c6..4129419e0 100644
--- a/java/core/src/test/org/apache/orc/TestTypeDescription.java
+++ b/java/core/src/test/org/apache/orc/TestTypeDescription.java
@@ -514,5 +514,7 @@ public class TestTypeDescription {
   public void testSetAttribute() {
     TypeDescription type = TypeDescription.fromString("int");
     type.setAttribute("key1", null);
+
+    assertEquals(0, type.getAttributeNames().size());
   }
 }

Reply via email to