Search in sources :

Example 6 with TupleSchema

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

the class TestProjectionFilter method testTypeFilter.

@Test
public void testTypeFilter() {
    TupleMetadata schema = new SchemaBuilder().add(A_COL.copy()).add(B_COL.copy()).addMap("m").add("a", MinorType.INT).resumeSchema().build();
    ProjectionFilter filter = new TypeProjectionFilter(schema, EmptyErrorContext.INSTANCE);
    assertFalse(filter.isEmpty());
    assertTrue(filter.isProjected("a"));
    assertTrue(filter.projection(A_COL).isProjected);
    assertTrue(filter.isProjected("b"));
    assertTrue(filter.projection(B_COL).isProjected);
    assertTrue(filter.isProjected("c"));
    assertTrue(filter.projection(MetadataUtils.newScalar("c", Types.required(MinorType.BIGINT))).isProjected);
    ColumnMetadata typeConflict = MetadataUtils.newScalar("a", Types.required(MinorType.BIGINT));
    try {
        filter.projection(typeConflict);
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains("conflict"));
    }
    ColumnMetadata modeConflict = MetadataUtils.newScalar("a", Types.optional(MinorType.INT));
    try {
        filter.projection(modeConflict);
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains("conflict"));
    }
    ProjResult result = filter.projection(MAP_COL);
    assertTrue(result.isProjected);
    ProjectionFilter child = result.mapFilter;
    assertTrue(child.isProjected("a"));
    assertTrue(child.isProjected("b"));
    result = filter.projection(MAP_COL2);
    assertTrue(result.isProjected);
    assertSame(ProjectionFilter.PROJECT_ALL, result.mapFilter);
    try {
        ColumnMetadata aMap = MetadataUtils.newMap("a", new TupleSchema());
        filter.projection(aMap);
        fail();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains("type conflict"));
    }
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) SchemaProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.SchemaProjectionFilter) TypeProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.TypeProjectionFilter) DirectProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.DirectProjectionFilter) CompoundProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.CompoundProjectionFilter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) UserException(org.apache.drill.common.exceptions.UserException) TypeProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.TypeProjectionFilter) ProjResult(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult) TupleSchema(org.apache.drill.exec.record.metadata.TupleSchema) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest)

Example 7 with TupleSchema

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

the class IcebergColumnConverterFactory method convertSchema.

public static TupleSchema convertSchema(Types.StructType structType) {
    TupleSchema schema = new TupleSchema();
    for (Types.NestedField field : structType.fields()) {
        ColumnMetadata columnMetadata = getColumnMetadata(field);
        schema.add(columnMetadata);
    }
    return schema;
}
Also used : Types(org.apache.iceberg.types.Types) DictColumnMetadata(org.apache.drill.exec.record.metadata.DictColumnMetadata) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) TupleSchema(org.apache.drill.exec.record.metadata.TupleSchema)

Example 8 with TupleSchema

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

the class CompliantTextBatchReader method buildFromColumnHeaders.

/**
 * File has column headers. No provided schema. Build schema from the
 * column headers.
 */
private FieldVarCharOutput buildFromColumnHeaders(ColumnsSchemaNegotiator schemaNegotiator, String[] fieldNames) {
    final TupleMetadata schema = new TupleSchema();
    for (final String colName : fieldNames) {
        schema.addColumn(textColumn(colName));
    }
    schemaNegotiator.tableSchema(schema, true);
    writer = schemaNegotiator.build().writer();
    ValueWriter[] colWriters = new ValueWriter[fieldNames.length];
    for (int i = 0; i < fieldNames.length; i++) {
        colWriters[i] = writer.column(i).scalar();
    }
    return new FieldVarCharOutput(writer, colWriters);
}
Also used : TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) ValueWriter(org.apache.drill.exec.vector.accessor.ValueWriter) TupleSchema(org.apache.drill.exec.record.metadata.TupleSchema)

Example 9 with TupleSchema

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

the class CompliantTextBatchReader method mergeSchemas.

private TupleMetadata mergeSchemas(TupleMetadata providedSchema, String[] fieldNames) {
    final TupleMetadata readerSchema = new TupleSchema();
    for (String fieldName : fieldNames) {
        final ColumnMetadata providedCol = providedSchema.metadata(fieldName);
        readerSchema.addColumn(providedCol == null ? textColumn(fieldName) : providedCol);
    }
    return readerSchema;
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) TupleSchema(org.apache.drill.exec.record.metadata.TupleSchema)

Example 10 with TupleSchema

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

the class SchemaVisitor method visitColumns.

@Override
public TupleMetadata visitColumns(SchemaParser.ColumnsContext ctx) {
    TupleMetadata schema = new TupleSchema();
    ColumnDefVisitor columnDefVisitor = new ColumnDefVisitor();
    ctx.column_def().forEach(columnDef -> schema.addColumn(columnDef.accept(columnDefVisitor)));
    return schema;
}
Also used : TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) TupleSchema(org.apache.drill.exec.record.metadata.TupleSchema)

Aggregations

TupleSchema (org.apache.drill.exec.record.metadata.TupleSchema)30 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)25 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)12 Test (org.junit.Test)10 MapColumnMetadata (org.apache.drill.exec.record.metadata.MapColumnMetadata)6 PrimitiveColumnMetadata (org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata)6 VariantColumnMetadata (org.apache.drill.exec.record.metadata.VariantColumnMetadata)6 SubOperatorTest (org.apache.drill.test.SubOperatorTest)5 SchemaPath (org.apache.drill.common.expression.SchemaPath)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 UserException (org.apache.drill.common.exceptions.UserException)3 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)3 MaterializedField (org.apache.drill.exec.record.MaterializedField)3 BaseTest (org.apache.drill.test.BaseTest)3 Collectors (java.util.stream.Collectors)2 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)2 CompoundProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.CompoundProjectionFilter)2 DirectProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.DirectProjectionFilter)2