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());
}
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;
}
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;
}
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();
}
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);
}
Aggregations