You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by jc...@apache.org on 2020/03/02 20:01:54 UTC

[orc] branch master updated: ORC-595: Optimize Decimal64 scale calculation

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

jcamacho pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/master by this push:
     new ffca3ba  ORC-595: Optimize Decimal64 scale calculation
ffca3ba is described below

commit ffca3bace55ce244e4aea99490569d463acfdadf
Author: Panos Garefalakis <pg...@cloudera.com>
AuthorDate: Thu Feb 13 15:24:41 2020 +0000

    ORC-595: Optimize Decimal64 scale calculation
    
    Fixes #482
    
    Signed-off-by: Jesus Camacho Rodriguez <jc...@apache.org>
---
 .../org/apache/orc/impl/TreeReaderFactory.java     | 34 +++++++++++++++++-----
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/java/core/src/java/org/apache/orc/impl/TreeReaderFactory.java b/java/core/src/java/org/apache/orc/impl/TreeReaderFactory.java
index 8019afd..2e564d6 100644
--- a/java/core/src/java/org/apache/orc/impl/TreeReaderFactory.java
+++ b/java/core/src/java/org/apache/orc/impl/TreeReaderFactory.java
@@ -1180,6 +1180,28 @@ public class TreeReaderFactory {
     private int[] scratchScaleVector;
     private byte[] scratchBytes;
 
+    private static final long[] powerOfTenTable = {
+        1L,                   // 0
+        10L,
+        100L,
+        1_000L,
+        10_000L,
+        100_000L,
+        1_000_000L,
+        10_000_000L,
+        100_000_000L,           // 8
+        1_000_000_000L,
+        10_000_000_000L,
+        100_000_000_000L,
+        1_000_000_000_000L,
+        10_000_000_000_000L,
+        100_000_000_000_000L,
+        1_000_000_000_000_000L,
+        10_000_000_000_000_000L,   // 16
+        100_000_000_000_000_000L,
+        1_000_000_000_000_000_000L, // 18
+    };
+
     DecimalTreeReader(int columnId,
                       int precision,
                       int scale,
@@ -1290,18 +1312,14 @@ public class TreeReaderFactory {
       scaleReader.nextVector(result, scratchScaleVector, batchSize);
       if (result.noNulls) {
         for (int r=0; r < batchSize; ++r) {
-          result.vector[r] = SerializationUtils.readVslong(valueStream);
-          for(int s=scratchScaleVector[r]; s < scale; ++s) {
-            result.vector[r] *= 10;
-          }
+          final long scaleFactor = powerOfTenTable[scale - scratchScaleVector[r]];
+          result.vector[r] = SerializationUtils.readVslong(valueStream) * scaleFactor;
         }
       } else if (!result.isRepeating || !result.isNull[0]) {
         for (int r=0; r < batchSize; ++r) {
           if (!result.isNull[r]) {
-            result.vector[r] = SerializationUtils.readVslong(valueStream);
-            for(int s=scratchScaleVector[r]; s < scale; ++s) {
-              result.vector[r] *= 10;
-            }
+            final long scaleFactor = powerOfTenTable[scale - scratchScaleVector[r]];
+            result.vector[r] = SerializationUtils.readVslong(valueStream) * scaleFactor;
           }
         }
       }