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