You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by do...@apache.org on 2021/08/16 21:45:41 UTC

[orc] branch main updated: ORC-837: Reuse HiveDecimalWritable in ConvertTreeReaderFactory (#742)

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

dongjoon 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 18a2be6  ORC-837: Reuse HiveDecimalWritable in ConvertTreeReaderFactory (#742)
18a2be6 is described below

commit 18a2be61ba11ab20a5e88b719cb9af7af200e00e
Author: belugabehr <12...@users.noreply.github.com>
AuthorDate: Mon Aug 16 17:45:36 2021 -0400

    ORC-837: Reuse HiveDecimalWritable in ConvertTreeReaderFactory (#742)
    
    ### What changes were proposed in this pull request?
    Create reusable HiveDecimalWritable objects instead of creating a new HiveDecimalWritable for each processed item.
    
    ### Why are the changes needed?
    Performance, less garbage collection
    
    ### How was this patch tested?
    No change in functionality. Use existing unit tests.
---
 .../apache/orc/impl/ConvertTreeReaderFactory.java  | 24 ++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java b/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java
index e15011f..d78aa43 100644
--- a/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java
+++ b/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java
@@ -818,21 +818,23 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
   public static class DecimalFromAnyIntegerTreeReader extends ConvertTreeReader {
     private LongColumnVector longColVector;
     private ColumnVector decimalColVector;
+    private final HiveDecimalWritable value;
 
     DecimalFromAnyIntegerTreeReader(int columnId, TypeDescription fileType, Context context)
         throws IOException {
       super(columnId, createFromInteger(columnId, fileType, context), context);
+      value = new HiveDecimalWritable();
     }
 
     @Override
     public void setConvertVectorElement(int elementNum) {
       long longValue = longColVector.vector[elementNum];
-      HiveDecimalWritable hiveDecimalWritable = new HiveDecimalWritable(longValue);
+      this.value.setFromLong(longValue);
       // The DecimalColumnVector will enforce precision and scale and set the entry to null when out of bounds.
       if (decimalColVector instanceof Decimal64ColumnVector) {
-        ((Decimal64ColumnVector) decimalColVector).set(elementNum, hiveDecimalWritable);
+        ((Decimal64ColumnVector) decimalColVector).set(elementNum, value);
       } else {
-        ((DecimalColumnVector) decimalColVector).set(elementNum, hiveDecimalWritable);
+        ((DecimalColumnVector) decimalColVector).set(elementNum, value);
       }
     }
 
@@ -1250,15 +1252,19 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
    * Convert a decimal to an Instant using seconds & nanos.
    * @param vector the decimal64 column vector
    * @param element the element number to use
+   * @param value the writable container to reuse
    * @return the timestamp instant
    */
-  static Instant decimalToInstant(DecimalColumnVector vector, int element) {
-    // copy the value so that we can mutate it
-    HiveDecimalWritable value = new HiveDecimalWritable(vector.vector[element]);
-    long seconds = value.longValue();
+  static Instant decimalToInstant(DecimalColumnVector vector, int element,
+      HiveDecimalWritable value) {
+    final HiveDecimalWritable writable = vector.vector[element];
+    final long seconds = writable.longValue();
+
     if (seconds < MIN_EPOCH_SECONDS || seconds > MAX_EPOCH_SECONDS) {
       return null;
     } else {
+      // copy the value so that we can mutate it
+      value.set(writable);
       value.mutateFractionPortion();
       value.mutateScaleByPowerOfTen(9);
       int nanos = (int) value.longValue();
@@ -1559,6 +1565,7 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
     private final TimeZone local;
     private final boolean useProlepticGregorian;
     private final boolean fileUsedProlepticGregorian;
+    private final HiveDecimalWritable value;
 
     TimestampFromDecimalTreeReader(int columnId, TypeDescription fileType,
                                    Context context,
@@ -1571,11 +1578,12 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
       local = TimeZone.getDefault();
       useProlepticGregorian = context.useProlepticGregorian();
       fileUsedProlepticGregorian = context.fileUsedProlepticGregorian();
+      value = new HiveDecimalWritable();
     }
 
     @Override
     public void setConvertVectorElement(int elementNum) {
-      Instant t = decimalToInstant(decimalColVector, elementNum);
+      Instant t = decimalToInstant(decimalColVector, elementNum, value);
       if (t == null) {
         timestampColVector.noNulls = false;
         timestampColVector.isNull[elementNum] = true;