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
1 change: 1 addition & 0 deletions vector/src/main/codegen/templates/PromotableWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public void setPosition(int index) {

protected boolean requiresArrowType(MinorType type) {
return type == MinorType.DECIMAL
|| type == MinorType.DECIMAL256
Comment thread
robert3005 marked this conversation as resolved.
Resolved
|| type == MinorType.MAP
|| type == MinorType.DURATION
|| type == MinorType.FIXEDSIZEBINARY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Objects;
import java.util.UUID;
import org.apache.arrow.memory.ArrowBuf;
Expand Down Expand Up @@ -759,6 +760,60 @@ public void testPromoteLargeVarBinaryHelpersDirect() throws Exception {
}
}

@Test
public void testDecimal256InPromotedUnion() {
BigDecimal narrow = new BigDecimal("123.45");
BigDecimal wide = new BigDecimal("123456789012345678901234567890123456789.01");
try (ListVector vector = ListVector.empty("decimals", allocator)) {
UnionListWriter writer = vector.getWriter();
writer.startList();
writer.decimal().writeDecimal(narrow);
writer.decimal256().writeDecimal256(wide);
writer.decimal().writeDecimal(narrow.negate());
writer.decimal256().writeDecimal256(wide.negate());
writer.endList();
vector.setValueCount(1);
assertEquals(
Arrays.asList(narrow, wide, narrow.negate(), wide.negate()), vector.getObject(0));
vector.validateFull();
}
}

@Test
public void testAddDecimal256ToExistingUnion() {
BigDecimal decimal = new BigDecimal("-123.456");
try (ListVector vector = ListVector.empty("values", allocator)) {
UnionListWriter writer = vector.getWriter();
writer.startList();
writer.integer().writeInt(7);
writer.bigInt().writeBigInt(8L);
writer.decimal256().writeDecimal256(decimal);
writer.endList();
vector.setValueCount(1);
assertEquals(Arrays.asList(7, 8L, decimal), vector.getObject(0));
}
}

@Test
public void testPromoteStructFieldToDecimal256() throws Exception {
BigDecimal decimal = new BigDecimal("123.456");
try (StructVector parent = StructVector.empty("parent", allocator);
PromotableWriter writer = new PromotableWriter(parent.addOrGetStruct("value"), parent)) {
parent.allocateNew();
writer.setPosition(0);
writer.start();
writer.integer("id").writeInt(7);
writer.end();
writer.setPosition(1);
writer.writeDecimal256(decimal);
parent.setValueCount(2);

UnionVector values = parent.getChild("value", UnionVector.class);
assertEquals(7, values.getStruct().getObject(0).get("id"));
assertEquals(decimal, values.getObject(1));
}
}

@Test
public void testPromoteToUnionFromDecimal() throws Exception {
try (final NonNullableStructVector container =
Expand Down
Loading