Search in sources :

Example 1 with ArrowFileWriter

use of org.apache.arrow.vector.ipc.ArrowFileWriter in project twister2 by DSC-SPIDAL.

the class Twister2ArrowFileWriter method setUpTwister2ArrowWrite.

public boolean setUpTwister2ArrowWrite(int workerId) throws Exception {
    LOG.fine("%%%%%%%%% worker id details:" + workerId + "\t" + arrowFile);
    this.root = VectorSchemaRoot.create(Schema.fromJSON(arrowSchema), this.rootAllocator);
    Path path = new Path(arrowFile);
    this.fileSystem = FileSystemUtils.get(path);
    this.fsDataOutputStream = fileSystem.create(path);
    this.twister2ArrowOutputStream = new Twister2ArrowOutputStream(this.fsDataOutputStream);
    DictionaryProvider.MapDictionaryProvider provider = new DictionaryProvider.MapDictionaryProvider();
    if (!flag) {
        this.arrowFileWriter = new ArrowFileWriter(root, provider, this.fsDataOutputStream.getChannel());
    } else {
        this.arrowFileWriter = new ArrowFileWriter(root, provider, this.twister2ArrowOutputStream);
    }
    LOG.info("root schema fields:" + root.getSchema().getFields());
    for (Field field : root.getSchema().getFields()) {
        FieldVector vector = root.getVector(field.getName());
        if (vector.getMinorType().equals(Types.MinorType.INT)) {
            this.generatorMap.put(vector, new IntVectorGenerator());
        } else if (vector.getMinorType().equals(Types.MinorType.BIGINT)) {
            this.generatorMap.put(vector, new BigIntVectorGenerator());
        } else if (vector.getMinorType().equals(Types.MinorType.FLOAT4)) {
            this.generatorMap.put(vector, new FloatVectorGenerator());
        } else {
            throw new RuntimeException("unsupported arrow write type");
        }
    }
    return true;
}
Also used : Path(edu.iu.dsc.tws.api.data.Path) Field(org.apache.arrow.vector.types.pojo.Field) DictionaryProvider(org.apache.arrow.vector.dictionary.DictionaryProvider) ArrowFileWriter(org.apache.arrow.vector.ipc.ArrowFileWriter) FieldVector(org.apache.arrow.vector.FieldVector)

Aggregations

Path (edu.iu.dsc.tws.api.data.Path)1 FieldVector (org.apache.arrow.vector.FieldVector)1 DictionaryProvider (org.apache.arrow.vector.dictionary.DictionaryProvider)1 ArrowFileWriter (org.apache.arrow.vector.ipc.ArrowFileWriter)1 Field (org.apache.arrow.vector.types.pojo.Field)1