Search in sources :

Example 1 with VariantColumnMetadata

use of org.apache.drill.exec.record.metadata.VariantColumnMetadata 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 2 with VariantColumnMetadata

use of org.apache.drill.exec.record.metadata.VariantColumnMetadata 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 3 with VariantColumnMetadata

use of org.apache.drill.exec.record.metadata.VariantColumnMetadata 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)

Aggregations

ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)3 MapColumnMetadata (org.apache.drill.exec.record.metadata.MapColumnMetadata)3 PrimitiveColumnMetadata (org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata)3 VariantColumnMetadata (org.apache.drill.exec.record.metadata.VariantColumnMetadata)3 VariantMetadata (org.apache.drill.exec.record.metadata.VariantMetadata)3 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)2 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)2 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)2 TupleSchema (org.apache.drill.exec.record.metadata.TupleSchema)2 SubOperatorTest (org.apache.drill.test.SubOperatorTest)2 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)2 Test (org.junit.Test)2