Search in sources :

Example 6 with VariantMetadata

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

Example 7 with VariantMetadata

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

Example 8 with VariantMetadata

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

Example 9 with VariantMetadata

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

Example 10 with VariantMetadata

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

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