Skip to content

Commit 1430979

Browse files
committed
ARROW-6218: [Java] Add UINT type test in integration to avoid potential overflow
1 parent 1a3eab5 commit 1430979

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

java/vector/src/test/java/org/apache/arrow/vector/ipc/TestJSONFile.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717

1818
package org.apache.arrow.vector.ipc;
1919

20+
import static org.junit.Assert.assertEquals;
21+
2022
import java.io.File;
2123
import java.io.IOException;
2224

2325
import org.apache.arrow.memory.BufferAllocator;
2426
import org.apache.arrow.vector.FieldVector;
27+
import org.apache.arrow.vector.UInt1Vector;
28+
import org.apache.arrow.vector.UInt4Vector;
29+
import org.apache.arrow.vector.UInt8Vector;
2530
import org.apache.arrow.vector.VectorSchemaRoot;
2631
import org.apache.arrow.vector.complex.StructVector;
2732
import org.apache.arrow.vector.complex.impl.ComplexWriterImpl;
@@ -401,4 +406,39 @@ public void testWriteReadMapJSON() throws IOException {
401406
reader.close();
402407
}
403408
}
409+
410+
@Test
411+
public void testNoOverFlowWithUINT() {
412+
try (final UInt8Vector uInt8Vector = new UInt8Vector("uint8", allocator);
413+
final UInt4Vector uInt4Vector = new UInt4Vector("uint4", allocator);
414+
final UInt1Vector uInt1Vector = new UInt1Vector("uint1", allocator)) {
415+
416+
long[] longValues = new long[]{0x8000000000000000L, 0x7fffffffffffffffL, 0xffffffffffffffffL};
417+
uInt8Vector.allocateNew(3);
418+
uInt8Vector.setValueCount(3);
419+
for (int i = 0; i < longValues.length; i++) {
420+
uInt8Vector.set(i, longValues[i]);
421+
long readValue = uInt8Vector.getObjectNoOverflow(i).longValue();
422+
assertEquals(readValue, longValues[i]);
423+
}
424+
425+
int[] intValues = new int[]{0x80000000, 0x7fffffff, 0xffffffff};
426+
uInt4Vector.allocateNew(3);
427+
uInt4Vector.setValueCount(3);
428+
for (int i = 0; i < intValues.length; i++) {
429+
uInt4Vector.set(i, intValues[i]);
430+
int actualValue = (int) UInt4Vector.getNoOverflow(uInt4Vector.getDataBuffer(), i);
431+
assertEquals(intValues[i], actualValue);
432+
}
433+
434+
byte[] byteValues = new byte[]{-128, 127, -1};
435+
uInt1Vector.allocateNew(3);
436+
uInt1Vector.setValueCount(3);
437+
for (int i = 0; i < byteValues.length; i++) {
438+
uInt1Vector.set(i, byteValues[i]);
439+
byte actualValue = (byte) UInt1Vector.getNoOverflow(uInt1Vector.getDataBuffer(),i);
440+
assertEquals(byteValues[i], actualValue);
441+
}
442+
}
443+
}
404444
}

0 commit comments

Comments
 (0)