use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by axbaretto.
the class TestSchemaBuilder method testRowBasics.
@Test
public void testRowBasics() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.VARCHAR, // Generic
DataMode.OPTIONAL).add("b", // Required
MinorType.INT).addNullable("c", // Convenience
MinorType.FLOAT8).addArray("d", // Convenience
MinorType.BIGINT).buildSchema();
assertEquals(4, 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());
ColumnMetadata c = schema.metadata(2);
assertEquals("c", c.name());
assertEquals(MinorType.FLOAT8, c.type());
assertEquals(DataMode.OPTIONAL, c.mode());
ColumnMetadata d = schema.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 axbaretto.
the class TestSchemaBuilder method testRepeatedListInMap.
/**
* Verify that the repeated list-in-map plumbing works.
*/
@Test
public void testRepeatedListInMap() {
TupleMetadata schema = new SchemaBuilder().addMap("m1").addRepeatedList("r").addArray(MinorType.INT).resumeMap().add("b", MinorType.VARCHAR).resumeSchema().buildSchema();
TupleMetadata m1Schema = schema.metadata("m1").mapSchema();
ColumnMetadata r = m1Schema.metadata(0);
assertEquals("r", r.name());
assertEquals(MinorType.LIST, r.type());
assertEquals(DataMode.REPEATED, r.mode());
ColumnMetadata child = r.childSchema();
assertEquals(r.name(), child.name());
assertEquals(MinorType.INT, child.type());
ColumnMetadata b = m1Schema.metadata(1);
assertEquals("b", b.name());
assertEquals(MinorType.VARCHAR, b.type());
}
use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by axbaretto.
the class TestSchemaBuilder method testRepeatedListInUnion.
@Test
public void testRepeatedListInUnion() {
TupleMetadata schema = new SchemaBuilder().addUnion("u").addRepeatedList().addArray(MinorType.INT).resumeUnion().addType(MinorType.FLOAT8).resumeSchema().buildSchema();
ColumnMetadata u = schema.metadata("u");
VariantMetadata variant = u.variantSchema();
ColumnMetadata listType = variant.member(MinorType.LIST);
assertNotNull(listType);
ColumnMetadata child = listType.childSchema();
assertEquals(MinorType.INT, child.type());
assertTrue(variant.hasType(MinorType.FLOAT8));
assertFalse(variant.hasType(MinorType.VARCHAR));
}
use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by axbaretto.
the class TestSchemaBuilder method testUnionInMap.
/**
* Verify that the union-in-map plumbing works.
*/
@Test
public void testUnionInMap() {
TupleMetadata schema = new SchemaBuilder().addMap("m1").addUnion("u").addType(MinorType.INT).resumeMap().add("b", MinorType.VARCHAR).resumeSchema().buildSchema();
TupleMetadata m1Schema = schema.metadata("m1").mapSchema();
VariantMetadata uSchema = m1Schema.metadata("u").variantSchema();
assertTrue(uSchema.hasType(MinorType.INT));
assertFalse(uSchema.hasType(MinorType.VARCHAR));
ColumnMetadata b = m1Schema.metadata(1);
assertEquals("b", b.name());
assertEquals(MinorType.VARCHAR, b.type());
}
use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by axbaretto.
the class TestSchemaBuilder method testListInRow.
/**
* Test building a list (of unions) in the top-level schema.
*/
@Test
public void testListInRow() {
TupleMetadata schema = new SchemaBuilder().addList("list").addType(MinorType.VARCHAR).addType(MinorType.INT).resumeSchema().buildSchema();
assertEquals(1, schema.size());
ColumnMetadata list = schema.metadata(0);
assertEquals("list", list.name());
assertEquals(StructureType.VARIANT, list.structureType());
assertTrue(list.isVariant());
assertEquals(MinorType.LIST, list.type());
// Yes, strange. Though a list is, essentially, an array, an
// optional list has one set of semantics (in ListVector, not
// really supported), while a repeated list has entirely different
// semantics (in the RepeatedListVector) and is supported.
assertEquals(DataMode.OPTIONAL, list.mode());
VariantMetadata variant = list.variantSchema();
assertNotNull(variant);
assertEquals(2, variant.size());
assertTrue(variant.hasType(MinorType.VARCHAR));
ColumnMetadata vMember = variant.member(MinorType.VARCHAR);
assertNotNull(vMember);
assertEquals(Types.typeKey(MinorType.VARCHAR), vMember.name());
assertEquals(MinorType.VARCHAR, vMember.type());
assertEquals(DataMode.OPTIONAL, vMember.mode());
assertTrue(variant.hasType(MinorType.INT));
ColumnMetadata iMember = variant.member(MinorType.INT);
assertNotNull(iMember);
assertEquals(Types.typeKey(MinorType.INT), iMember.name());
assertEquals(MinorType.INT, iMember.type());
assertEquals(DataMode.OPTIONAL, iMember.mode());
}
Aggregations