Skip to content

Commit

Permalink
fix: cleaning vector module v5
Browse files Browse the repository at this point in the history
  • Loading branch information
vibhatha committed Sep 12, 2024
1 parent f8bc623 commit ab93ca8
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 33 deletions.
17 changes: 17 additions & 0 deletions java/memory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,21 @@ under the License.
<module>memory-netty-buffer-patch</module>
<module>memory-netty</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<compilerArgs combine.children="override">
<arg>-XDcompilePolicy=simple</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ public static ByteBuffer serializeMessage(
* valid Message was read, or null if end-of-stream
* @throws IOException on error
*/
@SuppressWarnings("UnusedVariable")
public static MessageMetadataResult readMessage(ReadChannel in) throws IOException {

// Read the message size. There is an i32 little endian prefix.
Expand All @@ -740,6 +741,10 @@ public static MessageMetadataResult readMessage(ReadChannel in) throws IOExcepti
throw new IOException("Unexpected end of stream trying to read message.");
}

// see https://github.com/apache/arrow/issues/41717 for reason why we cast to
// java.nio.Buffer
ByteBuffer rewindBuffer = (ByteBuffer) ((java.nio.Buffer) messageBuffer).rewind();

// Load the message.
Message message = Message.getRootAsMessage(messageBuffer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ public Void visit(BaseVariableWidthVector vector, Void value) {
int lastOffset =
valueCount == 0
? 0
: vector.getOffsetBuffer().getInt((long) valueCount * BaseVariableWidthVector.OFFSET_WIDTH);
: vector
.getOffsetBuffer()
.getInt((long) valueCount * BaseVariableWidthVector.OFFSET_WIDTH);
validateDataBuffer(vector, lastOffset);
return null;
}
Expand Down Expand Up @@ -172,7 +174,9 @@ public Void visit(ListVector vector, Void value) {
int lastOffset =
valueCount == 0
? 0
: vector.getOffsetBuffer().getInt((long) valueCount * BaseVariableWidthVector.OFFSET_WIDTH);
: vector
.getOffsetBuffer()
.getInt((long) valueCount * BaseVariableWidthVector.OFFSET_WIDTH);
int dataVectorLength = dataVector == null ? 0 : dataVector.getValueCount();
validateOrThrow(
dataVectorLength >= lastOffset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ public Void visit(LargeListVector vector, Void value) {

long firstOffset = vector.getOffsetBuffer().getLong(0);
long lastOffset =
vector.getOffsetBuffer().getLong((long) vector.getValueCount() * LargeListVector.OFFSET_WIDTH);
vector
.getOffsetBuffer()
.getLong((long) vector.getValueCount() * LargeListVector.OFFSET_WIDTH);

if (firstOffset < 0 || lastOffset < 0) {
throw new IllegalArgumentException("Negative offsets in list vector");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,18 @@ public void testToISO8601IntervalString() {
.toISO8601IntervalString());
assertEquals(
"PT1H1.000000123S",
new PeriodDuration(Period.ZERO, Duration.ofSeconds(Duration.ofSeconds(3601).getSeconds(), 123))
new PeriodDuration(
Period.ZERO, Duration.ofSeconds(Duration.ofSeconds(3601).getSeconds(), 123))
.toISO8601IntervalString());
assertEquals(
"PT24H1M1.000000123S",
new PeriodDuration(Period.ZERO, Duration.ofSeconds(Duration.ofSeconds(86461).getSeconds(), 123))
new PeriodDuration(
Period.ZERO, Duration.ofSeconds(Duration.ofSeconds(86461).getSeconds(), 123))
.toISO8601IntervalString());
assertEquals(
"P1Y2M3DT24H1M1.000000123S",
new PeriodDuration(Period.of(1, 2, 3), Duration.ofSeconds(Duration.ofSeconds(86461).getSeconds(), 123))
new PeriodDuration(
Period.of(1, 2, 3), Duration.ofSeconds(Duration.ofSeconds(86461).getSeconds(), 123))
.toISO8601IntervalString());

assertEquals(
Expand All @@ -77,11 +80,13 @@ public void testToISO8601IntervalString() {
new PeriodDuration(Period.ZERO, Duration.ofNanos(-123)).toISO8601IntervalString());
assertEquals(
"PT-24H-1M-0.999999877S",
new PeriodDuration(Period.ZERO, Duration.ofSeconds(Duration.ofSeconds(-86461).getSeconds(), 123))
new PeriodDuration(
Period.ZERO, Duration.ofSeconds(Duration.ofSeconds(-86461).getSeconds(), 123))
.toISO8601IntervalString());
assertEquals(
"P-1Y-2M-3DT-0.999999877S",
new PeriodDuration(Period.of(-1, -2, -3), Duration.ofSeconds(Duration.ofSeconds(-1).getSeconds(), 123))
new PeriodDuration(
Period.of(-1, -2, -3), Duration.ofSeconds(Duration.ofSeconds(-1).getSeconds(), 123))
.toISO8601IntervalString());
}

Expand All @@ -95,7 +100,9 @@ public void testTemporalAccessor() {
PeriodDuration pd2 = new PeriodDuration(Period.ZERO, Duration.ofMinutes(1));
assertEquals(LocalDateTime.of(2024, 1, 2, 3, 3), pd2.subtractFrom(dateTime));

PeriodDuration pd3 = new PeriodDuration(Period.of(1, 2, 3), Duration.ofSeconds(Duration.ofSeconds(86461).getSeconds(), 123));
PeriodDuration pd3 =
new PeriodDuration(
Period.of(1, 2, 3), Duration.ofSeconds(Duration.ofSeconds(86461).getSeconds(), 123));
assertEquals(pd3.get(ChronoUnit.YEARS), 1);
assertEquals(pd3.get(ChronoUnit.MONTHS), 2);
assertEquals(pd3.get(ChronoUnit.DAYS), 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public void testCopyMapVector() {
mapWriter.value().integer().writeInt(i);
mapWriter.endEntry();
mapWriter.startEntry();
mapWriter.key().decimal().writeDecimal(BigDecimal.valueOf(i * 2));
mapWriter.value().decimal().writeDecimal(BigDecimal.valueOf(i * 2));
mapWriter.key().decimal().writeDecimal(BigDecimal.valueOf(i * 2L));
mapWriter.value().decimal().writeDecimal(BigDecimal.valueOf(i * 2L));
mapWriter.endEntry();
mapWriter.endMap();
}
Expand Down Expand Up @@ -176,13 +176,13 @@ public void testCopyListVector() {

listWriter.list().startList();
listWriter.list().bigInt().writeBigInt(i);
listWriter.list().bigInt().writeBigInt(i * 2);
listWriter.list().bigInt().writeBigInt(i * 3);
listWriter.list().bigInt().writeBigInt(i * 2L);
listWriter.list().bigInt().writeBigInt(i * 3L);
listWriter.list().endList();

listWriter.list().startList();
listWriter.list().decimal().writeDecimal(BigDecimal.valueOf(i * 4));
listWriter.list().decimal().writeDecimal(BigDecimal.valueOf(i * 5));
listWriter.list().decimal().writeDecimal(BigDecimal.valueOf(i * 4L));
listWriter.list().decimal().writeDecimal(BigDecimal.valueOf(i * 5L));
listWriter.list().endList();
listWriter.endList();
}
Expand Down Expand Up @@ -597,7 +597,7 @@ public void testCopyFixedSizedListOfDecimalsVector() {
writer
.decimal()
.writeBigEndianBytesToDecimal(
BigDecimal.valueOf(i * 4).unscaledValue().toByteArray(), arrowType);
BigDecimal.valueOf(i * 4L).unscaledValue().toByteArray(), arrowType);

writer.endList();
}
Expand Down Expand Up @@ -631,12 +631,12 @@ public void testCopyUnionListWithDecimal() {
listWriter.setPosition(i);
listWriter.startList();

listWriter.decimal().writeDecimal(BigDecimal.valueOf(i * 2));
listWriter.decimal().writeDecimal(BigDecimal.valueOf(i * 2L));
listWriter.integer().writeInt(i);
listWriter
.decimal()
.writeBigEndianBytesToDecimal(
BigDecimal.valueOf(i * 3).unscaledValue().toByteArray(),
BigDecimal.valueOf(i * 3L).unscaledValue().toByteArray(),
new ArrowType.Decimal(3, 0, 128));

listWriter.endList();
Expand Down Expand Up @@ -671,15 +671,15 @@ public void testCopyStructVector() {
structWriter.setPosition(i);
structWriter.start();
structWriter.integer("int").writeInt(i);
structWriter.decimal("dec", 0, 38).writeDecimal(BigDecimal.valueOf(i * 2));
structWriter.decimal("dec", 0, 38).writeDecimal(BigDecimal.valueOf(i * 2L));
StructWriter innerStructWriter = structWriter.struct("struc");
innerStructWriter.start();
innerStructWriter.integer("innerint").writeInt(i * 3);
innerStructWriter.decimal("innerdec", 0, 38).writeDecimal(BigDecimal.valueOf(i * 4));
innerStructWriter.decimal("innerdec", 0, 38).writeDecimal(BigDecimal.valueOf(i * 4L));
innerStructWriter
.decimal("innerdec", 0, 38)
.writeBigEndianBytesToDecimal(
BigDecimal.valueOf(i * 4).unscaledValue().toByteArray(),
BigDecimal.valueOf(i * 4L).unscaledValue().toByteArray(),
new ArrowType.Decimal(3, 0, 128));
innerStructWriter.end();
structWriter.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ protected VectorSchemaRoot writeDecimalData(BufferAllocator bufferAllocator) {

for (int i = 0; i < count; i++) {
decimalVector1.setSafe(i, new BigDecimal(BigInteger.valueOf(i), 3));
decimalVector2.setSafe(i, new BigDecimal(BigInteger.valueOf(i * (1 << 10)), 2));
decimalVector2.setSafe(i, new BigDecimal(BigInteger.valueOf(i * ((long) (1 << 10))), 2));
decimalVector3.setSafe(i, new BigDecimal(BigInteger.valueOf(i * 1111111111111111L), 8));
}

Expand Down Expand Up @@ -543,7 +543,7 @@ protected void validateDecimalData(VectorSchemaRoot root) {
// Verify decimal 2 vector
readValue = decimalVector2.getObject(i);
type = (ArrowType.Decimal) decimalVector2.getField().getType();
genValue = new BigDecimal(BigInteger.valueOf(i * (1 << 10)), type.getScale());
genValue = new BigDecimal(BigInteger.valueOf(i * ((long) (1 << 10))), type.getScale());
assertEquals(genValue, readValue);

// Verify decimal 3 vector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ public void testReadInterleavedData() throws IOException {
Collections.singletonList(dictVector1),
dictVector1.getValueCount());
ArrowDictionaryBatch dictionaryBatch1 =
new ArrowDictionaryBatch(1, new VectorUnloader(dictRoot1).getRecordBatch());
new ArrowDictionaryBatch(1, new VectorUnloader(dictRoot1).getRecordBatch(), false);
MessageSerializer.serialize(out, dictionaryBatch1);
dictionaryBatch1.close();
dictRoot1.close();
Expand All @@ -799,7 +799,7 @@ public void testReadInterleavedData() throws IOException {
Collections.singletonList(dictVector2),
dictVector2.getValueCount());
ArrowDictionaryBatch dictionaryBatch2 =
new ArrowDictionaryBatch(2, new VectorUnloader(dictRoot2).getRecordBatch());
new ArrowDictionaryBatch(2, new VectorUnloader(dictRoot2).getRecordBatch(), false);
MessageSerializer.serialize(out, dictionaryBatch2);
dictionaryBatch2.close();
dictRoot2.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ public void list() throws Exception {
org.apache.arrow.vector.types.pojo.Schema schema =
new org.apache.arrow.vector.types.pojo.Schema(tempSchema.getFields());
schemaBuilder.finish(schema.getSchema(schemaBuilder));
Schema finalSchema = Schema.deserialize(ByteBuffer.wrap(schemaBuilder.sizedByteArray()));
Schema finalSchema =
Schema.convertSchema(
org.apache.arrow.flatbuf.Schema.getRootAsSchema(
ByteBuffer.wrap(schemaBuilder.sizedByteArray())));
assertFalse(finalSchema.toString().contains("[DEFAULT]"));
}

Expand Down Expand Up @@ -131,6 +134,7 @@ public void schemaMetadata() {
}

@Test
@SuppressWarnings("EnumOrdinal")
public void nestedSchema() {
java.util.List<Field> children = new ArrayList<>();
children.add(new Field("child1", FieldType.nullable(Utf8.INSTANCE), null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ void testSimpleDenseUnionVector() {
}

@Test
@SuppressWarnings("FloatingPointLiteralPrecision")
void testExtensionTypeVector() {
TestExtensionType.LocationVector vector =
new TestExtensionType.LocationVector("location", allocator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void testPopulateDateMilliVector() {
if (i % 2 == 0) {
vector1.setNull(i);
} else {
vector1.set(i, i * 1000);
vector1.set(i, i * 1000L);
}
}
vector1.setValueCount(10);
Expand Down Expand Up @@ -334,7 +334,7 @@ public void testPopulateTimeMicroVector() {
if (i % 2 == 0) {
vector1.setNull(i);
} else {
vector1.set(i, i * 10000);
vector1.set(i, i * 10000L);
}
}
vector1.setValueCount(10);
Expand Down Expand Up @@ -372,7 +372,7 @@ public void testPopulateTimeNanoVector() {
if (i % 2 == 0) {
vector1.setNull(i);
} else {
vector1.set(i, i * 10000);
vector1.set(i, i * 10000L);
}
}
vector1.setValueCount(10);
Expand Down Expand Up @@ -410,7 +410,7 @@ public void testPopulateTimeStampMicroVector() {
if (i % 2 == 0) {
vector1.setNull(i);
} else {
vector1.set(i, i * 10000);
vector1.set(i, i * 10000L);
}
}
vector1.setValueCount(10);
Expand All @@ -429,7 +429,7 @@ public void testPopulateTimeStampMilliVector() {
if (i % 2 == 0) {
vector1.setNull(i);
} else {
vector1.set(i, i * 10000);
vector1.set(i, i * 10000L);
}
}
vector1.setValueCount(10);
Expand All @@ -448,7 +448,7 @@ public void testPopulateTimeStampNanoVector() {
if (i % 2 == 0) {
vector1.setNull(i);
} else {
vector1.set(i, i * 10000);
vector1.set(i, i * 10000L);
}
}
vector1.setValueCount(10);
Expand All @@ -467,7 +467,7 @@ public void testPopulateTimeStampSecVector() {
if (i % 2 == 0) {
vector1.setNull(i);
} else {
vector1.set(i, i * 100);
vector1.set(i, i * 100L);
}
}
vector1.setValueCount(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public void testNullCheck() {

/** Test that a custom Location type can be round-tripped through a temporary file. */
@Test
@SuppressWarnings("FloatingPointLiteralPrecision")
public void roundtripLocation() throws IOException {
ExtensionTypeRegistry.register(new LocationType());
final Schema schema =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class TestValidator {

@Test
@SuppressWarnings("FloatingPointLiteralPrecision")
public void testFloatComp() {
assertTrue(equalEnough(912.4140000000002F, 912.414F));
assertTrue(equalEnough(912.4140000000002D, 912.414D));
Expand Down

0 comments on commit ab93ca8

Please sign in to comment.