use of org.apache.drill.exec.record.metadata.VariantMetadata in project drill by apache.
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 apache.
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 apache.
the class HyperReaderBuilder method buildList.
// Note: Does not yet handle 2D lists. See the "single" base reader builder
// for the needed code.
private AbstractObjectReader buildList(VectorAccessor listAccessor, ColumnMetadata metadata) {
VariantMetadata listSchema = metadata.variantSchema();
ColumnMetadata dataMetadata = listSchema.listSubtype();
return ArrayReaderImpl.buildList(metadata, listAccessor, buildVectorReader(new VectorAccessors.ListMemberHyperVectorAccessor(listAccessor, dataMetadata.majorType()), dataMetadata));
}
use of org.apache.drill.exec.record.metadata.VariantMetadata in project drill by apache.
the class HyperReaderBuilder method buildUnion.
private AbstractObjectReader buildUnion(VectorAccessor unionAccessor, ColumnMetadata metadata) {
VariantMetadata unionSchema = metadata.variantSchema();
final AbstractObjectReader[] variants = new AbstractObjectReader[MinorType.values().length];
for (ColumnMetadata member : unionSchema.members()) {
// The following builds a synthetic field since we have no good way to
// access the real field at this point.
variants[member.type().ordinal()] = buildVectorReader(new VectorAccessors.UnionMemberHyperVectorAccessor(unionAccessor, member.majorType()), member);
}
return UnionReaderImpl.build(metadata, unionAccessor, variants);
}
Aggregations