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