Search in sources :

Example 11 with VariantMetadata

use of org.apache.drill.exec.record.metadata.VariantMetadata in project drill by axbaretto.

the class TestTupleSchema method doVariantTest.

private void doVariantTest(ColumnMetadata col) {
    assertTrue(col instanceof VariantColumnMetadata);
    assertTrue(col.isNullable());
    assertFalse(col.isVariableWidth());
    assertFalse(col.isMap());
    assertTrue(col.isVariant());
    assertEquals(0, col.expectedWidth());
    col.setExpectedWidth(10);
    assertEquals(0, col.expectedWidth());
    VariantMetadata variant = col.variantSchema();
    assertNotNull(variant);
    assertEquals(0, variant.size());
    ColumnMetadata member = variant.addType(MinorType.INT);
    assertEquals(MinorType.INT, member.type());
    assertEquals(DataMode.OPTIONAL, member.mode());
    assertEquals(Types.typeKey(MinorType.INT), member.name());
    assertEquals(1, variant.size());
    assertTrue(variant.hasType(MinorType.INT));
    assertSame(member, variant.member(MinorType.INT));
    try {
        variant.addType(MinorType.INT);
        fail();
    } catch (IllegalArgumentException e) {
    // expected
    }
    assertFalse(variant.hasType(MinorType.VARCHAR));
    member = variant.addType(MinorType.VARCHAR);
    assertEquals(MinorType.VARCHAR, member.type());
    assertEquals(DataMode.OPTIONAL, member.mode());
    assertEquals(Types.typeKey(MinorType.VARCHAR), member.name());
    assertEquals(2, variant.size());
    assertTrue(variant.hasType(MinorType.VARCHAR));
    assertSame(member, variant.member(MinorType.VARCHAR));
    assertFalse(variant.hasType(MinorType.BIGINT));
}
Also used : VariantMetadata(org.apache.drill.exec.record.metadata.VariantMetadata) VariantColumnMetadata(org.apache.drill.exec.record.metadata.VariantColumnMetadata) 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)

Example 12 with VariantMetadata

use of org.apache.drill.exec.record.metadata.VariantMetadata in project drill by axbaretto.

the class TestTupleSchema method testListSchema.

@Test
public void testListSchema() {
    TupleMetadata schema = new SchemaBuilder().addList("list").addType(MinorType.BIGINT).addType(MinorType.VARCHAR).resumeSchema().buildSchema();
    assertEquals(1, schema.size());
    ColumnMetadata col = schema.metadata(0);
    assertTrue(col instanceof VariantColumnMetadata);
    // Implementation shows through here: actual major
    // type is (LIST, OPTIONAL) even though the metadata
    // lies that this is a variant array.
    assertEquals(MinorType.LIST, col.type());
    assertEquals(DataMode.OPTIONAL, col.mode());
    assertTrue(col.isNullable());
    assertTrue(col.isArray());
    assertTrue(col.isVariant());
    assertEquals(StructureType.VARIANT, col.structureType());
    VariantMetadata union = col.variantSchema();
    assertNotNull(union);
    assertEquals(2, union.size());
    assertTrue(union.hasType(MinorType.BIGINT));
    assertTrue(union.hasType(MinorType.VARCHAR));
    assertFalse(union.hasType(MinorType.INT));
    Collection<MinorType> types = union.types();
    assertNotNull(types);
    assertEquals(2, types.size());
    assertTrue(types.contains(MinorType.BIGINT));
    assertTrue(types.contains(MinorType.VARCHAR));
    BatchSchema batchSchema = ((TupleSchema) schema).toBatchSchema(SelectionVectorMode.NONE);
    MaterializedField field = batchSchema.getColumn(0);
    assertEquals("list", field.getName());
    MajorType majorType = field.getType();
    assertEquals(MinorType.LIST, majorType.getMinorType());
    assertEquals(DataMode.OPTIONAL, majorType.getMode());
    assertEquals(2, majorType.getSubTypeCount());
    List<MinorType> subtypes = majorType.getSubTypeList();
    assertEquals(2, subtypes.size());
    assertTrue(subtypes.contains(MinorType.BIGINT));
    assertTrue(subtypes.contains(MinorType.VARCHAR));
}
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) VariantColumnMetadata(org.apache.drill.exec.record.metadata.VariantColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) TupleSchema(org.apache.drill.exec.record.metadata.TupleSchema) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 13 with VariantMetadata

use of org.apache.drill.exec.record.metadata.VariantMetadata in project drill by axbaretto.

the class TestTupleSchema method testUnionSchema.

@Test
public void testUnionSchema() {
    TupleMetadata schema = new SchemaBuilder().addUnion("u").addType(MinorType.BIGINT).addType(MinorType.VARCHAR).resumeSchema().buildSchema();
    assertEquals(1, schema.size());
    ColumnMetadata col = schema.metadata(0);
    assertTrue(col instanceof VariantColumnMetadata);
    assertEquals(MinorType.UNION, col.type());
    assertEquals(DataMode.OPTIONAL, col.mode());
    assertTrue(col.isNullable());
    assertFalse(col.isArray());
    assertTrue(col.isVariant());
    assertEquals(StructureType.VARIANT, col.structureType());
    VariantMetadata union = col.variantSchema();
    assertNotNull(union);
    assertEquals(2, union.size());
    assertTrue(union.hasType(MinorType.BIGINT));
    assertTrue(union.hasType(MinorType.VARCHAR));
    assertFalse(union.hasType(MinorType.INT));
    Collection<MinorType> types = union.types();
    assertNotNull(types);
    assertEquals(2, types.size());
    assertTrue(types.contains(MinorType.BIGINT));
    assertTrue(types.contains(MinorType.VARCHAR));
    BatchSchema batchSchema = ((TupleSchema) schema).toBatchSchema(SelectionVectorMode.NONE);
    MaterializedField field = batchSchema.getColumn(0);
    assertEquals("u", field.getName());
    MajorType majorType = field.getType();
    assertEquals(MinorType.UNION, majorType.getMinorType());
    assertEquals(DataMode.OPTIONAL, majorType.getMode());
    assertEquals(2, majorType.getSubTypeCount());
    List<MinorType> subtypes = majorType.getSubTypeList();
    assertEquals(2, subtypes.size());
    assertTrue(subtypes.contains(MinorType.BIGINT));
    assertTrue(subtypes.contains(MinorType.VARCHAR));
}
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) VariantColumnMetadata(org.apache.drill.exec.record.metadata.VariantColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) TupleSchema(org.apache.drill.exec.record.metadata.TupleSchema) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 14 with VariantMetadata

use of org.apache.drill.exec.record.metadata.VariantMetadata in project drill by apache.

the class TestSchemaBuilder method testStandaloneUnionBuilder.

@Test
public void testStandaloneUnionBuilder() {
    ColumnMetadata columnMetadata = new UnionBuilder("u", MinorType.UNION).addType(MinorType.INT).addType(MinorType.VARCHAR).buildColumn();
    assertEquals("u", columnMetadata.name());
    assertTrue(columnMetadata.isVariant());
    VariantMetadata variantMetadata = columnMetadata.variantSchema();
    assertTrue(variantMetadata.hasType(MinorType.INT));
    assertTrue(variantMetadata.hasType(MinorType.VARCHAR));
}
Also used : VariantMetadata(org.apache.drill.exec.record.metadata.VariantMetadata) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) UnionBuilder(org.apache.drill.exec.record.metadata.UnionBuilder) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 15 with VariantMetadata

use of org.apache.drill.exec.record.metadata.VariantMetadata in project drill by apache.

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

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