You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by pr...@apache.org on 2019/08/13 09:04:09 UTC

[arrow] branch master updated: ARROW-6218: [Java] Add UINT type test in integration to avoid potential overflow

This is an automated email from the ASF dual-hosted git repository.

praveenbingo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new c79f06c  ARROW-6218: [Java] Add UINT type test in integration to avoid potential overflow
c79f06c is described below

commit c79f06c56fcbdb5d6b71b8fb171eb92719bbd666
Author: tianchen <ni...@alibaba-inc.com>
AuthorDate: Tue Aug 13 14:33:53 2019 +0530

    ARROW-6218: [Java] Add UINT type test in integration to avoid potential overflow
    
    Related to [ARROW-6218](https://issues.apache.org/jira/browse/ARROW-6218).
    As per discussion https://github.com/apache/arrow/pull/5002
    
    For UINT type, when write/read json data in integration test, it extend data type(i.e. Long->BigInteger, Int->Long) to avoid potential overflow.
    
    Like UINT8 the write side and read side code like this:
    >case UINT8:
      generator.writeNumber(UInt8Vector.getNoOverflow(buffer, index));
      break;
    
    >BigInteger value = parser.getBigIntegerValue();
    buf.writeLong(value.longValue());
    
    Should add a test to avoid potential overflow in the data transfer process.
    
    Closes #5072 from tianchen92/ARROW-6218 and squashes the following commits:
    
    2bdbe7e09 <tianchen> use MIN_VALUE and MAX_VALUE
    1430979b4 <tianchen> ARROW-6218:  Add UINT type test in integration to avoid potential overflow
    
    Authored-by: tianchen <ni...@alibaba-inc.com>
    Signed-off-by: Praveen <pr...@dremio.com>
---
 .../org/apache/arrow/vector/ipc/TestJSONFile.java  | 40 ++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestJSONFile.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestJSONFile.java
index b482725..467d40c 100644
--- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestJSONFile.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/TestJSONFile.java
@@ -17,11 +17,16 @@
 
 package org.apache.arrow.vector.ipc;
 
+import static org.junit.Assert.assertEquals;
+
 import java.io.File;
 import java.io.IOException;
 
 import org.apache.arrow.memory.BufferAllocator;
 import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.UInt1Vector;
+import org.apache.arrow.vector.UInt4Vector;
+import org.apache.arrow.vector.UInt8Vector;
 import org.apache.arrow.vector.VectorSchemaRoot;
 import org.apache.arrow.vector.complex.StructVector;
 import org.apache.arrow.vector.complex.impl.ComplexWriterImpl;
@@ -401,4 +406,39 @@ public class TestJSONFile extends BaseFileTest {
       reader.close();
     }
   }
+
+  @Test
+  public void testNoOverFlowWithUINT() {
+    try (final UInt8Vector uInt8Vector = new UInt8Vector("uint8", allocator);
+        final UInt4Vector uInt4Vector = new UInt4Vector("uint4", allocator);
+        final UInt1Vector uInt1Vector = new UInt1Vector("uint1", allocator)) {
+
+      long[] longValues = new long[]{Long.MIN_VALUE, Long.MAX_VALUE, -1L};
+      uInt8Vector.allocateNew(3);
+      uInt8Vector.setValueCount(3);
+      for (int i = 0; i < longValues.length; i++) {
+        uInt8Vector.set(i, longValues[i]);
+        long readValue = uInt8Vector.getObjectNoOverflow(i).longValue();
+        assertEquals(readValue, longValues[i]);
+      }
+
+      int[] intValues = new int[]{Integer.MIN_VALUE, Integer.MAX_VALUE, -1};
+      uInt4Vector.allocateNew(3);
+      uInt4Vector.setValueCount(3);
+      for (int i = 0; i < intValues.length; i++) {
+        uInt4Vector.set(i, intValues[i]);
+        int actualValue = (int) UInt4Vector.getNoOverflow(uInt4Vector.getDataBuffer(), i);
+        assertEquals(intValues[i], actualValue);
+      }
+
+      byte[] byteValues = new byte[]{Byte.MIN_VALUE, Byte.MAX_VALUE, -1};
+      uInt1Vector.allocateNew(3);
+      uInt1Vector.setValueCount(3);
+      for (int i = 0; i < byteValues.length; i++) {
+        uInt1Vector.set(i, byteValues[i]);
+        byte actualValue = (byte) UInt1Vector.getNoOverflow(uInt1Vector.getDataBuffer(),i);
+        assertEquals(byteValues[i], actualValue);
+      }
+    }
+  }
 }