Search in sources :

Example 16 with ColumnMetadata

use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by axbaretto.

the class TestSchemaBuilder method testDecimal.

/**
 * Test the ability to specify decimal precision and scale. Decimal is
 * broken in Drill, so we don't bother about decimals in unions,
 * lists or repeated lists, though those methods could be added.
 */
@Test
public void testDecimal() {
    TupleMetadata schema = new SchemaBuilder().addDecimal("a", MinorType.DECIMAL18, DataMode.OPTIONAL, 5, 2).addDecimal("b", MinorType.DECIMAL18, DataMode.REQUIRED, 6, 3).addDecimal("c", MinorType.DECIMAL18, DataMode.REPEATED, 7, 4).addMap("m").addDecimal("d", MinorType.DECIMAL18, DataMode.OPTIONAL, 8, 1).resumeSchema().buildSchema();
    // Use name methods, just for variety
    ColumnMetadata a = schema.metadata("a");
    assertEquals(DataMode.OPTIONAL, a.mode());
    assertEquals(5, a.precision());
    assertEquals(2, a.scale());
    ColumnMetadata b = schema.metadata("b");
    assertEquals(DataMode.REQUIRED, b.mode());
    assertEquals(6, b.precision());
    assertEquals(3, b.scale());
    ColumnMetadata c = schema.metadata("c");
    assertEquals(DataMode.REPEATED, c.mode());
    assertEquals(7, c.precision());
    assertEquals(4, c.scale());
    ColumnMetadata d = schema.metadata("m").mapSchema().metadata("d");
    assertEquals(DataMode.OPTIONAL, d.mode());
    assertEquals(8, d.precision());
    assertEquals(1, d.scale());
}
Also used : AbstractColumnMetadata(org.apache.drill.exec.record.metadata.AbstractColumnMetadata) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 17 with ColumnMetadata

use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by axbaretto.

the class RowSetPrinter method printTupleSchema.

private void printTupleSchema(PrintStream out, TupleMetadata schema) {
    for (int i = 0; i < schema.size(); i++) {
        if (i > 0) {
            out.print(", ");
        }
        ColumnMetadata colSchema = schema.metadata(i);
        out.print(colSchema.name());
        if (colSchema.isMap()) {
            out.print("(");
            printTupleSchema(out, colSchema.mapSchema());
            out.print(")");
        }
    }
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata)

Example 18 with ColumnMetadata

use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by apache.

the class ScanSchemaResolver method createMap.

/**
 * Recursively create a map, including nested maps.
 */
private ColumnMetadata createMap(DynamicColumn projection, ProjectionFilter filter, ColumnMetadata revised) {
    ColumnMetadata map = revised.cloneEmpty();
    SchemaUtils.mergeColProperties(map, projection);
    SchemaUtils.mergeColProperties(map, revised);
    copyDynamicMembers(map, projection);
    // then strict means no additional columns are allowed.
    if (!projection.isMap() && mode != SchemaType.STRICT_PROVIDED_SCHEMA) {
        SchemaUtils.markProjectAll(map);
    }
    expandMapProjection(map.tupleSchema(), filter, revised.tupleSchema());
    return map;
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata)

Example 19 with ColumnMetadata

use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by apache.

the class MissingColumnHandlerBuilder method buildSchema.

public TupleMetadata buildSchema() {
    if (inputSchema == null || inputSchema.isEmpty()) {
        return null;
    }
    outputSchema = new TupleSchema();
    MajorType selectedNullType = nullType == null ? DEFAULT_NULL_TYPE : nullType;
    for (ColumnMetadata inputCol : inputSchema) {
        if (inputCol.isDynamic()) {
            outputSchema.addColumn(MetadataUtils.newScalar(inputCol.name(), selectedNullType));
        } else {
            outputSchema.addColumn(inputCol);
        }
    }
    return outputSchema;
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) TupleSchema(org.apache.drill.exec.record.metadata.TupleSchema)

Example 20 with ColumnMetadata

use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by apache.

the class ScanLevelProjection method expandOutputSchema.

private boolean expandOutputSchema() {
    if (readerSchema == null) {
        return false;
    }
    for (int i = 0; i < readerSchema.size(); i++) {
        ColumnMetadata col = readerSchema.metadata(i);
        // automatically.
        if (col.booleanProperty(ColumnMetadata.EXCLUDE_FROM_WILDCARD)) {
            continue;
        }
        outputCols.add(new UnresolvedColumn(null, col));
    }
    return true;
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) UnresolvedColumn(org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn)

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