Search in sources :

Example 11 with ColumnMetadata

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

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 : 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 12 with ColumnMetadata

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

the class TestSchemaBuilder method testMapInRow.

/**
 * Tests creating a map within a row.
 * Also the basic map add column methods.
 */
@Test
public void testMapInRow() {
    TupleMetadata schema = new SchemaBuilder().addMap("m").add("a", MinorType.VARCHAR, // Generic
    DataMode.OPTIONAL).add("b", // Required
    MinorType.INT).addNullable("c", // Convenience
    MinorType.FLOAT8).addArray("d", // Convenience
    MinorType.BIGINT).resumeSchema().buildSchema();
    assertEquals(1, schema.size());
    ColumnMetadata m = schema.metadata(0);
    assertEquals("m", m.name());
    assertTrue(m.isMap());
    assertEquals(DataMode.REQUIRED, m.mode());
    TupleMetadata mapSchema = m.mapSchema();
    assertNotNull(mapSchema);
    assertEquals(4, mapSchema.size());
    ColumnMetadata a = mapSchema.metadata(0);
    assertEquals("a", a.name());
    assertEquals(MinorType.VARCHAR, a.type());
    assertEquals(DataMode.OPTIONAL, a.mode());
    ColumnMetadata b = mapSchema.metadata(1);
    assertEquals("b", b.name());
    assertEquals(MinorType.INT, b.type());
    assertEquals(DataMode.REQUIRED, b.mode());
    ColumnMetadata c = mapSchema.metadata(2);
    assertEquals("c", c.name());
    assertEquals(MinorType.FLOAT8, c.type());
    assertEquals(DataMode.OPTIONAL, c.mode());
    ColumnMetadata d = mapSchema.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 13 with ColumnMetadata

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

the class TestSchemaBuilder method testMapInRepeatedList.

// Note: union-in-union not supported in Drill
@Test
public void testMapInRepeatedList() {
    TupleMetadata schema = new SchemaBuilder().addRepeatedList("x").addMapArray().add("a", MinorType.INT).addNullable("b", MinorType.VARCHAR).resumeList().resumeSchema().buildSchema();
    ColumnMetadata list = schema.metadata("x");
    ColumnMetadata mapCol = list.childSchema();
    assertTrue(mapCol.isMap());
    TupleMetadata mapSchema = mapCol.mapSchema();
    ColumnMetadata a = mapSchema.metadata("a");
    assertEquals(MinorType.INT, a.type());
    assertEquals(DataMode.REQUIRED, a.mode());
    ColumnMetadata b = mapSchema.metadata("b");
    assertEquals(MinorType.VARCHAR, b.type());
    assertEquals(DataMode.OPTIONAL, b.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 14 with ColumnMetadata

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

the class TestSchemaBuilder method testMapInMap.

/**
 * Verify that the map-in-map plumbing works.
 */
@Test
public void testMapInMap() {
    TupleMetadata schema = new SchemaBuilder().addMap("m1").addMap("m2").add("a", MinorType.INT).resumeMap().add("b", MinorType.VARCHAR).resumeSchema().buildSchema();
    TupleMetadata m1Schema = schema.metadata("m1").mapSchema();
    TupleMetadata m2Schema = m1Schema.metadata("m2").mapSchema();
    ColumnMetadata a = m2Schema.metadata(0);
    assertEquals("a", a.name());
    assertEquals(MinorType.INT, a.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 15 with ColumnMetadata

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

the class TestSchemaBuilder method testRepeatedListInRepeatedList.

/**
 * Test that repeated lists can be nested to provide 3D or
 * higher dimensions.
 */
@Test
public void testRepeatedListInRepeatedList() {
    TupleMetadata schema = new SchemaBuilder().addRepeatedList("x").addDimension().addArray(MinorType.VARCHAR).resumeList().resumeSchema().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 : 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