Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kiszk committed Nov 3, 2020
1 parent ff33c3c commit 8b530eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static void writeBigDecimalToArrowBuf(BigDecimal value, ArrowBuf bytebuf,
*/
public static void writeLongToArrowBuf(long value, ArrowBuf bytebuf, int index, int byteWidth) {
if (byteWidth != 16 && byteWidth != 32) {
throw new UnsupportedOperationException("DeciimalUtility.writeLongToArrowBuf() currently supports " +
throw new UnsupportedOperationException("DecimalUtility.writeLongToArrowBuf() currently supports " +
"128-bit or 256-bit width data");
}
final long addressOfValue = bytebuf.memoryAddress() + (long) index * byteWidth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.DecimalVector;
import org.apache.arrow.vector.compare.VectorEqualsVisitor;
import org.apache.arrow.vector.complex.FixedSizeListVector;
import org.apache.arrow.vector.complex.ListVector;
Expand Down Expand Up @@ -526,7 +527,7 @@ public void testCopyFixedSizedListOfDecimalsVector() {
to.addOrGetVector(FieldType.nullable(new ArrowType.Decimal(3, 0, 128)));

DecimalHolder holder = new DecimalHolder();
holder.buffer = allocator.buffer(16);
holder.buffer = allocator.buffer(DecimalVector.TYPE_WIDTH);
ArrowType arrowType = new ArrowType.Decimal(3, 0, 128);

// populate from vector
Expand All @@ -535,13 +536,13 @@ public void testCopyFixedSizedListOfDecimalsVector() {
writer.startList();
writer.decimal().writeDecimal(BigDecimal.valueOf(i));

DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(i * 2), holder.buffer, 0, /*byteWidth=*/16);
DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(i * 2), holder.buffer, 0, DecimalVector.TYPE_WIDTH);
holder.start = 0;
holder.scale = 0;
holder.precision = 3;
writer.decimal().write(holder);

DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(i * 3), holder.buffer, 0, /*byteWidth=*/16);
DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(i * 3), holder.buffer, 0, DecimalVector.TYPE_WIDTH);
writer.decimal().writeDecimal(0, holder.buffer, arrowType);

writer.decimal().writeBigEndianBytesToDecimal(BigDecimal.valueOf(i * 4).unscaledValue().toByteArray(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.util.AutoCloseables;
import org.apache.arrow.vector.BigIntVector;
import org.apache.arrow.vector.DecimalVector;
import org.apache.arrow.vector.Float4Vector;
import org.apache.arrow.vector.Float8Vector;
import org.apache.arrow.vector.IntVector;
Expand Down Expand Up @@ -310,21 +311,21 @@ public void listDecimalType() {
listVector.allocateNew();
UnionListWriter listWriter = new UnionListWriter(listVector);
DecimalHolder holder = new DecimalHolder();
holder.buffer = allocator.buffer(16);
holder.buffer = allocator.buffer(DecimalVector.TYPE_WIDTH);
ArrowType arrowType = new ArrowType.Decimal(10, 0, 128);
for (int i = 0; i < COUNT; i++) {
listWriter.startList();
for (int j = 0; j < i % 7; j++) {
if (j % 4 == 0) {
listWriter.writeDecimal(new BigDecimal(j));
} else if (j % 4 == 1) {
DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(j), holder.buffer, 0, 16);
DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(j), holder.buffer, 0, DecimalVector.TYPE_WIDTH);
holder.start = 0;
holder.scale = 0;
holder.precision = 10;
listWriter.write(holder);
} else if (j % 4 == 2) {
DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(j), holder.buffer, 0, 16);
DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(j), holder.buffer, 0, DecimalVector.TYPE_WIDTH);
listWriter.writeDecimal(0, holder.buffer, arrowType);
} else {
byte[] value = BigDecimal.valueOf(j).unscaledValue().toByteArray();
Expand Down

0 comments on commit 8b530eb

Please sign in to comment.