use of org.apache.drill.exec.record.metadata.VariantMetadata in project drill by axbaretto.
the class TestTupleSchema method testNestedSchema.
@Test
public void testNestedSchema() {
TupleMetadata schema = new SchemaBuilder().addList("list").addType(MinorType.BIGINT).addType(MinorType.VARCHAR).addMap().add("a", MinorType.INT).add("b", MinorType.VARCHAR).resumeUnion().addList().addType(MinorType.FLOAT8).addType(MinorType.DECIMAL18).buildNested().resumeSchema().buildSchema();
assertEquals(1, schema.size());
ColumnMetadata col = schema.metadata(0);
assertTrue(col.isVariant());
VariantMetadata union = col.variantSchema();
assertNotNull(union);
assertEquals(4, union.size());
assertTrue(union.hasType(MinorType.MAP));
assertTrue(union.hasType(MinorType.LIST));
ColumnMetadata mapCol = union.member(MinorType.MAP);
TupleMetadata mapSchema = mapCol.mapSchema();
assertEquals(2, mapSchema.size());
ColumnMetadata listCol = union.member(MinorType.LIST);
VariantMetadata listSchema = listCol.variantSchema();
assertEquals(2, listSchema.size());
assertTrue(listSchema.hasType(MinorType.FLOAT8));
assertTrue(listSchema.hasType(MinorType.DECIMAL18));
}
use of org.apache.drill.exec.record.metadata.VariantMetadata in project drill by apache.
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").tupleSchema();
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 apache.
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.tupleSchema();
assertEquals(2, mapSchema.size());
assertTrue(variant.hasType(MinorType.FLOAT8));
assertFalse(variant.hasType(MinorType.VARCHAR));
}
use of org.apache.drill.exec.record.metadata.VariantMetadata in project drill by apache.
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 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));
}
Aggregations