Search in sources :

Example 96 with ColumnMetadata

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

the class TestSchemaBuilder method testRowBasics.

@Test
public void testRowBasics() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.VARCHAR, // Generic
    DataMode.OPTIONAL).add("b", // Required
    MinorType.INT).addNullable("c", // Convenience
    MinorType.FLOAT8).addArray("d", // Convenience
    MinorType.BIGINT).buildSchema();
    assertEquals(4, schema.size());
    ColumnMetadata a = schema.metadata(0);
    assertEquals("a", a.name());
    assertEquals(MinorType.VARCHAR, a.type());
    assertEquals(DataMode.OPTIONAL, a.mode());
    ColumnMetadata b = schema.metadata(1);
    assertEquals("b", b.name());
    assertEquals(MinorType.INT, b.type());
    assertEquals(DataMode.REQUIRED, b.mode());
    ColumnMetadata c = schema.metadata(2);
    assertEquals("c", c.name());
    assertEquals(MinorType.FLOAT8, c.type());
    assertEquals(DataMode.OPTIONAL, c.mode());
    ColumnMetadata d = schema.metadata(3);
    assertEquals("d", d.name());
    assertEquals(MinorType.BIGINT, d.type());
    assertEquals(DataMode.REPEATED, d.mode());
}
Also used : 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)

Example 97 with ColumnMetadata

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

the class TestSchemaBuilder method testRepeatedListInMap.

/**
 * Verify that the repeated list-in-map plumbing works.
 */
@Test
public void testRepeatedListInMap() {
    TupleMetadata schema = new SchemaBuilder().addMap("m1").addRepeatedList("r").addArray(MinorType.INT).resumeMap().add("b", MinorType.VARCHAR).resumeSchema().buildSchema();
    TupleMetadata m1Schema = schema.metadata("m1").mapSchema();
    ColumnMetadata r = m1Schema.metadata(0);
    assertEquals("r", r.name());
    assertEquals(MinorType.LIST, r.type());
    assertEquals(DataMode.REPEATED, r.mode());
    ColumnMetadata child = r.childSchema();
    assertEquals(r.name(), child.name());
    assertEquals(MinorType.INT, child.type());
    ColumnMetadata b = m1Schema.metadata(1);
    assertEquals("b", b.name());
    assertEquals(MinorType.VARCHAR, b.type());
}
Also used : 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)

Example 98 with ColumnMetadata

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

Example 99 with ColumnMetadata

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

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").mapSchema();
    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) 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)

Example 100 with ColumnMetadata

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

the class TestSchemaBuilder method testListInRow.

/**
 * Test building a list (of unions) in the top-level schema.
 */
@Test
public void testListInRow() {
    TupleMetadata schema = new SchemaBuilder().addList("list").addType(MinorType.VARCHAR).addType(MinorType.INT).resumeSchema().buildSchema();
    assertEquals(1, schema.size());
    ColumnMetadata list = schema.metadata(0);
    assertEquals("list", list.name());
    assertEquals(StructureType.VARIANT, list.structureType());
    assertTrue(list.isVariant());
    assertEquals(MinorType.LIST, list.type());
    // Yes, strange. Though a list is, essentially, an array, an
    // optional list has one set of semantics (in ListVector, not
    // really supported), while a repeated list has entirely different
    // semantics (in the RepeatedListVector) and is supported.
    assertEquals(DataMode.OPTIONAL, list.mode());
    VariantMetadata variant = list.variantSchema();
    assertNotNull(variant);
    assertEquals(2, variant.size());
    assertTrue(variant.hasType(MinorType.VARCHAR));
    ColumnMetadata vMember = variant.member(MinorType.VARCHAR);
    assertNotNull(vMember);
    assertEquals(Types.typeKey(MinorType.VARCHAR), vMember.name());
    assertEquals(MinorType.VARCHAR, vMember.type());
    assertEquals(DataMode.OPTIONAL, vMember.mode());
    assertTrue(variant.hasType(MinorType.INT));
    ColumnMetadata iMember = variant.member(MinorType.INT);
    assertNotNull(iMember);
    assertEquals(Types.typeKey(MinorType.INT), iMember.name());
    assertEquals(MinorType.INT, iMember.type());
    assertEquals(DataMode.OPTIONAL, iMember.mode());
}
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)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