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 <[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]>
---
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());
}
}