|
17 | 17 |
|
18 | 18 | package org.apache.arrow.vector.ipc; |
19 | 19 |
|
| 20 | +import static org.junit.Assert.assertEquals; |
| 21 | + |
20 | 22 | import java.io.File; |
21 | 23 | import java.io.IOException; |
22 | 24 |
|
23 | 25 | import org.apache.arrow.memory.BufferAllocator; |
24 | 26 | 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; |
25 | 30 | import org.apache.arrow.vector.VectorSchemaRoot; |
26 | 31 | import org.apache.arrow.vector.complex.StructVector; |
27 | 32 | import org.apache.arrow.vector.complex.impl.ComplexWriterImpl; |
@@ -401,4 +406,39 @@ public void testWriteReadMapJSON() throws IOException { |
401 | 406 | reader.close(); |
402 | 407 | } |
403 | 408 | } |
| 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 | + } |
404 | 444 | } |
0 commit comments