org.datavec.arrow.recordreader.ArrowRecordWriter Java Examples

The following examples show how to use org.datavec.arrow.recordreader.ArrowRecordWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArrowBinaryInputAdapterTest.java    From konduit-serving with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)

    public void testArrowBinary() throws Exception {
        Schema irisInputSchema = TrainUtils.getIrisInputSchema();
        ArrowRecordWriter arrowRecordWriter = new ArrowRecordWriter(irisInputSchema);
        CSVRecordReader reader = new CSVRecordReader();
        reader.initialize(new FileSplit(new ClassPathResource("iris.txt").getFile()));
        List<List<Writable>> writables = reader.next(150);

        File tmpFile = new File(temporary.getRoot(), "tmp.arrow");
        FileSplit fileSplit = new FileSplit(tmpFile);
        arrowRecordWriter.initialize(fileSplit, new NumberOfRecordsPartitioner());
        arrowRecordWriter.writeBatch(writables);
        byte[] arrowBytes = FileUtils.readFileToByteArray(tmpFile);

        Buffer buffer = Buffer.buffer(arrowBytes);
        ArrowBinaryInputAdapter arrowBinaryInputAdapter = new ArrowBinaryInputAdapter();
        ArrowWritableRecordBatch convert = arrowBinaryInputAdapter.convert(buffer, ConverterArgs.builder().schema(irisInputSchema).build(), null);
        assertEquals(writables.size(), convert.size());
    }
 
Example #2
Source File: BatchInputParserMultiRecordTest.java    From konduit-serving with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void runAdd(TestContext testContext) throws Exception {
    BatchInputArrowParserVerticle verticleRef = (BatchInputArrowParserVerticle) verticle;
    Schema irisInputSchema = TrainUtils.getIrisInputSchema();
    ArrowRecordWriter arrowRecordWriter = new ArrowRecordWriter(irisInputSchema);
    CSVRecordReader reader = new CSVRecordReader();
    reader.initialize(new FileSplit(new ClassPathResource("iris.txt").getFile()));
    List<List<Writable>> writables = reader.next(150);

    File tmpFile = new File(temporary.getRoot(), "tmp.arrow");
    FileSplit fileSplit = new FileSplit(tmpFile);
    arrowRecordWriter.initialize(fileSplit, new NumberOfRecordsPartitioner());
    arrowRecordWriter.writeBatch(writables);

    given().port(port)
            .multiPart("input1", tmpFile)
            .when().post("/")
            .then().statusCode(200);

    testContext.assertNotNull(verticleRef.getBatch(), "Inputs were null. This means parsing failed.");
    testContext.assertTrue(verticleRef.getBatch().length >= 1);
    testContext.assertNotNull(verticleRef.getBatch());
    testContext.assertEquals(150, verticleRef.getBatch().length);
}
 
Example #3
Source File: RecordMapperTest.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Test
public void testCopyFromCsvToArrow() throws Exception {
    val recordsPair = records();

    Path p = Files.createTempFile("csvwritetest", ".csv");
    FileUtils.write(p.toFile(),recordsPair.getFirst());
    p.toFile().deleteOnExit();


    CSVRecordReader recordReader = new CSVRecordReader();
    FileSplit fileSplit = new FileSplit(p.toFile());

    ArrowRecordWriter arrowRecordWriter = new ArrowRecordWriter(recordsPair.getMiddle());
    File outputFile = Files.createTempFile("outputarrow","arrow").toFile();
    FileSplit outputFileSplit = new FileSplit(outputFile);
    RecordMapper mapper = RecordMapper.builder().batchSize(10).inputUrl(fileSplit)
            .outputUrl(outputFileSplit).partitioner(new NumberOfRecordsPartitioner())
            .recordReader(recordReader).recordWriter(arrowRecordWriter)
            .build();
    mapper.copy();

    ArrowRecordReader arrowRecordReader = new ArrowRecordReader();
    arrowRecordReader.initialize(outputFileSplit);
    List<List<Writable>> next = arrowRecordReader.next(10);
    System.out.println(next);
    assertEquals(10,next.size());

}
 
Example #4
Source File: RecordMapperTest.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testCopyFromCsvToArrow() throws Exception {
    val recordsPair = records();

    Path p = Files.createTempFile("csvwritetest", ".csv");
    FileUtils.write(p.toFile(),recordsPair.getFirst());
    p.toFile().deleteOnExit();


    CSVRecordReader recordReader = new CSVRecordReader();
    FileSplit fileSplit = new FileSplit(p.toFile());

    ArrowRecordWriter arrowRecordWriter = new ArrowRecordWriter(recordsPair.getMiddle());
    File outputFile = Files.createTempFile("outputarrow","arrow").toFile();
    FileSplit outputFileSplit = new FileSplit(outputFile);
    RecordMapper mapper = RecordMapper.builder().batchSize(10).inputUrl(fileSplit)
            .outputUrl(outputFileSplit).partitioner(new NumberOfRecordsPartitioner())
            .recordReader(recordReader).recordWriter(arrowRecordWriter)
            .build();
    mapper.copy();

    ArrowRecordReader arrowRecordReader = new ArrowRecordReader();
    arrowRecordReader.initialize(outputFileSplit);
    List<List<Writable>> next = arrowRecordReader.next(10);
    System.out.println(next);
    assertEquals(10,next.size());

}