Search in sources :

Example 1 with AbstractObjectWriter

use of org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter in project drill by axbaretto.

the class BaseWriterBuilder method buildContainerChildren.

protected List<AbstractObjectWriter> buildContainerChildren(VectorContainer container, MetadataProvider mdProvider) {
    List<AbstractObjectWriter> writers = new ArrayList<>();
    for (int i = 0; i < container.getNumberOfColumns(); i++) {
        @SuppressWarnings("resource") ValueVector vector = container.getValueVector(i).getValueVector();
        VectorDescrip descrip = new VectorDescrip(mdProvider, i, vector.getField());
        writers.add(buildVectorWriter(vector, descrip));
    }
    return writers;
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) ArrayList(java.util.ArrayList) VectorDescrip(org.apache.drill.exec.physical.rowSet.model.MetadataProvider.VectorDescrip) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)

Example 2 with AbstractObjectWriter

use of org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter in project drill by axbaretto.

the class DummyWriterTest method testDummyMap.

/**
 * Test a dummy map or map array. A (non-enforced) rule is that such maps
 * contain only dummy writers. The writers act like "real" writers.
 */
@Test
public void testDummyMap() {
    TupleMetadata schema = new SchemaBuilder().addMap("m1").add("a", MinorType.INT).addArray("b", MinorType.VARCHAR).resumeSchema().addMapArray("m2").add("c", MinorType.INT).resumeSchema().buildSchema();
    List<AbstractObjectWriter> writers = new ArrayList<>();
    {
        schema.metadata("m1").setProjected(false);
        TupleMetadata mapSchema = schema.metadata("m1").mapSchema();
        List<AbstractObjectWriter> members = new ArrayList<>();
        members.add(ColumnWriterFactory.buildColumnWriter(mapSchema.metadata("a"), null));
        members.add(ColumnWriterFactory.buildColumnWriter(mapSchema.metadata("b"), null));
        writers.add(ColumnWriterFactory.buildMapWriter(schema.metadata("m1"), null, members));
    }
    {
        schema.metadata("m2").setProjected(false);
        TupleMetadata mapSchema = schema.metadata("m2").mapSchema();
        List<AbstractObjectWriter> members = new ArrayList<>();
        members.add(ColumnWriterFactory.buildColumnWriter(mapSchema.metadata("c"), null));
        writers.add(ColumnWriterFactory.buildMapWriter(schema.metadata("m2"), null, members));
    }
    AbstractTupleWriter rootWriter = new RootWriterFixture(schema, writers);
    // Events are ignored.
    rootWriter.startWrite();
    rootWriter.startRow();
    // Dummy columns seem real.
    rootWriter.tuple("m1").scalar("a").setInt(20);
    rootWriter.tuple(0).array("b").scalar().setString("foo");
    // Dummy array map seems real.
    rootWriter.array("m2").tuple().scalar("c").setInt(30);
    rootWriter.array("m2").save();
    rootWriter.array(1).tuple().scalar(0).setInt(40);
    rootWriter.array(1).save();
    // More ignored events.
    rootWriter.restartRow();
    rootWriter.saveRow();
    rootWriter.endWrite();
}
Also used : AbstractTupleWriter(org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 3 with AbstractObjectWriter

use of org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter in project drill by apache.

the class BaseWriterBuilder method buildContainerChildren.

protected List<AbstractObjectWriter> buildContainerChildren(VectorContainer container, MetadataProvider mdProvider) {
    final List<AbstractObjectWriter> writers = new ArrayList<>();
    for (int i = 0; i < container.getNumberOfColumns(); i++) {
        final ValueVector vector = container.getValueVector(i).getValueVector();
        final VectorDescrip descrip = new VectorDescrip(mdProvider, i, vector.getField());
        writers.add(buildVectorWriter(vector, descrip));
    }
    return writers;
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) ArrayList(java.util.ArrayList) VectorDescrip(org.apache.drill.exec.physical.resultSet.model.MetadataProvider.VectorDescrip) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)

Example 4 with AbstractObjectWriter

use of org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter in project drill by apache.

the class BaseWriterBuilder method buildMap.

private List<AbstractObjectWriter> buildMap(AbstractMapVector vector, VectorDescrip descrip) {
    final List<AbstractObjectWriter> writers = new ArrayList<>();
    final MetadataProvider provider = descrip.parent.childProvider(descrip.metadata);
    int i = 0;
    for (final ValueVector child : vector) {
        final VectorDescrip childDescrip = new VectorDescrip(provider, i, child.getField());
        writers.add(buildVectorWriter(child, childDescrip));
        i++;
    }
    return writers;
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) MetadataProvider(org.apache.drill.exec.physical.resultSet.model.MetadataProvider) ArrayList(java.util.ArrayList) VectorDescrip(org.apache.drill.exec.physical.resultSet.model.MetadataProvider.VectorDescrip) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)

Example 5 with AbstractObjectWriter

use of org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter in project drill by apache.

the class BaseWriterBuilder method buildDict.

private AbstractObjectWriter buildDict(ValueVector vector, VectorDescrip descrip) {
    if (vector.getField().getType().getMode() == DataMode.REPEATED) {
        ValueVector dataVector = ((RepeatedDictVector) vector).getDataVector();
        List<AbstractObjectWriter> writers = buildMap((AbstractMapVector) dataVector, descrip);
        return ObjectDictWriter.buildDictArray(descrip.metadata, (RepeatedDictVector) vector, writers);
    } else {
        List<AbstractObjectWriter> writers = buildMap((AbstractMapVector) vector, descrip);
        return ObjectDictWriter.buildDict(descrip.metadata, (DictVector) vector, writers);
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) RepeatedDictVector(org.apache.drill.exec.vector.complex.RepeatedDictVector) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)

Aggregations

AbstractObjectWriter (org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)21 ArrayList (java.util.ArrayList)9 ValueVector (org.apache.drill.exec.vector.ValueVector)9 RepeatedListVectorState (org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListVectorState)7 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)7 ListVectorState (org.apache.drill.exec.physical.resultSet.impl.ListState.ListVectorState)6 PrimitiveColumnMetadata (org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata)5 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)5 AbstractTupleWriter (org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter)5 SubOperatorTest (org.apache.drill.test.SubOperatorTest)5 Test (org.junit.Test)5 OffsetVectorState (org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.OffsetVectorState)4 SimpleVectorState (org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.SimpleVectorState)4 MapVectorState (org.apache.drill.exec.physical.resultSet.impl.TupleState.MapVectorState)4 UnionVectorState (org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionVectorState)4 VectorDescrip (org.apache.drill.exec.physical.resultSet.model.MetadataProvider.VectorDescrip)4 ProjResult (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult)3 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)3 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)3 RepeatedDictVector (org.apache.drill.exec.vector.complex.RepeatedDictVector)3