arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject arrow git commit: ARROW-265: Fix few decimal bugs
Date Sat, 20 Aug 2016 00:39:55 GMT
Repository: arrow
Updated Branches:
  refs/heads/master 282fcacc8 -> c2eb1612d


ARROW-265: Fix few decimal bugs


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

Branch: refs/heads/master
Commit: c2eb1612df34bee7baddc8851d24826d3c33faa6
Parents: 282fcac
Author: Steven Phillips <steven@dremio.com>
Authored: Fri Aug 19 17:39:36 2016 -0700
Committer: Steven Phillips <steven@dremio.com>
Committed: Fri Aug 19 17:39:36 2016 -0700

----------------------------------------------------------------------
 .../templates/AbstractPromotableFieldWriter.java | 19 ++++++++++++++++---
 .../codegen/templates/FixedValueVectors.java     |  2 +-
 .../src/main/codegen/templates/MapWriters.java   |  2 +-
 .../org/apache/arrow/vector/types/Types.java     |  3 ++-
 .../apache/arrow/vector/util/DecimalUtility.java |  3 +--
 5 files changed, 21 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/c2eb1612/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java b/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java
index 7e60320..d21dcd0 100644
--- a/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java
+++ b/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java
@@ -82,7 +82,18 @@ abstract class AbstractPromotableFieldWriter extends AbstractFieldWriter
{
     getWriter(MinorType.${name?upper_case}).write${minor.class}(<#list fields as field>${field.name}<#if
field_has_next>, </#if></#list>);
   }
 
+  <#else>
+  @Override
+  public void write(DecimalHolder holder) {
+    getWriter(MinorType.DECIMAL).write(holder);
+  }
+
+  public void writeDecimal(int start, ArrowBuf buffer) {
+    getWriter(MinorType.DECIMAL).writeDecimal(start, buffer);
+  }
+
   </#if>
+
   </#list></#list>
 
   public void writeNull() {
@@ -113,8 +124,11 @@ abstract class AbstractPromotableFieldWriter extends AbstractFieldWriter
{
   <#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
   <#assign upperName = minor.class?upper_case />
   <#assign capName = minor.class?cap_first />
-  <#if !minor.class?starts_with("Decimal") >
-
+  <#if minor.class?starts_with("Decimal") >
+  public ${capName}Writer ${lowerName}(String name, int scale, int precision) {
+    return getWriter(MinorType.MAP).${lowerName}(name, scale, precision);
+  }
+  </#if>
   @Override
   public ${capName}Writer ${lowerName}(String name) {
     return getWriter(MinorType.MAP).${lowerName}(name);
@@ -125,7 +139,6 @@ abstract class AbstractPromotableFieldWriter extends AbstractFieldWriter
{
     return getWriter(MinorType.LIST).${lowerName}();
   }
 
-  </#if>
   </#list></#list>
 
   public void copyReader(FieldReader reader) {

http://git-wip-us.apache.org/repos/asf/arrow/blob/c2eb1612/java/vector/src/main/codegen/templates/FixedValueVectors.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/FixedValueVectors.java b/java/vector/src/main/codegen/templates/FixedValueVectors.java
index 37946f6..7958222 100644
--- a/java/vector/src/main/codegen/templates/FixedValueVectors.java
+++ b/java/vector/src/main/codegen/templates/FixedValueVectors.java
@@ -446,7 +446,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements
F
 
     @Override
     public ${friendlyType} getObject(int index) {
-      return org.apache.arrow.vector.util.DecimalUtility.getBigDecimalFromArrowBuf(data,
index, scale);
+      return org.apache.arrow.vector.util.DecimalUtility.getBigDecimalFromArrowBuf(data,
${type.width} * index, scale);
     }
 
     <#else>

http://git-wip-us.apache.org/repos/asf/arrow/blob/c2eb1612/java/vector/src/main/codegen/templates/MapWriters.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/MapWriters.java b/java/vector/src/main/codegen/templates/MapWriters.java
index af29228..8a8983a 100644
--- a/java/vector/src/main/codegen/templates/MapWriters.java
+++ b/java/vector/src/main/codegen/templates/MapWriters.java
@@ -198,7 +198,7 @@ public class ${mode}MapWriter extends AbstractFieldWriter {
     if(writer == null) {
       ValueVector vector;
       ValueVector currentVector = container.getChild(name);
-      ${vectName}Vector v = container.addOrGet(name, MinorType.${upperName}, ${vectName}Vector.class);
+      ${vectName}Vector v = container.addOrGet(name, MinorType.${upperName}, ${vectName}Vector.class<#if
minor.class == "Decimal"> , new int[] {precision, scale}</#if>);
       writer = new PromotableWriter(v, container);
       vector = v;
       if (currentVector == null || currentVector != vector) {

http://git-wip-us.apache.org/repos/asf/arrow/blob/c2eb1612/java/vector/src/main/java/org/apache/arrow/vector/types/Types.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/java/org/apache/arrow/vector/types/Types.java b/java/vector/src/main/java/org/apache/arrow/vector/types/Types.java
index 5ea1456..c34882a 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/types/Types.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/types/Types.java
@@ -47,6 +47,7 @@ import org.apache.arrow.vector.complex.UnionVector;
 import org.apache.arrow.vector.complex.impl.BigIntWriterImpl;
 import org.apache.arrow.vector.complex.impl.BitWriterImpl;
 import org.apache.arrow.vector.complex.impl.DateWriterImpl;
+import org.apache.arrow.vector.complex.impl.DecimalWriterImpl;
 import org.apache.arrow.vector.complex.impl.Float4WriterImpl;
 import org.apache.arrow.vector.complex.impl.Float8WriterImpl;
 import org.apache.arrow.vector.complex.impl.IntWriterImpl;
@@ -386,7 +387,7 @@ public class Types {
 
       @Override
       public FieldWriter getNewFieldWriter(ValueVector vector) {
-        return new VarBinaryWriterImpl((NullableVarBinaryVector) vector);
+        return new DecimalWriterImpl((NullableDecimalVector) vector);
       }
     },   //  variable length binary
     UINT1(new Int(8, false)) {

http://git-wip-us.apache.org/repos/asf/arrow/blob/c2eb1612/java/vector/src/main/java/org/apache/arrow/vector/util/DecimalUtility.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/java/org/apache/arrow/vector/util/DecimalUtility.java b/java/vector/src/main/java/org/apache/arrow/vector/util/DecimalUtility.java
index e171e87..4c439b2 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/util/DecimalUtility.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/util/DecimalUtility.java
@@ -135,9 +135,8 @@ public class DecimalUtility {
     return str;
   }
 
-  public static BigDecimal getBigDecimalFromArrowBuf(ArrowBuf bytebuf, int index, int scale)
{
+  public static BigDecimal getBigDecimalFromArrowBuf(ArrowBuf bytebuf, int startIndex, int
scale) {
     byte[] value = new byte[DECIMAL_BYTE_LENGTH];
-    final int startIndex = index * DECIMAL_BYTE_LENGTH;
     bytebuf.getBytes(startIndex, value, 0, DECIMAL_BYTE_LENGTH);
     BigInteger unscaledValue = new BigInteger(value);
     return new BigDecimal(unscaledValue, scale);


Mime
View raw message