use of org.apache.drill.exec.record.metadata.VariantMetadata 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.VariantMetadata 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());
}
use of org.apache.drill.exec.record.metadata.VariantMetadata in project drill by axbaretto.
the class TestSchemaBuilder method testListInUnion.
// Note: list-in-union may be supported, but this area of the code is obscure
// and not a priority to maintain. The problem will be that both lists
// and repeated lists key off of the same type code: LIST, so it is
// ambiguous which is supported. The schema builder muddles through this
// case, but the rest of the code might not.
@Test
public void testListInUnion() {
TupleMetadata schema = new SchemaBuilder().addUnion("u").addList().addType(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);
VariantMetadata listSchema = listType.variantSchema();
assertTrue(listSchema.hasType(MinorType.INT));
assertTrue(variant.hasType(MinorType.FLOAT8));
assertFalse(variant.hasType(MinorType.VARCHAR));
}
use of org.apache.drill.exec.record.metadata.VariantMetadata in project drill by axbaretto.
the class TestSchemaBuilder method testUnionInRow.
/**
* Test building a union in the top-level schema.
* Also tests the basic union add type methods.
*/
@Test
public void testUnionInRow() {
TupleMetadata schema = new SchemaBuilder().addUnion("u").addType(MinorType.VARCHAR).addType(MinorType.INT).resumeSchema().buildSchema();
assertEquals(1, schema.size());
ColumnMetadata u = schema.metadata(0);
assertEquals("u", u.name());
assertEquals(StructureType.VARIANT, u.structureType());
assertTrue(u.isVariant());
assertEquals(MinorType.UNION, u.type());
assertEquals(DataMode.OPTIONAL, u.mode());
VariantMetadata variant = u.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());
}
use of org.apache.drill.exec.record.metadata.VariantMetadata in project drill by axbaretto.
the class TestSchemaBuilder method testMapInUnion.
@Test
public void testMapInUnion() {
TupleMetadata schema = new SchemaBuilder().addUnion("u").addMap().add("a", MinorType.INT).add("b", MinorType.VARCHAR).resumeUnion().addType(MinorType.FLOAT8).resumeSchema().buildSchema();
ColumnMetadata u = schema.metadata("u");
VariantMetadata variant = u.variantSchema();
ColumnMetadata mapType = variant.member(MinorType.MAP);
assertNotNull(mapType);
TupleMetadata mapSchema = mapType.mapSchema();
assertEquals(2, mapSchema.size());
assertTrue(variant.hasType(MinorType.FLOAT8));
assertFalse(variant.hasType(MinorType.VARCHAR));
}
Aggregations