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:25 UTC
[orc] branch main 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 main
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/main by this push:
new fbcbac57d ORC-1228: Fix `setAttribute` to handle null value
fbcbac57d is described below
commit fbcbac57dc1297616b2ce2c61998b83ae25eae6e
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>
---
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());
}
}