use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by axbaretto.
the class VectorContainerBuilder method buildMap.
@SuppressWarnings("resource")
private void buildMap(TupleProxy parentTuple, BaseMapColumnState colModel) {
// 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.
ColumnMetadata mapColSchema = colModel.schema().cloneEmpty();
// Don't get the map vector from the vector cache. Map vectors may
// have content that varies from batch to batch. Only the leaf
// vectors can be cached.
AbstractMapVector mapVector;
if (mapColSchema.isArray()) {
// A repeated map shares an offset vector with the internal
// repeated map.
UInt4Vector offsets = (UInt4Vector) colModel.vector();
mapVector = new RepeatedMapVector(mapColSchema.schema(), offsets, null);
} else {
mapVector = new MapVector(mapColSchema.schema(), allocator(), null);
}
// Add the map vector and schema to the parent tuple
parentTuple.add(mapVector);
int index = parentTuple.schema.addColumn(mapColSchema);
assert parentTuple.size() == parentTuple.size();
// Update the tuple, which will add the new columns in the map
updateTuple(colModel.mapState(), parentTuple.mapProxy(index));
}
use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by axbaretto.
the class SchemaInference method infer.
public TupleMetadata infer(VectorContainer container) {
List<ColumnMetadata> columns = new ArrayList<>();
for (int i = 0; i < container.getNumberOfColumns(); i++) {
MaterializedField field = container.getValueVector(i).getField();
columns.add(inferVector(field));
}
return MetadataUtils.fromColumns(columns);
}
use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by axbaretto.
the class TestTupleSchema method testEmptyRootTuple.
// Repeated list
/**
* Test the basics of an empty root tuple (i.e. row) schema.
*/
@Test
public void testEmptyRootTuple() {
TupleMetadata root = new TupleSchema();
assertEquals(0, root.size());
assertTrue(root.isEmpty());
assertEquals(-1, root.index("foo"));
try {
root.metadata(0);
fail();
} catch (IndexOutOfBoundsException e) {
// Expected
}
assertNull(root.metadata("foo"));
try {
root.column(0);
fail();
} catch (IndexOutOfBoundsException e) {
// Expected
}
assertNull(root.column("foo"));
try {
root.fullName(0);
fail();
} catch (IndexOutOfBoundsException e) {
// Expected
}
// The full name method does not check if the column is actually
// in the tuple.
MaterializedField field = SchemaBuilder.columnSchema("c", MinorType.INT, DataMode.REQUIRED);
ColumnMetadata col = MetadataUtils.fromField(field);
assertEquals("c", root.fullName(col));
assertTrue(root.isEquivalent(root));
assertNull(root.parent());
assertTrue(root.toFieldList().isEmpty());
}
use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by axbaretto.
the class TestTupleSchema method testDecimalScalePrecision.
@Test
public void testDecimalScalePrecision() {
MaterializedField field = MaterializedField.create("d", MajorType.newBuilder().setMinorType(MinorType.DECIMAL9).setMode(DataMode.REQUIRED).setPrecision(3).setScale(4).build());
ColumnMetadata col = MetadataUtils.fromField(field);
assertFalse(col.isNullable());
assertFalse(col.isArray());
assertFalse(col.isVariableWidth());
assertFalse(col.isMap());
assertFalse(col.isVariant());
assertEquals(3, col.precision());
assertEquals(4, col.scale());
assertTrue(field.isEquivalent(col.schema()));
}
use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by axbaretto.
the class TestTupleSchema method testRepeatedMapColumn.
@Test
public void testRepeatedMapColumn() {
MaterializedField field = SchemaBuilder.columnSchema("m", MinorType.MAP, DataMode.REPEATED);
ColumnMetadata col = MetadataUtils.fromField(field);
assertTrue(col instanceof MapColumnMetadata);
assertNotNull(col.mapSchema());
assertEquals(0, col.mapSchema().size());
assertFalse(col.isNullable());
assertTrue(col.isArray());
assertFalse(col.isVariableWidth());
assertTrue(col.isMap());
assertFalse(col.isVariant());
assertEquals(0, col.expectedWidth());
col.setExpectedWidth(10);
assertEquals(0, col.expectedWidth());
assertEquals(ColumnMetadata.DEFAULT_ARRAY_SIZE, col.expectedElementCount());
col.setExpectedElementCount(2);
assertEquals(2, col.expectedElementCount());
}
Aggregations