Search in sources :

Example 71 with ColumnMetadata

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

the class TestSchemaBuilder method testRepeatedListInRow.

/**
 * Test building a repeated list in the top-level schema.
 */
@Test
public void testRepeatedListInRow() {
    TupleMetadata schema = new SchemaBuilder().addRepeatedList("list").addArray(MinorType.VARCHAR).resumeSchema().buildSchema();
    assertEquals(1, schema.size());
    ColumnMetadata list = schema.metadata(0);
    assertEquals("list", list.name());
    assertFalse(list.isVariant());
    assertEquals(StructureType.MULTI_ARRAY, list.structureType());
    assertEquals(MinorType.LIST, list.type());
    // See note above for the (non-repeated) list.
    assertEquals(DataMode.REPEATED, list.mode());
    ColumnMetadata child = list.childSchema();
    assertNotNull(child);
    assertEquals(list.name(), child.name());
    assertEquals(MinorType.VARCHAR, child.type());
    assertEquals(DataMode.REPEATED, child.mode());
}
Also used : 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 72 with ColumnMetadata

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

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

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

the class TestSchemaBuilder method testRepeatedListShortcut.

@Test
public void testRepeatedListShortcut() {
    TupleMetadata schema = new SchemaBuilder().addArray("x", MinorType.VARCHAR, 3).buildSchema();
    assertEquals(1, schema.size());
    ColumnMetadata outerList = schema.metadata(0);
    assertEquals("x", outerList.name());
    assertEquals(StructureType.MULTI_ARRAY, outerList.structureType());
    assertEquals(MinorType.LIST, outerList.type());
    assertEquals(DataMode.REPEATED, outerList.mode());
    ColumnMetadata innerList = outerList.childSchema();
    assertNotNull(innerList);
    assertEquals(outerList.name(), innerList.name());
    assertEquals(StructureType.MULTI_ARRAY, innerList.structureType());
    assertEquals(MinorType.LIST, innerList.type());
    assertEquals(DataMode.REPEATED, innerList.mode());
    ColumnMetadata child = innerList.childSchema();
    assertNotNull(child);
    assertEquals(outerList.name(), child.name());
    assertEquals(MinorType.VARCHAR, child.type());
    assertEquals(DataMode.REPEATED, child.mode());
}
Also used : 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 75 with ColumnMetadata

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

the class TestSchemaBuilder method testVarDecimal.

@Test
public void testVarDecimal() {
    TupleMetadata schema = new SchemaBuilder().addNullable("a", MinorType.VARDECIMAL, 5, 2).add("b", MinorType.VARDECIMAL, 6, 3).addArray("c", MinorType.VARDECIMAL, 7, 4).add("e", MinorType.VARDECIMAL).add("g", MinorType.VARDECIMAL, 38, 4).addMap("m").addNullable("d", MinorType.VARDECIMAL, 8, 1).add("f", MinorType.VARDECIMAL).resumeSchema().buildSchema();
    // Use name methods, just for variety
    ColumnMetadata a = schema.metadata("a");
    assertEquals(MinorType.VARDECIMAL, a.type());
    assertEquals(DataMode.OPTIONAL, a.mode());
    assertEquals(5, a.precision());
    assertEquals(2, a.scale());
    ColumnMetadata b = schema.metadata("b");
    assertEquals(MinorType.VARDECIMAL, b.type());
    assertEquals(DataMode.REQUIRED, b.mode());
    assertEquals(6, b.precision());
    assertEquals(3, b.scale());
    ColumnMetadata c = schema.metadata("c");
    assertEquals(MinorType.VARDECIMAL, c.type());
    assertEquals(DataMode.REPEATED, c.mode());
    assertEquals(7, c.precision());
    assertEquals(4, c.scale());
    ColumnMetadata e = schema.metadata("e");
    assertEquals(MinorType.VARDECIMAL, e.type());
    assertEquals(DataMode.REQUIRED, e.mode());
    assertEquals(38, e.precision());
    assertEquals(0, e.scale());
    ColumnMetadata g = schema.metadata("g");
    assertEquals(MinorType.VARDECIMAL, g.type());
    assertEquals(DataMode.REQUIRED, g.mode());
    assertEquals(38, g.precision());
    assertEquals(4, g.scale());
    ColumnMetadata d = schema.metadata("m").tupleSchema().metadata("d");
    assertEquals(MinorType.VARDECIMAL, d.type());
    assertEquals(DataMode.OPTIONAL, d.mode());
    assertEquals(8, d.precision());
    assertEquals(1, d.scale());
    ColumnMetadata f = schema.metadata("m").tupleSchema().metadata("f");
    assertEquals(MinorType.VARDECIMAL, f.type());
    assertEquals(DataMode.REQUIRED, f.mode());
    assertEquals(38, f.precision());
    assertEquals(0, f.scale());
}
Also used : 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)195 Test (org.junit.Test)104 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)98 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)50 DrillTest (org.apache.drill.test.DrillTest)37 PrimitiveColumnMetadata (org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata)31 SubOperatorTest (org.apache.drill.test.SubOperatorTest)31 BaseTest (org.apache.drill.test.BaseTest)26 MapColumnMetadata (org.apache.drill.exec.record.metadata.MapColumnMetadata)20 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)20 VariantColumnMetadata (org.apache.drill.exec.record.metadata.VariantColumnMetadata)19 VariantMetadata (org.apache.drill.exec.record.metadata.VariantMetadata)19 AbstractColumnMetadata (org.apache.drill.exec.record.metadata.AbstractColumnMetadata)17 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)17 DictColumnMetadata (org.apache.drill.exec.record.metadata.DictColumnMetadata)15 EvfTest (org.apache.drill.categories.EvfTest)13 ProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter)13 TupleSchema (org.apache.drill.exec.record.metadata.TupleSchema)11 ArrayList (java.util.ArrayList)10 ProjResult (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult)10