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;
}
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();
}
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);
}
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());
}
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);
}
Aggregations