Search in sources :

Example 1 with RowSetSchema

use of org.apache.drill.test.rowSet.RowSetSchema in project drill by apache.

the class RowSetTest method testMapSchema.

@Test
public void testMapSchema() {
    BatchSchema batchSchema = new SchemaBuilder().add("c", MinorType.INT).addMap("a").addNullable("b", MinorType.VARCHAR).add("d", MinorType.INT).addMap("e").add("f", MinorType.VARCHAR).buildMap().add("g", MinorType.INT).buildMap().add("h", MinorType.BIGINT).build();
    RowSetSchema schema = new RowSetSchema(batchSchema);
    // Access schema: flattened with maps removed
    FlattenedSchema access = schema.flatAccess();
    assertEquals(6, access.count());
    crossCheck(access, 0, "c", MinorType.INT);
    crossCheck(access, 1, "a.b", MinorType.VARCHAR);
    crossCheck(access, 2, "a.d", MinorType.INT);
    crossCheck(access, 3, "a.e.f", MinorType.VARCHAR);
    crossCheck(access, 4, "a.g", MinorType.INT);
    crossCheck(access, 5, "h", MinorType.BIGINT);
    // Should have two maps.
    assertEquals(2, access.mapCount());
    assertEquals("a", access.map(0).getName());
    assertEquals("e", access.map(1).getName());
    assertEquals(0, access.mapIndex("a"));
    assertEquals(1, access.mapIndex("a.e"));
    // Verify physical schema: should mirror the schema created above.
    PhysicalSchema physical = schema.physical();
    assertEquals(3, physical.count());
    assertEquals("c", physical.column(0).field().getName());
    assertEquals("c", physical.column(0).fullName());
    assertFalse(physical.column(0).isMap());
    assertNull(physical.column(0).mapSchema());
    assertEquals("a", physical.column(1).field().getName());
    assertEquals("a", physical.column(1).fullName());
    assertTrue(physical.column(1).isMap());
    assertNotNull(physical.column(1).mapSchema());
    assertEquals("h", physical.column(2).field().getName());
    assertEquals("h", physical.column(2).fullName());
    assertFalse(physical.column(2).isMap());
    assertNull(physical.column(2).mapSchema());
    PhysicalSchema aSchema = physical.column(1).mapSchema();
    assertEquals(4, aSchema.count());
    assertEquals("b", aSchema.column(0).field().getName());
    assertEquals("a.b", aSchema.column(0).fullName());
    assertEquals("d", aSchema.column(1).field().getName());
    assertEquals("e", aSchema.column(2).field().getName());
    assertEquals("g", aSchema.column(3).field().getName());
    PhysicalSchema eSchema = aSchema.column(2).mapSchema();
    assertEquals(1, eSchema.count());
    assertEquals("f", eSchema.column(0).field().getName());
    assertEquals("a.e.f", eSchema.column(0).fullName());
}
Also used : PhysicalSchema(org.apache.drill.test.rowSet.RowSetSchema.PhysicalSchema) BatchSchema(org.apache.drill.exec.record.BatchSchema) FlattenedSchema(org.apache.drill.test.rowSet.RowSetSchema.FlattenedSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RowSetSchema(org.apache.drill.test.rowSet.RowSetSchema) Test(org.junit.Test)

Example 2 with RowSetSchema

use of org.apache.drill.test.rowSet.RowSetSchema in project drill by apache.

the class RowSetTest method testSchema.

/**
   * Test a simple physical schema with no maps.
   */
@Test
public void testSchema() {
    BatchSchema batchSchema = new SchemaBuilder().add("c", MinorType.INT).add("a", MinorType.INT, DataMode.REPEATED).addNullable("b", MinorType.VARCHAR).build();
    assertEquals("c", batchSchema.getColumn(0).getName());
    assertEquals("a", batchSchema.getColumn(1).getName());
    assertEquals("b", batchSchema.getColumn(2).getName());
    RowSetSchema schema = new RowSetSchema(batchSchema);
    TupleSchema access = schema.hierarchicalAccess();
    assertEquals(3, access.count());
    crossCheck(access, 0, "c", MinorType.INT);
    assertEquals(DataMode.REQUIRED, access.column(0).getDataMode());
    assertEquals(DataMode.REQUIRED, access.column(0).getType().getMode());
    assertTrue(!access.column(0).isNullable());
    crossCheck(access, 1, "a", MinorType.INT);
    assertEquals(DataMode.REPEATED, access.column(1).getDataMode());
    assertEquals(DataMode.REPEATED, access.column(1).getType().getMode());
    assertTrue(!access.column(1).isNullable());
    crossCheck(access, 2, "b", MinorType.VARCHAR);
    assertEquals(MinorType.VARCHAR, access.column(2).getType().getMinorType());
    assertEquals(DataMode.OPTIONAL, access.column(2).getDataMode());
    assertEquals(DataMode.OPTIONAL, access.column(2).getType().getMode());
    assertTrue(access.column(2).isNullable());
    // No maps: physical schema is the same as access schema.
    PhysicalSchema physical = schema.physical();
    assertEquals(3, physical.count());
    assertEquals("c", physical.column(0).field().getName());
    assertEquals("a", physical.column(1).field().getName());
    assertEquals("b", physical.column(2).field().getName());
}
Also used : PhysicalSchema(org.apache.drill.test.rowSet.RowSetSchema.PhysicalSchema) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RowSetSchema(org.apache.drill.test.rowSet.RowSetSchema) TupleSchema(org.apache.drill.exec.vector.accessor.TupleAccessor.TupleSchema) Test(org.junit.Test)

Aggregations

BatchSchema (org.apache.drill.exec.record.BatchSchema)2 RowSetSchema (org.apache.drill.test.rowSet.RowSetSchema)2 PhysicalSchema (org.apache.drill.test.rowSet.RowSetSchema.PhysicalSchema)2 SchemaBuilder (org.apache.drill.test.rowSet.SchemaBuilder)2 Test (org.junit.Test)2 TupleSchema (org.apache.drill.exec.vector.accessor.TupleAccessor.TupleSchema)1 FlattenedSchema (org.apache.drill.test.rowSet.RowSetSchema.FlattenedSchema)1