use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by apache.
the class TestSchemaBuilder method testStandaloneRepeatedListBuilder.
@Test
public void testStandaloneRepeatedListBuilder() {
ColumnMetadata columnMetadata = new RepeatedListBuilder("l").addMapArray().addNullable("v", MinorType.VARCHAR).add("i", MinorType.INT).resumeList().buildColumn();
assertTrue(columnMetadata.isArray());
assertEquals("l", columnMetadata.name());
assertEquals(MinorType.LIST, columnMetadata.type());
ColumnMetadata child = columnMetadata.childSchema();
assertEquals("l", child.name());
assertTrue(child.isArray());
assertTrue(child.isMap());
TupleMetadata mapSchema = child.tupleSchema();
ColumnMetadata col0 = mapSchema.metadata(0);
assertEquals("v", col0.name());
assertEquals(MinorType.VARCHAR, col0.type());
assertTrue(col0.isNullable());
ColumnMetadata col1 = mapSchema.metadata(1);
assertEquals("i", col1.name());
assertEquals(MinorType.INT, col1.type());
assertFalse(col1.isNullable());
}
use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by apache.
the class TestSchemaBuilder method testRowPreBuilt.
@Test
public void testRowPreBuilt() {
MaterializedField aField = MaterializedField.create("a", Types.optional(MinorType.VARCHAR));
ColumnMetadata bCol = MetadataUtils.newScalar("b", MinorType.INT, DataMode.REQUIRED);
SchemaBuilder builder = new SchemaBuilder().add(aField);
// Internal method, does not return builder itself.
builder.addColumn(bCol);
TupleMetadata schema = builder.buildSchema();
assertEquals(2, schema.size());
ColumnMetadata a = schema.metadata(0);
assertEquals("a", a.name());
assertEquals(MinorType.VARCHAR, a.type());
assertEquals(DataMode.OPTIONAL, a.mode());
ColumnMetadata b = schema.metadata(1);
assertEquals("b", b.name());
assertEquals(MinorType.INT, b.type());
assertEquals(DataMode.REQUIRED, b.mode());
}
use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by apache.
the class TestSchemaBuilder method testMapInRow.
/**
* Tests creating a map within a row.
* Also the basic map add column methods.
*/
@Test
public void testMapInRow() {
TupleMetadata schema = new SchemaBuilder().addMap("m").add("a", MinorType.VARCHAR, // Generic
DataMode.OPTIONAL).add("b", // Required
MinorType.INT).addNullable("c", // Convenience
MinorType.FLOAT8).addArray("d", // Convenience
MinorType.BIGINT).resumeSchema().buildSchema();
assertEquals(1, schema.size());
ColumnMetadata m = schema.metadata(0);
assertEquals("m", m.name());
assertTrue(m.isMap());
assertEquals(DataMode.REQUIRED, m.mode());
TupleMetadata mapSchema = m.tupleSchema();
assertNotNull(mapSchema);
assertEquals(4, mapSchema.size());
ColumnMetadata a = mapSchema.metadata(0);
assertEquals("a", a.name());
assertEquals(MinorType.VARCHAR, a.type());
assertEquals(DataMode.OPTIONAL, a.mode());
ColumnMetadata b = mapSchema.metadata(1);
assertEquals("b", b.name());
assertEquals(MinorType.INT, b.type());
assertEquals(DataMode.REQUIRED, b.mode());
ColumnMetadata c = mapSchema.metadata(2);
assertEquals("c", c.name());
assertEquals(MinorType.FLOAT8, c.type());
assertEquals(DataMode.OPTIONAL, c.mode());
ColumnMetadata d = mapSchema.metadata(3);
assertEquals("d", d.name());
assertEquals(MinorType.BIGINT, d.type());
assertEquals(DataMode.REPEATED, d.mode());
}
use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by apache.
the class TestSchemaBuilder method testMapInRepeatedList.
// Note: union-in-union not supported in Drill
@Test
public void testMapInRepeatedList() {
TupleMetadata schema = new SchemaBuilder().addRepeatedList("x").addMapArray().add("a", MinorType.INT).addNullable("b", MinorType.VARCHAR).resumeList().resumeSchema().buildSchema();
ColumnMetadata list = schema.metadata("x");
ColumnMetadata mapCol = list.childSchema();
assertTrue(mapCol.isMap());
TupleMetadata mapSchema = mapCol.tupleSchema();
ColumnMetadata a = mapSchema.metadata("a");
assertEquals(MinorType.INT, a.type());
assertEquals(DataMode.REQUIRED, a.mode());
ColumnMetadata b = mapSchema.metadata("b");
assertEquals(MinorType.VARCHAR, b.type());
assertEquals(DataMode.OPTIONAL, b.mode());
}
use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by apache.
the class TestSchemaBuilder method testStandaloneMapBuilder.
@Test
public void testStandaloneMapBuilder() {
ColumnMetadata columnMetadata = new MapBuilder("m1", DataMode.OPTIONAL).addNullable("b", MinorType.BIGINT).addMap("m2").addNullable("v", MinorType.VARCHAR).resumeMap().buildColumn();
assertTrue(columnMetadata.isMap());
assertTrue(columnMetadata.isNullable());
assertEquals("m1", columnMetadata.name());
TupleMetadata schema = columnMetadata.tupleSchema();
ColumnMetadata col0 = schema.metadata(0);
assertEquals("b", col0.name());
assertEquals(MinorType.BIGINT, col0.type());
assertTrue(col0.isNullable());
ColumnMetadata col1 = schema.metadata(1);
assertEquals("m2", col1.name());
assertTrue(col1.isMap());
assertFalse(col1.isNullable());
ColumnMetadata child = col1.tupleSchema().metadata(0);
assertEquals("v", child.name());
assertEquals(MinorType.VARCHAR, child.type());
assertTrue(child.isNullable());
}
Aggregations