You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by wi...@apache.org on 2022/07/26 05:36:38 UTC

[orc] branch branch-1.8 updated: ORC-1228: Fix `setAttribute` to handle null value

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

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


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

commit 457fc3cd67088b9b2cd3462402530f7e5c3928af
Author: William Hyun <wi...@apache.org>
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 <wi...@apache.org>
    Signed-off-by: William Hyun <wi...@apache.org>
    (cherry picked from commit fbcbac57dc1297616b2ce2c61998b83ae25eae6e)
    Signed-off-by: William Hyun <wi...@apache.org>
---
 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 b5ef97c87..5f2e0808c 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());
   }
 }