Search in sources :

Example 16 with VariantMetadata

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());
}
Also used : VariantMetadata(org.apache.drill.exec.record.metadata.VariantMetadata) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 17 with VariantMetadata

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());
}
Also used : VariantMetadata(org.apache.drill.exec.record.metadata.VariantMetadata) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 18 with VariantMetadata

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));
}
Also used : VariantMetadata(org.apache.drill.exec.record.metadata.VariantMetadata) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata)

Example 19 with VariantMetadata

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);
}
Also used : VariantMetadata(org.apache.drill.exec.record.metadata.VariantMetadata) AbstractObjectReader(org.apache.drill.exec.vector.accessor.reader.AbstractObjectReader) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata)

Aggregations

ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)19 VariantMetadata (org.apache.drill.exec.record.metadata.VariantMetadata)19 Test (org.junit.Test)16 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)15 DrillTest (org.apache.drill.test.DrillTest)13 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)9 AbstractColumnMetadata (org.apache.drill.exec.record.metadata.AbstractColumnMetadata)6 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)6 MapColumnMetadata (org.apache.drill.exec.record.metadata.MapColumnMetadata)4 PrimitiveColumnMetadata (org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata)4 VariantColumnMetadata (org.apache.drill.exec.record.metadata.VariantColumnMetadata)4 SubOperatorTest (org.apache.drill.test.SubOperatorTest)3 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)2 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)2 TupleSchema (org.apache.drill.exec.record.metadata.TupleSchema)2 UnionBuilder (org.apache.drill.exec.record.metadata.UnionBuilder)1 AbstractObjectReader (org.apache.drill.exec.vector.accessor.reader.AbstractObjectReader)1