carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jack...@apache.org
Subject carbondata git commit: [CARBONDATA-1471] Replace BigDecimal to double to improve performance
Date Wed, 13 Sep 2017 08:46:07 GMT
Repository: carbondata
Updated Branches:
  refs/heads/master b6727d75d -> a8b3face6


[CARBONDATA-1471] Replace BigDecimal to double to improve performance

While calculating adaptive floating encoding currently it uses BigDecimal for calculations,
But it is very slow to use BIgdecimal as it creates many objects of BigDecimals. Alternatively,
we can use double to improve the performance.

This closes #1345


Project: http://git-wip-us.apache.org/repos/asf/carbondata/repo
Commit: http://git-wip-us.apache.org/repos/asf/carbondata/commit/a8b3face
Tree: http://git-wip-us.apache.org/repos/asf/carbondata/tree/a8b3face
Diff: http://git-wip-us.apache.org/repos/asf/carbondata/diff/a8b3face

Branch: refs/heads/master
Commit: a8b3face6271562d415922af737e3e9b22d2fce0
Parents: b6727d7
Author: Ravindra Pesala <ravi.pesala@gmail.com>
Authored: Sun Sep 10 14:21:15 2017 +0530
Committer: Jacky Li <jacky.likun@qq.com>
Committed: Wed Sep 13 16:45:58 2017 +0800

----------------------------------------------------------------------
 .../adaptive/AdaptiveFloatingCodec.java         | 47 ++++++++------------
 1 file changed, 18 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/carbondata/blob/a8b3face/core/src/main/java/org/apache/carbondata/core/datastore/page/encoding/adaptive/AdaptiveFloatingCodec.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/carbondata/core/datastore/page/encoding/adaptive/AdaptiveFloatingCodec.java
b/core/src/main/java/org/apache/carbondata/core/datastore/page/encoding/adaptive/AdaptiveFloatingCodec.java
index 7fc5811..789383c 100644
--- a/core/src/main/java/org/apache/carbondata/core/datastore/page/encoding/adaptive/AdaptiveFloatingCodec.java
+++ b/core/src/main/java/org/apache/carbondata/core/datastore/page/encoding/adaptive/AdaptiveFloatingCodec.java
@@ -18,7 +18,6 @@
 package org.apache.carbondata.core.datastore.page.encoding.adaptive;
 
 import java.io.IOException;
-import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -45,7 +44,7 @@ import org.apache.carbondata.format.Encoding;
 public class AdaptiveFloatingCodec extends AdaptiveCodec {
 
   private ColumnPage encodedPage;
-  private BigDecimal factor;
+  private Double factor;
 
   public static ColumnPageCodec newInstance(DataType srcDataType, DataType targetDataType,
       SimpleStatsResult stats) {
@@ -55,7 +54,7 @@ public class AdaptiveFloatingCodec extends AdaptiveCodec {
   public AdaptiveFloatingCodec(DataType srcDataType, DataType targetDataType,
       SimpleStatsResult stats) {
     super(srcDataType, targetDataType, stats);
-    this.factor = BigDecimal.valueOf(Math.pow(10, stats.getDecimalCount()));
+    this.factor = Math.pow(10, stats.getDecimalCount());
   }
 
   @Override
@@ -98,8 +97,8 @@ public class AdaptiveFloatingCodec extends AdaptiveCodec {
   public ColumnPageDecoder createDecoder(ColumnPageEncoderMeta meta) {
     assert meta instanceof AdaptiveFloatingEncoderMeta;
     AdaptiveFloatingEncoderMeta codecMeta = (AdaptiveFloatingEncoderMeta) meta;
-    final Compressor compressor = CompressorFactory.getInstance().getCompressor(
-        codecMeta.getCompressorName());
+    final Compressor compressor =
+        CompressorFactory.getInstance().getCompressor(codecMeta.getCompressorName());
     final DataType targetDataType = codecMeta.getTargetDataType();
     return new ColumnPageDecoder() {
       @Override
@@ -141,24 +140,19 @@ public class AdaptiveFloatingCodec extends AdaptiveCodec {
     public void encode(int rowId, float value) {
       switch (targetDataType) {
         case BYTE:
-          encodedPage.putByte(rowId,
-              BigDecimal.valueOf(value).multiply(factor).byteValue());
+          encodedPage.putByte(rowId, (byte) (value * factor));
           break;
         case SHORT:
-          encodedPage.putShort(rowId,
-              BigDecimal.valueOf(value).multiply(factor).shortValue());
+          encodedPage.putShort(rowId, (short) (value * factor));
           break;
         case SHORT_INT:
-          encodedPage.putShortInt(rowId,
-              BigDecimal.valueOf(value).multiply(factor).intValue());
+          encodedPage.putShortInt(rowId, (int) (value * factor));
           break;
         case INT:
-          encodedPage.putInt(rowId,
-              BigDecimal.valueOf(value).multiply(factor).intValue());
+          encodedPage.putInt(rowId, (int) (value * factor));
           break;
         case LONG:
-          encodedPage.putLong(rowId,
-              BigDecimal.valueOf(value).multiply(factor).longValue());
+          encodedPage.putLong(rowId, (long) (value * factor));
           break;
         default:
           throw new RuntimeException("internal error: " + debugInfo());
@@ -169,24 +163,19 @@ public class AdaptiveFloatingCodec extends AdaptiveCodec {
     public void encode(int rowId, double value) {
       switch (targetDataType) {
         case BYTE:
-          encodedPage.putByte(rowId,
-              BigDecimal.valueOf(value).multiply(factor).byteValue());
+          encodedPage.putByte(rowId, (byte) (value * factor));
           break;
         case SHORT:
-          encodedPage.putShort(rowId,
-              BigDecimal.valueOf(value).multiply(factor).shortValue());
+          encodedPage.putShort(rowId, (short) (value * factor));
           break;
         case SHORT_INT:
-          encodedPage.putShortInt(rowId,
-              BigDecimal.valueOf(value).multiply(factor).intValue());
+          encodedPage.putShortInt(rowId, (int) (value * factor));
           break;
         case INT:
-          encodedPage.putInt(rowId,
-              BigDecimal.valueOf(value).multiply(factor).intValue());
+          encodedPage.putInt(rowId, (int) (value * factor));
           break;
         case LONG:
-          encodedPage.putLong(rowId,
-              BigDecimal.valueOf(value).multiply(factor).longValue());
+          encodedPage.putLong(rowId, (long) (value * factor));
           break;
         case DOUBLE:
           encodedPage.putDouble(rowId, value);
@@ -213,22 +202,22 @@ public class AdaptiveFloatingCodec extends AdaptiveCodec {
 
     @Override
     public double decodeDouble(byte value) {
-      return BigDecimal.valueOf(value).divide(factor).doubleValue();
+      return value / factor;
     }
 
     @Override
     public double decodeDouble(short value) {
-      return BigDecimal.valueOf(value).divide(factor).doubleValue();
+      return value / factor;
     }
 
     @Override
     public double decodeDouble(int value) {
-      return BigDecimal.valueOf(value).divide(factor).doubleValue();
+      return value / factor;
     }
 
     @Override
     public double decodeDouble(long value) {
-      return BigDecimal.valueOf(value).divide(factor).doubleValue();
+      return value / factor;
     }
 
     @Override


Mime
View raw message