ArrowConverter { public static TimeStampMilliVector vectorFor(BufferAllocator allocator,String name,Date[] data) { TimeStampMilliVector float4Vector = new TimeStampMilliVector(name,allocator); float4Vector.allocateNew(data.length); for(int i = 0; i < data.length; i++) { float4Vector.setSafe(i,data[i].getTime()); } float4Vector.setValueCount(data.length); return float4Vector; }  static INDArray toArray(ArrowWritableRecordTimeSeriesBatch arrowWritableRecordBatch); static INDArray toArray(ArrowWritableRecordBatch arrowWritableRecordBatch); static INDArray convertArrowVector(FieldVector fieldVector,ColumnType type); static List<FieldVector> convertToArrowVector(INDArray from,List<String> name,ColumnType type,BufferAllocator bufferAllocator); static void writeRecordBatchTo(List<List<Writable>> recordBatch, Schema inputSchema,OutputStream outputStream); static void writeRecordBatchTo(BufferAllocator bufferAllocator ,List<List<Writable>> recordBatch, Schema inputSchema,OutputStream outputStream); static List<List<List<Writable>>> toArrowWritablesTimeSeries(List<FieldVector> fieldVectors,Schema schema,int timeSeriesLength); static ArrowWritableRecordBatch toArrowWritables(List<FieldVector> fieldVectors,Schema schema); static List<Writable> toArrowWritablesSingle(List<FieldVector> fieldVectors,Schema schema); static Pair<Schema,ArrowWritableRecordBatch> readFromFile(FileInputStream input); static Pair<Schema,ArrowWritableRecordBatch> readFromFile(File input); static Pair<Schema,ArrowWritableRecordBatch> readFromBytes(byte[] input); static org.apache.arrow.vector.types.pojo.Schema toArrowSchema(Schema schema); static Schema toDatavecSchema(org.apache.arrow.vector.types.pojo.Schema schema); static Field field(String name,ArrowType arrowType); static Field getFieldForColumn(String name,ColumnType columnType); static Field doubleField(String name); static Field floatField(String name); static Field intField(String name); static Field longField(String name); static Field stringField(String name); static Field booleanField(String name); static DictionaryProvider providerForVectors(List<FieldVector> vectors,List<Field> fields); static List<FieldVector> toArrowColumns(final BufferAllocator bufferAllocator, final Schema schema, List<List<Writable>> dataVecRecord); static List<FieldVector> toArrowColumnsTimeSeries(final BufferAllocator bufferAllocator,
                                                              final Schema schema,
                                                              List<List<List<Writable>>> dataVecRecord); static List<FieldVector> toArrowColumnsTimeSeriesHelper(final BufferAllocator bufferAllocator,
                                                                        final Schema schema,
                                                                        List<List<List<T>>> dataVecRecord); static List<FieldVector> toArrowColumnsStringSingle(final BufferAllocator bufferAllocator, final Schema schema, List<String> dataVecRecord); static List<FieldVector> toArrowColumnsStringTimeSeries(final BufferAllocator bufferAllocator,
                                                                    final Schema schema,
                                                                    List<List<List<String>>> dataVecRecord); static List<FieldVector> toArrowColumnsString(final BufferAllocator bufferAllocator, final Schema schema, List<List<String>> dataVecRecord); static void setValue(ColumnType columnType,FieldVector fieldVector,Object value,int row); static TimeStampMilliVector vectorFor(BufferAllocator allocator,String name,Date[] data); static TimeStampMilliVector timeVectorOf(BufferAllocator allocator,String name,int length); static VarCharVector vectorFor(BufferAllocator allocator,String name,String[] data); static VarCharVector stringVectorOf(BufferAllocator allocator,String name,int length); static Float4Vector vectorFor(BufferAllocator allocator,String name,float[] data); static Float4Vector floatVectorOf(BufferAllocator allocator,String name,int length); static Float8Vector vectorFor(BufferAllocator allocator,String name,double[] data); static Float8Vector doubleVectorOf(BufferAllocator allocator,String name,int length); static BitVector vectorFor(BufferAllocator allocator,String name,boolean[] data); static BitVector booleanVectorOf(BufferAllocator allocator,String name,int length); static IntVector vectorFor(BufferAllocator allocator,String name,int[] data); static IntVector intVectorOf(BufferAllocator allocator,String name,int length); static BigIntVector vectorFor(BufferAllocator allocator,String name,long[] data); static BigIntVector longVectorOf(BufferAllocator allocator,String name,int length); static Writable fromEntry(int item,FieldVector from,ColumnType columnType);  }
@Test public void testVectorForEdgeCases() { BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); val vector = ArrowConverter.vectorFor(allocator,"field1",new float[]{Float.MIN_VALUE,Float.MAX_VALUE}); assertEquals(Float.MIN_VALUE,vector.get(0),1e-2); assertEquals(Float.MAX_VALUE,vector.get(1),1e-2); val vectorInt = ArrowConverter.vectorFor(allocator,"field1",new int[]{Integer.MIN_VALUE,Integer.MAX_VALUE}); assertEquals(Integer.MIN_VALUE,vectorInt.get(0),1e-2); assertEquals(Integer.MAX_VALUE,vectorInt.get(1),1e-2); }
@Test public void testVectorFor() { BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); val vector = ArrowConverter.vectorFor(allocator,"field1",new float[]{1,2,3}); assertEquals(3,vector.getValueCount()); assertEquals(1,vector.get(0),1e-2); assertEquals(2,vector.get(1),1e-2); assertEquals(3,vector.get(2),1e-2); val vectorLong = ArrowConverter.vectorFor(allocator,"field1",new long[]{1,2,3}); assertEquals(3,vectorLong.getValueCount()); assertEquals(1,vectorLong.get(0),1e-2); assertEquals(2,vectorLong.get(1),1e-2); assertEquals(3,vectorLong.get(2),1e-2); val vectorInt = ArrowConverter.vectorFor(allocator,"field1",new int[]{1,2,3}); assertEquals(3,vectorInt.getValueCount()); assertEquals(1,vectorInt.get(0),1e-2); assertEquals(2,vectorInt.get(1),1e-2); assertEquals(3,vectorInt.get(2),1e-2); val vectorDouble = ArrowConverter.vectorFor(allocator,"field1",new double[]{1,2,3}); assertEquals(3,vectorDouble.getValueCount()); assertEquals(1,vectorDouble.get(0),1e-2); assertEquals(2,vectorDouble.get(1),1e-2); assertEquals(3,vectorDouble.get(2),1e-2); val vectorBool = ArrowConverter.vectorFor(allocator,"field1",new boolean[]{true,true,false}); assertEquals(3,vectorBool.getValueCount()); assertEquals(1,vectorBool.get(0),1e-2); assertEquals(1,vectorBool.get(1),1e-2); assertEquals(0,vectorBool.get(2),1e-2); }
@Test public void testDates() { Date now = new Date(); BufferAllocator bufferAllocator = new RootAllocator(Long.MAX_VALUE); TimeStampMilliVector timeStampMilliVector = ArrowConverter.vectorFor(bufferAllocator, "col1", new Date[]{now}); assertEquals(now.getTime(),timeStampMilliVector.get(0)); }