Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion java/vector/src/main/codegen/data/ValueVectorTypes.tdd
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
maxPrecisionDigits: 38, nDecimalDigits: 4, friendlyType: "BigDecimal",
typeParams: [ {name: "scale", type: "int"}, { name: "precision", type: "int"}],
arrowType: "org.apache.arrow.vector.types.pojo.ArrowType.Decimal",
fields: [{name: "start", type: "int"}, {name: "buffer", type: "ArrowBuf"}]
fields: [{name: "start", type: "long"}, {name: "buffer", type: "ArrowBuf"}]
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions java/vector/src/main/codegen/templates/ComplexWriters.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ public void write(NullableDecimalHolder h){
vector.setValueCount(idx() + 1);
}

public void writeDecimal(int start, ArrowBuf buffer){
public void writeDecimal(long start, ArrowBuf buffer){
vector.setSafe(idx(), 1, start, buffer);
vector.setValueCount(idx() + 1);
}

public void writeDecimal(int start, ArrowBuf buffer, ArrowType arrowType){
public void writeDecimal(long start, ArrowBuf buffer, ArrowType arrowType){
DecimalUtility.checkPrecisionAndScale(((ArrowType.Decimal) arrowType).getPrecision(),
((ArrowType.Decimal) arrowType).getScale(), vector.getPrecision(), vector.getScale());
vector.setSafe(idx(), 1, start, buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void writeNull() {
writer.writeNull();
}

public void writeDecimal(int start, ArrowBuf buffer, ArrowType arrowType) {
public void writeDecimal(long start, ArrowBuf buffer, ArrowType arrowType) {
if (writer.idx() >= (idx() + 1) * listSize) {
throw new IllegalStateException(String.format("values at index %s is greater than listSize %s", idx(), listSize));
}
Expand Down
4 changes: 2 additions & 2 deletions java/vector/src/main/codegen/templates/UnionListWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ public void writeNull() {
writer.writeNull();
}

public void writeDecimal(int start, ArrowBuf buffer, ArrowType arrowType) {
public void writeDecimal(long start, ArrowBuf buffer, ArrowType arrowType) {
writer.writeDecimal(start, buffer, arrowType);
writer.setPosition(writer.idx()+1);
}

public void writeDecimal(int start, ArrowBuf buffer) {
public void writeDecimal(long start, ArrowBuf buffer) {
writer.writeDecimal(start, buffer);
writer.setPosition(writer.idx()+1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void setBigEndian(int index, byte[] value) {
* @param start start index of data in the buffer
* @param buffer ArrowBuf containing decimal value.
*/
public void set(int index, int start, ArrowBuf buffer) {
public void set(int index, long start, ArrowBuf buffer) {
BitVectorHelper.setBit(validityBuffer, index);
valueBuffer.setBytes((long) index * TYPE_WIDTH, buffer, start, TYPE_WIDTH);
}
Expand All @@ -258,7 +258,7 @@ public void set(int index, int start, ArrowBuf buffer) {
* @param buffer contains the decimal in little endian bytes
* @param length length of the value in the buffer
*/
public void setSafe(int index, int start, ArrowBuf buffer, int length) {
public void setSafe(int index, long start, ArrowBuf buffer, int length) {
handleSafe(index);
BitVectorHelper.setBit(validityBuffer, index);

Expand All @@ -285,7 +285,7 @@ public void setSafe(int index, int start, ArrowBuf buffer, int length) {
* @param buffer contains the decimal in big endian bytes
* @param length length of the value in the buffer
*/
public void setBigEndianSafe(int index, int start, ArrowBuf buffer, int length) {
public void setBigEndianSafe(int index, long start, ArrowBuf buffer, int length) {
handleSafe(index);
BitVectorHelper.setBit(validityBuffer, index);

Expand Down Expand Up @@ -394,7 +394,7 @@ public void setBigEndianSafe(int index, byte[] value) {
* @param start start index of data in the buffer
* @param buffer ArrowBuf containing decimal value.
*/
public void setSafe(int index, int start, ArrowBuf buffer) {
public void setSafe(int index, long start, ArrowBuf buffer) {
handleSafe(index);
set(index, start, buffer);
}
Expand Down Expand Up @@ -460,7 +460,7 @@ public void setSafe(int index, DecimalHolder holder) {
* @param start start position of the value in the buffer
* @param buffer buffer containing the value to be stored in the vector
*/
public void set(int index, int isSet, int start, ArrowBuf buffer) {
public void set(int index, int isSet, long start, ArrowBuf buffer) {
if (isSet > 0) {
set(index, start, buffer);
} else {
Expand All @@ -478,7 +478,7 @@ public void set(int index, int isSet, int start, ArrowBuf buffer) {
* @param start start position of the value in the buffer
* @param buffer buffer containing the value to be stored in the vector
*/
public void setSafe(int index, int isSet, int start, ArrowBuf buffer) {
public void setSafe(int index, int isSet, long start, ArrowBuf buffer) {
handleSafe(index);
set(index, isSet, start, buffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public void write(DecimalHolder holder) {
}

@Override
public void writeDecimal(int start, ArrowBuf buffer, ArrowType arrowType) {
public void writeDecimal(long start, ArrowBuf buffer, ArrowType arrowType) {
getWriter(MinorType.DECIMAL, new ArrowType.Decimal(MAX_DECIMAL_PRECISION,
((ArrowType.Decimal) arrowType).getScale())).writeDecimal(start, buffer, arrowType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private DecimalUtility() {}
public static BigDecimal getBigDecimalFromArrowBuf(ArrowBuf bytebuf, int index, int scale) {
byte[] value = new byte[DECIMAL_BYTE_LENGTH];
byte temp;
final int startIndex = index * DECIMAL_BYTE_LENGTH;
final long startIndex = (long) index * DECIMAL_BYTE_LENGTH;

// Decimal stored as little endian, need to swap bytes to make BigDecimal
bytebuf.getBytes(startIndex, value, 0, DECIMAL_BYTE_LENGTH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.math.BigDecimal;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.holders.NullableDecimalHolder;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -114,7 +117,7 @@ public void testLargeDecimalVector() {
final int vecLength = (int) (bufSize / DecimalVector.TYPE_WIDTH);

try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
DecimalVector largeVec = new DecimalVector("vec", allocator, 38, 16)) {
DecimalVector largeVec = new DecimalVector("vec", allocator, 38, 0)) {
largeVec.allocateNew(vecLength);

logger.trace("Successfully allocated a vector with capacity {}", vecLength);
Expand All @@ -139,6 +142,22 @@ public void testLargeDecimalVector() {
}
}
logger.trace("Successfully read {} values", vecLength);

// try setting values with a large offset in the buffer
largeVec.set(vecLength - 1, 12345L);
assertEquals(12345L, largeVec.getObject(vecLength - 1).longValue());

NullableDecimalHolder holder = new NullableDecimalHolder();
holder.buffer = largeVec.valueBuffer;
holder.isSet = 1;
holder.start = (long) (vecLength - 1) * largeVec.getTypeWidth();
assertTrue(holder.start > Integer.MAX_VALUE);
largeVec.set(0, holder);

BigDecimal decimal = largeVec.getObject(0);
assertEquals(12345L, decimal.longValue());

logger.trace("Successfully setting values from large offsets");
}
logger.trace("Successfully released the large vector.");
}
Expand Down