Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,11 @@ private class TransferImpl implements TransferPair {

public TransferImpl(String ref, BufferAllocator allocator) {
to =
new Decimal256Vector(
ref, allocator, Decimal256Vector.this.precision, Decimal256Vector.this.scale);
(Decimal256Vector.this.field != null
&& Decimal256Vector.this.field.getFieldType() != null)
? new Decimal256Vector(ref, Decimal256Vector.this.field.getFieldType(), allocator)
: new Decimal256Vector(
ref, allocator, Decimal256Vector.this.precision, Decimal256Vector.this.scale);
}

public TransferImpl(Field field, BufferAllocator allocator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,10 @@ private class TransferImpl implements TransferPair {

public TransferImpl(String ref, BufferAllocator allocator) {
to =
new DecimalVector(ref, allocator, DecimalVector.this.precision, DecimalVector.this.scale);
(DecimalVector.this.field != null && DecimalVector.this.field.getFieldType() != null)
? new DecimalVector(ref, DecimalVector.this.field.getFieldType(), allocator)
: new DecimalVector(
ref, allocator, DecimalVector.this.precision, DecimalVector.this.scale);
}

public TransferImpl(Field field, BufferAllocator allocator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.types.pojo.FieldType;
import org.apache.arrow.vector.util.TransferPair;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -375,6 +376,33 @@ public void testGetTransferPairWithField() {
assertSame(fromVector.getField(), toVector.getField());
}

@Test
public void testGetTransferPairWithoutField() {
final Decimal256Vector fromVector = new Decimal256Vector("decimal", allocator, 10, scale);
final TransferPair transferPair =
fromVector.getTransferPair(fromVector.getField().getName(), allocator);
final Decimal256Vector toVector = (Decimal256Vector) transferPair.getTo();
// A new Field created inside a new vector should reuse the field type (should be the same in
// memory as the original Field's field type).
assertSame(fromVector.getField().getFieldType(), toVector.getField().getFieldType());
}

@Test
public void testGetTransferPairWithoutFieldNonNullable() {
final FieldType decimal256NonNullableType =
new FieldType(
false, new ArrowType.Decimal(10, scale, Decimal256Vector.TYPE_WIDTH * 8), null);
final Decimal256Vector fromVector =
new Decimal256Vector("decimal", decimal256NonNullableType, allocator);
final TransferPair transferPair =
fromVector.getTransferPair(fromVector.getField().getName(), allocator);
final Decimal256Vector toVector = (Decimal256Vector) transferPair.getTo();
// A new Field created inside a new vector should reuse the field type (should be the same in
// memory as the original Field's field type).
assertSame(fromVector.getField().getFieldType(), toVector.getField().getFieldType());
assertSame(decimal256NonNullableType, toVector.getField().getFieldType());
}

private void verifyWritingArrowBufWithBigEndianBytes(
Decimal256Vector decimalVector, ArrowBuf buf, BigDecimal[] expectedValues, int length) {
decimalVector.allocateNew();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.types.pojo.FieldType;
import org.apache.arrow.vector.util.TransferPair;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -371,6 +372,31 @@ public void testGetTransferPairWithField() {
assertSame(fromVector.getField(), toVector.getField());
}

@Test
public void testGetTransferPairWithoutField() {
final DecimalVector fromVector = new DecimalVector("decimal", allocator, 10, scale);
final TransferPair transferPair =
fromVector.getTransferPair(fromVector.getField().getName(), allocator);
final DecimalVector toVector = (DecimalVector) transferPair.getTo();
// A new Field created inside a new vector should reuse the field type (should be the same in
// memory as the original Field's field type).
assertSame(fromVector.getField().getFieldType(), toVector.getField().getFieldType());
}

@Test
public void testGetTransferPairWithoutFieldNonNullable() {
final FieldType decimalNonNullableType =
new FieldType(false, new ArrowType.Decimal(10, scale), null);
final DecimalVector fromVector =
new DecimalVector("decimal", decimalNonNullableType, allocator);
final TransferPair transferPair =
fromVector.getTransferPair(fromVector.getField().getName(), allocator);
final DecimalVector toVector = (DecimalVector) transferPair.getTo();
// A new Field created inside a new vector should reuse the field type (should be the same in
// memory as the original Field's field type).
assertSame(fromVector.getField().getFieldType(), toVector.getField().getFieldType());
}

private void verifyWritingArrowBufWithBigEndianBytes(
DecimalVector decimalVector, ArrowBuf buf, BigDecimal[] expectedValues, int length) {
decimalVector.allocateNew();
Expand Down
Loading