Search in sources :

Example 16 with AbstractObjectWriter

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

the class BaseWriterBuilder method buildMap.

private List<AbstractObjectWriter> buildMap(AbstractMapVector vector, VectorDescrip descrip) {
    List<AbstractObjectWriter> writers = new ArrayList<>();
    MetadataProvider provider = descrip.parent.childProvider(descrip.metadata);
    int i = 0;
    for (ValueVector child : vector) {
        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.rowSet.model.MetadataProvider) ArrayList(java.util.ArrayList) VectorDescrip(org.apache.drill.exec.physical.rowSet.model.MetadataProvider.VectorDescrip) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)

Example 17 with AbstractObjectWriter

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

the class DummyWriterTest method testDummyScalar.

/**
 * Test dummy column writers for scalars and arrays of
 * scalars.
 */
@Test
public void testDummyScalar() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addArray("b", MinorType.VARCHAR).buildSchema();
    List<AbstractObjectWriter> writers = new ArrayList<>();
    // We provide no vector. Factory should build us "dummy" writers.
    writers.add(ColumnWriterFactory.buildColumnWriter(schema.metadata("a"), null));
    writers.add(ColumnWriterFactory.buildColumnWriter(schema.metadata("b"), null));
    AbstractTupleWriter rootWriter = new RootWriterFixture(schema, writers);
    // Events are ignored.
    rootWriter.startWrite();
    rootWriter.startRow();
    // At present, dummy writers report no type (because they don't have one.)
    assertNull(rootWriter.scalar(0).valueType());
    // First column. Set int value.
    rootWriter.scalar(0).setInt(10);
    // Dummy writer does not do type checking. Write "wrong" type.
    // Should be allowed.
    rootWriter.scalar("a").setString("foo");
    // Column is required, but writer does no checking. Can set
    // a null value.
    rootWriter.column(0).scalar().setNull();
    // Second column: is an array.
    rootWriter.array(1).scalar().setString("bar");
    rootWriter.array(1).scalar().setString("mumble");
    // Again, type is not checked.
    rootWriter.array("b").scalar().setInt(200);
    // 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) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 18 with AbstractObjectWriter

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

the class BaseWriterBuilder method buildMultiDList.

private AbstractObjectWriter buildMultiDList(RepeatedListVector vector, VectorDescrip descrip) {
    final ValueVector child = vector.getDataVector();
    if (child == null) {
        throw new UnsupportedOperationException("No child vector for repeated list.");
    }
    final VectorDescrip childDescrip = new VectorDescrip(descrip.childProvider(), 0, child.getField());
    final AbstractObjectWriter childWriter = buildVectorWriter(child, childDescrip);
    return RepeatedListWriter.buildRepeatedList(descrip.metadata, vector, childWriter);
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) VectorDescrip(org.apache.drill.exec.physical.resultSet.model.MetadataProvider.VectorDescrip) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)

Example 19 with AbstractObjectWriter

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

the class ColumnBuilder method buildMapArray.

private ColumnState buildMapArray(ContainerState parent, ColumnMetadata columnSchema) {
    final ProjectionFilter projFilter = parent.projection();
    final ProjResult projResult = projFilter.projection(columnSchema);
    // Create the map's offset vector.
    final RepeatedMapVector mapVector;
    final UInt4Vector offsetVector;
    if (projResult.isProjected) {
        // Creating the map vector will create its contained vectors if we
        // give it a materialized field with children. So, instead pass a clone
        // without children so we can add them.
        final ColumnMetadata mapColSchema = columnSchema.cloneEmpty();
        // vectors can be cached.
        assert columnSchema.tupleSchema().isEmpty();
        mapVector = new RepeatedMapVector(mapColSchema.schema(), parent.loader().allocator(), null);
        offsetVector = mapVector.getOffsetVector();
    } else {
        mapVector = null;
        offsetVector = null;
    }
    // Create the writer using the offset vector
    final AbstractObjectWriter writer = MapWriter.buildMapArray(columnSchema, mapVector, new ArrayList<>());
    // Wrap the offset vector in a vector state
    VectorState offsetVectorState;
    if (!projResult.isProjected) {
        offsetVectorState = new NullVectorState();
    } else {
        offsetVectorState = new OffsetVectorState((((AbstractArrayWriter) writer.array()).offsetWriter()), offsetVector, writer.array().entry().events());
    }
    final VectorState mapVectorState = new MapVectorState(mapVector, offsetVectorState);
    // Assemble it all into the column state.
    final MapArrayState mapState = new MapArrayState(parent.loader(), parent.vectorCache().childCache(columnSchema.name()), projResult.mapFilter);
    return new MapColumnState(mapState, writer, mapVectorState, parent.isVersioned());
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) PrimitiveColumnMetadata(org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata) OffsetVectorState(org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.OffsetVectorState) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) ProjResult(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult) MapColumnState(org.apache.drill.exec.physical.resultSet.impl.TupleState.MapColumnState) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) MapVectorState(org.apache.drill.exec.physical.resultSet.impl.TupleState.MapVectorState) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter) MapVectorState(org.apache.drill.exec.physical.resultSet.impl.TupleState.MapVectorState) RepeatedListVectorState(org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListVectorState) UnionVectorState(org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionVectorState) OffsetVectorState(org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.OffsetVectorState) ListVectorState(org.apache.drill.exec.physical.resultSet.impl.ListState.ListVectorState) SimpleVectorState(org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.SimpleVectorState) MapArrayState(org.apache.drill.exec.physical.resultSet.impl.TupleState.MapArrayState)

Example 20 with AbstractObjectWriter

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

the class ColumnBuilder method buildPrimitive.

/**
 * Build a primitive column. Check if the column is projected. If not,
 * allocate a dummy writer for the column. If projected, then allocate
 * a vector, a writer, and the column state which binds the two together
 * and manages the column.
 *
 * @param parent schema of the new primitive column
 * @param columnSchema implied projection type for the column
 * @return column state for the new column
 */
private ColumnState buildPrimitive(ContainerState parent, ColumnMetadata columnSchema) {
    final ValueVector vector;
    if (parent.projection().projection(columnSchema).isProjected || allowCreation(parent)) {
        // Create the vector for the column.
        vector = parent.vectorCache().vectorFor(columnSchema.schema());
        // from that requested. Update the schema to match.
        if (parent.vectorCache().isPermissive() && !vector.getField().isEquivalent(columnSchema.schema())) {
            columnSchema = ((PrimitiveColumnMetadata) columnSchema).mergeWith(vector.getField());
        }
    } else {
        // Column is not projected. No materialized backing for the column.
        vector = null;
    }
    // Create the writer.
    final AbstractObjectWriter colWriter = ColumnWriterFactory.buildColumnWriter(columnSchema, vector);
    // Build the vector state which manages the vector.
    VectorState vectorState;
    if (vector == null) {
        vectorState = new NullVectorState();
    } else if (columnSchema.isArray()) {
        vectorState = new RepeatedVectorState(colWriter.array(), (RepeatedValueVector) vector);
    } else if (columnSchema.isNullable()) {
        vectorState = new NullableVectorState(colWriter, (NullableVector) vector);
    } else {
        vectorState = SimpleVectorState.vectorState(columnSchema, colWriter.events(), vector);
    }
    // Create the column state which binds the vector and writer together.
    return new PrimitiveColumnState(parent.loader(), colWriter, vectorState);
}
Also used : RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) ValueVector(org.apache.drill.exec.vector.ValueVector) NullableVector(org.apache.drill.exec.vector.NullableVector) PrimitiveColumnState(org.apache.drill.exec.physical.resultSet.impl.ColumnState.PrimitiveColumnState) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter) MapVectorState(org.apache.drill.exec.physical.resultSet.impl.TupleState.MapVectorState) RepeatedListVectorState(org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListVectorState) UnionVectorState(org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionVectorState) OffsetVectorState(org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.OffsetVectorState) ListVectorState(org.apache.drill.exec.physical.resultSet.impl.ListState.ListVectorState) SimpleVectorState(org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.SimpleVectorState)

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