Search in sources :

Example 66 with SchemaBuilder

use of org.apache.drill.test.rowSet.schema.SchemaBuilder 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 67 with SchemaBuilder

use of org.apache.drill.test.rowSet.schema.SchemaBuilder 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 68 with SchemaBuilder

use of org.apache.drill.test.rowSet.schema.SchemaBuilder 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 69 with SchemaBuilder

use of org.apache.drill.test.rowSet.schema.SchemaBuilder 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 70 with SchemaBuilder

use of org.apache.drill.test.rowSet.schema.SchemaBuilder 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

SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)175 Test (org.junit.Test)154 BatchSchema (org.apache.drill.exec.record.BatchSchema)102 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)91 SubOperatorTest (org.apache.drill.test.SubOperatorTest)86 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)65 RowSet (org.apache.drill.test.rowSet.RowSet)52 RowSetReader (org.apache.drill.test.rowSet.RowSetReader)50 ResultSetLoader (org.apache.drill.exec.physical.rowSet.ResultSetLoader)38 RowSetLoader (org.apache.drill.exec.physical.rowSet.RowSetLoader)38 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)26 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)25 DrillTest (org.apache.drill.test.DrillTest)21 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)20 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)18 RowSetBuilder (org.apache.drill.test.rowSet.RowSetBuilder)18 ScalarElementReader (org.apache.drill.exec.vector.accessor.ScalarElementReader)17 AbstractColumnMetadata (org.apache.drill.exec.record.metadata.AbstractColumnMetadata)16 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)16 RecordBatch (org.apache.drill.exec.record.RecordBatch)14