ArrowConverter { public static List<FieldVector> convertToArrowVector(INDArray from,List<String> name,ColumnType type,BufferAllocator bufferAllocator) { List<FieldVector> ret = new ArrayList<>(); if(from.isVector()) { long cols = from.length(); switch(type) { case Double: double[] fromData = from.isView() ? from.dup().data().asDouble() : from.data().asDouble(); ret.add(vectorFor(bufferAllocator,name.get(0),fromData)); break; case Float: float[] fromDataFloat = from.isView() ? from.dup().data().asFloat() : from.data().asFloat(); ret.add(vectorFor(bufferAllocator,name.get(0),fromDataFloat)); break; case Integer: int[] fromDataInt = from.isView() ? from.dup().data().asInt() : from.data().asInt(); ret.add(vectorFor(bufferAllocator,name.get(0),fromDataInt)); break; default: throw new IllegalArgumentException("Illegal type " + type); } } else { long cols = from.size(1); for(int i = 0; i < cols; i++) { INDArray column = from.getColumn(i); switch(type) { case Double: double[] fromData = column.isView() ? column.dup().data().asDouble() : from.data().asDouble(); ret.add(vectorFor(bufferAllocator,name.get(i),fromData)); break; case Float: float[] fromDataFloat = column.isView() ? column.dup().data().asFloat() : from.data().asFloat(); ret.add(vectorFor(bufferAllocator,name.get(i),fromDataFloat)); break; case Integer: int[] fromDataInt = column.isView() ? column.dup().data().asInt() : from.data().asInt(); ret.add(vectorFor(bufferAllocator,name.get(i),fromDataInt)); break; default: throw new IllegalArgumentException("Illegal type " + type); } } } return ret; }  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 testConvertToArrowVectors() { INDArray matrix = Nd4j.linspace(1,4,4).reshape(2,2); val vectors = ArrowConverter.convertToArrowVector(matrix,Arrays.asList("test","test2"), ColumnType.Double,bufferAllocator); assertEquals(matrix.rows(),vectors.size()); INDArray vector = Nd4j.linspace(1,4,4); val vectors2 = ArrowConverter.convertToArrowVector(vector,Arrays.asList("test"), ColumnType.Double,bufferAllocator); assertEquals(1,vectors2.size()); assertEquals(matrix.length(),vectors2.get(0).getValueCount()); }