Search in sources :

Example 1 with VariantMetadata

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

Example 2 with VariantMetadata

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());
}
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 3 with VariantMetadata

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));
}
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 4 with VariantMetadata

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));
}
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 5 with VariantMetadata

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));
}
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