Search in sources :

Example 21 with ColumnMetadata

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

the class ScanLevelProjection method addTableColumn.

private void addTableColumn(RequestedColumn inCol) {
    ColumnMetadata outputCol = null;
    if (readerSchema != null) {
        outputCol = readerSchema.metadata(inCol.name());
    }
    addTableColumn(new UnresolvedColumn(inCol, outputCol));
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) UnresolvedColumn(org.apache.drill.exec.physical.impl.scan.project.AbstractUnresolvedColumn.UnresolvedColumn)

Example 22 with ColumnMetadata

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

the class OutputBatchBuilder method physicalProjection.

/**
 * Project the source vectors to the output container, merging
 * maps along the way.
 */
@SuppressWarnings("unchecked")
private void physicalProjection() {
    outputContainer.removeAll();
    mapVectors.clear();
    for (int i = 0; i < outputSchema.size(); i++) {
        ColumnMetadata outputCol = outputSchema.metadata(i);
        ValueVector outputVector;
        if (outputCol.isMap()) {
            outputVector = buildTopMap(outputCol, (List<VectorSource>) vectorSources[i]);
            // must be set separately from the underling data vectors.
            if (outputVector instanceof MapVector) {
                mapVectors.add((MapVector) outputVector);
            }
        } else {
            outputVector = getVector((VectorSource) vectorSources[i]);
        }
        outputContainer.add(outputVector);
    }
    outputContainer.buildSchema(SelectionVectorMode.NONE);
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) List(java.util.List) ArrayList(java.util.ArrayList) AbstractMapVector(org.apache.drill.exec.vector.complex.AbstractMapVector) MapVector(org.apache.drill.exec.vector.complex.MapVector)

Example 23 with ColumnMetadata

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

the class TestDirectConverter method testSpecialConversionType.

/**
 * Test the specialized types: conversation to/from string.
 */
@Test
public void testSpecialConversionType() {
    StandardConversions conversions = StandardConversions.builder().build();
    TupleMetadata schema = new SchemaBuilder().add("time", MinorType.TIME).add("date", MinorType.DATE).add("ts", MinorType.TIMESTAMP).add("interval", MinorType.INTERVAL).add("year", MinorType.INTERVALYEAR).add("day", MinorType.INTERVALDAY).add("int", MinorType.INT).add("bi", MinorType.BIGINT).add("str", MinorType.VARCHAR).buildSchema();
    ColumnMetadata timeCol = schema.metadata("time");
    ColumnMetadata dateCol = schema.metadata("date");
    ColumnMetadata tsCol = schema.metadata("ts");
    ColumnMetadata intervalCol = schema.metadata("interval");
    ColumnMetadata yearCol = schema.metadata("year");
    ColumnMetadata dayCol = schema.metadata("day");
    ColumnMetadata intCol = schema.metadata("int");
    ColumnMetadata bigIntCol = schema.metadata("bi");
    ColumnMetadata stringCol = schema.metadata("str");
    // TIME
    expect(ConversionType.NONE, conversions.analyze(timeCol, timeCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(timeCol, stringCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, timeCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(intCol, timeCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(timeCol, intCol));
    // DATE
    expect(ConversionType.NONE, conversions.analyze(dateCol, dateCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(dateCol, stringCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, dateCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(bigIntCol, dateCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(dateCol, bigIntCol));
    // TIMESTAMP
    expect(ConversionType.NONE, conversions.analyze(tsCol, tsCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(tsCol, stringCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, tsCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(bigIntCol, tsCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(tsCol, bigIntCol));
    // INTERVAL
    expect(ConversionType.NONE, conversions.analyze(intervalCol, intervalCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(intervalCol, stringCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, intervalCol));
    // INTERVALYEAR
    expect(ConversionType.NONE, conversions.analyze(yearCol, yearCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(yearCol, stringCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, yearCol));
    // INTERVALDAY
    expect(ConversionType.NONE, conversions.analyze(dayCol, dayCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(dayCol, stringCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, dayCol));
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 24 with ColumnMetadata

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

the class TestDirectConverter method testBasicConversionType.

/**
 * Test the conversion type for a subset of type pairs.
 */
@Test
public void testBasicConversionType() {
    StandardConversions conversions = StandardConversions.builder().build();
    TupleMetadata schema = new SchemaBuilder().add("ti", MinorType.TINYINT).add("si", MinorType.SMALLINT).add("int", MinorType.INT).add("bi", MinorType.BIGINT).add("fl", MinorType.FLOAT4).add("db", MinorType.FLOAT8).add("dec", MinorType.VARDECIMAL, 10, 0).add("str", MinorType.VARCHAR).buildSchema();
    ColumnMetadata tinyIntCol = schema.metadata("ti");
    ColumnMetadata smallIntCol = schema.metadata("si");
    ColumnMetadata intCol = schema.metadata("int");
    ColumnMetadata bigIntCol = schema.metadata("bi");
    ColumnMetadata float4Col = schema.metadata("fl");
    ColumnMetadata float8Col = schema.metadata("db");
    ColumnMetadata decimalCol = schema.metadata("dec");
    ColumnMetadata stringCol = schema.metadata("str");
    // TinyInt --> x
    expect(ConversionType.NONE, conversions.analyze(tinyIntCol, tinyIntCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(tinyIntCol, smallIntCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(tinyIntCol, intCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(tinyIntCol, bigIntCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(tinyIntCol, float4Col));
    expect(ConversionType.IMPLICIT, conversions.analyze(tinyIntCol, float8Col));
    expect(ConversionType.EXPLICIT, conversions.analyze(tinyIntCol, decimalCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(tinyIntCol, stringCol));
    // SmallInt --> x
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(smallIntCol, tinyIntCol));
    expect(ConversionType.NONE, conversions.analyze(smallIntCol, smallIntCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(smallIntCol, intCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(smallIntCol, bigIntCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(smallIntCol, float4Col));
    expect(ConversionType.IMPLICIT, conversions.analyze(smallIntCol, float8Col));
    expect(ConversionType.EXPLICIT, conversions.analyze(smallIntCol, decimalCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(smallIntCol, stringCol));
    // Int --> x
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(intCol, tinyIntCol));
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(intCol, smallIntCol));
    expect(ConversionType.NONE, conversions.analyze(intCol, intCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(intCol, bigIntCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(intCol, float4Col));
    expect(ConversionType.IMPLICIT, conversions.analyze(intCol, float8Col));
    expect(ConversionType.EXPLICIT, conversions.analyze(intCol, decimalCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(intCol, stringCol));
    // BigInt --> x
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(bigIntCol, tinyIntCol));
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(bigIntCol, smallIntCol));
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(bigIntCol, intCol));
    expect(ConversionType.NONE, conversions.analyze(bigIntCol, bigIntCol));
    expect(ConversionType.IMPLICIT, conversions.analyze(bigIntCol, float4Col));
    expect(ConversionType.IMPLICIT, conversions.analyze(bigIntCol, float8Col));
    expect(ConversionType.EXPLICIT, conversions.analyze(bigIntCol, decimalCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(bigIntCol, stringCol));
    // Float4 --> x
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(float4Col, tinyIntCol));
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(float4Col, smallIntCol));
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(float4Col, intCol));
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(float4Col, bigIntCol));
    expect(ConversionType.NONE, conversions.analyze(float4Col, float4Col));
    expect(ConversionType.IMPLICIT, conversions.analyze(float4Col, float8Col));
    expect(ConversionType.EXPLICIT, conversions.analyze(float4Col, decimalCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(float4Col, stringCol));
    // Float8 --> x
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(float8Col, tinyIntCol));
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(float8Col, smallIntCol));
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(float8Col, intCol));
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(float8Col, bigIntCol));
    expect(ConversionType.IMPLICIT_UNSAFE, conversions.analyze(float8Col, float4Col));
    expect(ConversionType.NONE, conversions.analyze(float8Col, float8Col));
    expect(ConversionType.EXPLICIT, conversions.analyze(float8Col, decimalCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(float8Col, stringCol));
    // Decimal --> x
    expect(ConversionType.EXPLICIT, conversions.analyze(decimalCol, tinyIntCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(decimalCol, smallIntCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(decimalCol, intCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(decimalCol, bigIntCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(decimalCol, float4Col));
    expect(ConversionType.EXPLICIT, conversions.analyze(decimalCol, float8Col));
    expect(ConversionType.NONE, conversions.analyze(decimalCol, decimalCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(decimalCol, stringCol));
    // VarChar --> x
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, tinyIntCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, smallIntCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, intCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, bigIntCol));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, float4Col));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, float8Col));
    expect(ConversionType.EXPLICIT, conversions.analyze(stringCol, decimalCol));
    expect(ConversionType.NONE, conversions.analyze(stringCol, stringCol));
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 25 with ColumnMetadata

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

the class TestDirectConverter method doTestBlanks.

private void doTestBlanks(DataMode mode, String frameworkOption, String colOption, Integer value) {
    TupleMetadata outputSchema = new SchemaBuilder().add("col", MinorType.INT, mode).buildSchema();
    ColumnMetadata colSchema = outputSchema.metadata("col");
    colSchema.setProperty(ColumnMetadata.DEFAULT_VALUE_PROP, "20");
    TupleMetadata inputSchema = new SchemaBuilder().addNullable("col", MinorType.VARCHAR).buildSchema();
    if (colOption != null) {
        colSchema = inputSchema.metadata("col");
        colSchema.setProperty(ColumnMetadata.BLANK_AS_PROP, colOption);
    }
    Map<String, String> props = null;
    if (frameworkOption != null) {
        props = new HashMap<>();
        props.put(ColumnMetadata.BLANK_AS_PROP, frameworkOption);
    }
    ConversionTestFixture testFixture = new ConversionTestFixture(fixture.allocator(), outputSchema);
    testFixture.withProperties(props);
    testFixture.createConvertersFor(inputSchema);
    try {
        testFixture.addSingleCol("").addSingleCol("  ").addSingleCol("10").addSingleCol(" 11  ");
    } catch (Exception e) {
        testFixture.build().clear();
        throw e;
    }
    RowSet actual = testFixture.build();
    final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addSingleCol(value).addSingleCol(value).addSingleCol(10).addSingleCol(11).build();
    RowSetUtilities.verify(expected, actual);
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) UserException(org.apache.drill.common.exceptions.UserException)

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