Search in sources :

Example 1 with TupleSchema

use of org.apache.drill.exec.record.metadata.TupleSchema 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 2 with TupleSchema

use of org.apache.drill.exec.record.metadata.TupleSchema 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 3 with TupleSchema

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

the class HyperSchemaInference method infer.

public TupleMetadata infer(VectorContainer container) throws SchemaChangeException {
    TupleMetadata schema = new TupleSchema();
    for (int i = 0; i < container.getNumberOfColumns(); i++) {
        VectorWrapper<?> vw = container.getValueVector(i);
        schema.addColumn(buildColumn(vw));
    }
    return schema;
}
Also used : TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) TupleSchema(org.apache.drill.exec.record.metadata.TupleSchema)

Example 4 with TupleSchema

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

the class ParquetTableMetadataUtils method getRowGroupMetadata.

/**
 * Returns {@link RowGroupMetadata} instance converted from specified parquet {@code rowGroupMetadata}.
 *
 * @param tableMetadata    table metadata which contains row group metadata to convert
 * @param rowGroupMetadata row group metadata to convert
 * @param rgIndexInFile    index of current row group within the file
 * @param location         location of file with current row group
 * @return {@link RowGroupMetadata} instance converted from specified parquet {@code rowGroupMetadata}
 */
public static RowGroupMetadata getRowGroupMetadata(MetadataBase.ParquetTableMetadataBase tableMetadata, MetadataBase.RowGroupMetadata rowGroupMetadata, int rgIndexInFile, Path location) {
    Map<SchemaPath, ColumnStatistics<?>> columnsStatistics = getRowGroupColumnStatistics(tableMetadata, rowGroupMetadata);
    List<StatisticsHolder<?>> rowGroupStatistics = new ArrayList<>();
    rowGroupStatistics.add(new StatisticsHolder<>(rowGroupMetadata.getRowCount(), TableStatisticsKind.ROW_COUNT));
    rowGroupStatistics.add(new StatisticsHolder<>(rowGroupMetadata.getStart(), new BaseStatisticsKind<>(ExactStatisticsConstants.START, true)));
    rowGroupStatistics.add(new StatisticsHolder<>(rowGroupMetadata.getLength(), new BaseStatisticsKind<>(ExactStatisticsConstants.LENGTH, true)));
    Map<SchemaPath, TypeProtos.MajorType> columns = getRowGroupFields(tableMetadata, rowGroupMetadata);
    Map<SchemaPath, TypeProtos.MajorType> intermediateColumns = getIntermediateFields(tableMetadata, rowGroupMetadata);
    TupleMetadata schema = new TupleSchema();
    columns.forEach((schemaPath, majorType) -> SchemaPathUtils.addColumnMetadata(schema, schemaPath, majorType, intermediateColumns));
    MetadataInfo metadataInfo = MetadataInfo.builder().type(MetadataType.ROW_GROUP).build();
    return RowGroupMetadata.builder().tableInfo(TableInfo.UNKNOWN_TABLE_INFO).metadataInfo(metadataInfo).schema(schema).columnsStatistics(columnsStatistics).metadataStatistics(rowGroupStatistics).hostAffinity(rowGroupMetadata.getHostAffinity()).rowGroupIndex(rgIndexInFile).path(location).build();
}
Also used : ColumnStatistics(org.apache.drill.metastore.statistics.ColumnStatistics) MetadataInfo(org.apache.drill.metastore.metadata.MetadataInfo) ArrayList(java.util.ArrayList) BaseStatisticsKind(org.apache.drill.metastore.statistics.BaseStatisticsKind) TupleSchema(org.apache.drill.exec.record.metadata.TupleSchema) StatisticsHolder(org.apache.drill.metastore.statistics.StatisticsHolder) SchemaPath(org.apache.drill.common.expression.SchemaPath) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata)

Example 5 with TupleSchema

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

the class TestProjectionFilter method testBuilders.

@Test
public void testBuilders() {
    assertSame(ProjectionFilter.PROJECT_ALL, ProjectionFilter.projectionFilter(Projections.projectAll(), EmptyErrorContext.INSTANCE));
    assertSame(ProjectionFilter.PROJECT_NONE, ProjectionFilter.projectionFilter(Projections.projectNone(), EmptyErrorContext.INSTANCE));
    assertTrue(ProjectionFilter.projectionFilter(Projections.parse(RowSetTestUtils.projectList("a")), EmptyErrorContext.INSTANCE) instanceof DirectProjectionFilter);
    TupleMetadata schema = new SchemaBuilder().add(A_COL.copy()).add(B_COL.copy()).build();
    assertSame(ProjectionFilter.PROJECT_NONE, ProjectionFilter.definedSchemaFilter(new TupleSchema(), EmptyErrorContext.INSTANCE));
    assertTrue(ProjectionFilter.definedSchemaFilter(schema, EmptyErrorContext.INSTANCE) instanceof SchemaProjectionFilter);
    assertTrue(ProjectionFilter.providedSchemaFilter(Projections.projectAll(), schema, EmptyErrorContext.INSTANCE) instanceof CompoundProjectionFilter);
    assertSame(ProjectionFilter.PROJECT_NONE, ProjectionFilter.providedSchemaFilter(Projections.projectNone(), schema, EmptyErrorContext.INSTANCE));
    assertSame(ProjectionFilter.PROJECT_ALL, ProjectionFilter.providedSchemaFilter(Projections.projectAll(), new TupleSchema(), EmptyErrorContext.INSTANCE));
    TupleMetadata strictEmpty = new TupleSchema();
    strictEmpty.setBooleanProperty(TupleMetadata.IS_STRICT_SCHEMA_PROP, true);
    assertSame(ProjectionFilter.PROJECT_NONE, ProjectionFilter.providedSchemaFilter(Projections.projectAll(), strictEmpty, EmptyErrorContext.INSTANCE));
    assertTrue(ProjectionFilter.providedSchemaFilter(Projections.parse(RowSetTestUtils.projectList("a")), schema, EmptyErrorContext.INSTANCE) instanceof CompoundProjectionFilter);
}
Also used : SchemaProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.SchemaProjectionFilter) DirectProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.DirectProjectionFilter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) TupleSchema(org.apache.drill.exec.record.metadata.TupleSchema) CompoundProjectionFilter(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.CompoundProjectionFilter) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest)

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