Search in sources :

Example 1 with ColumnMetadata

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));
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) AbstractMapVector(org.apache.drill.exec.vector.complex.AbstractMapVector) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) MapVector(org.apache.drill.exec.vector.complex.MapVector) AbstractMapVector(org.apache.drill.exec.vector.complex.AbstractMapVector)

Example 2 with ColumnMetadata

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);
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) ArrayList(java.util.ArrayList) MaterializedField(org.apache.drill.exec.record.MaterializedField)

Example 3 with ColumnMetadata

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());
}
Also used : MapColumnMetadata(org.apache.drill.exec.record.metadata.MapColumnMetadata) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) PrimitiveColumnMetadata(org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata) VariantColumnMetadata(org.apache.drill.exec.record.metadata.VariantColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) TupleSchema(org.apache.drill.exec.record.metadata.TupleSchema) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 4 with ColumnMetadata

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()));
}
Also used : MapColumnMetadata(org.apache.drill.exec.record.metadata.MapColumnMetadata) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) PrimitiveColumnMetadata(org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata) VariantColumnMetadata(org.apache.drill.exec.record.metadata.VariantColumnMetadata) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 5 with ColumnMetadata

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());
}
Also used : MapColumnMetadata(org.apache.drill.exec.record.metadata.MapColumnMetadata) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) PrimitiveColumnMetadata(org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata) VariantColumnMetadata(org.apache.drill.exec.record.metadata.VariantColumnMetadata) MapColumnMetadata(org.apache.drill.exec.record.metadata.MapColumnMetadata) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)195 Test (org.junit.Test)104 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)98 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)50 DrillTest (org.apache.drill.test.DrillTest)37 PrimitiveColumnMetadata (org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata)31 SubOperatorTest (org.apache.drill.test.SubOperatorTest)31 BaseTest (org.apache.drill.test.BaseTest)26 MapColumnMetadata (org.apache.drill.exec.record.metadata.MapColumnMetadata)20 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)20 VariantColumnMetadata (org.apache.drill.exec.record.metadata.VariantColumnMetadata)19 VariantMetadata (org.apache.drill.exec.record.metadata.VariantMetadata)19 AbstractColumnMetadata (org.apache.drill.exec.record.metadata.AbstractColumnMetadata)17 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)17 DictColumnMetadata (org.apache.drill.exec.record.metadata.DictColumnMetadata)15 EvfTest (org.apache.drill.categories.EvfTest)13 ProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter)13 TupleSchema (org.apache.drill.exec.record.metadata.TupleSchema)11 ArrayList (java.util.ArrayList)10 ProjResult (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult)10