Search in sources :

Example 11 with SchemaBuilder

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

the class RowSetTest method testDoubleRW.

private void testDoubleRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.FLOAT8).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).add(0D).add(Double.MAX_VALUE).add(Double.MIN_VALUE).build();
    RowSetReader reader = rs.reader();
    assertTrue(reader.next());
    assertEquals(0, reader.column(0).getDouble(), 0.000001);
    assertTrue(reader.next());
    assertEquals(Double.MAX_VALUE, reader.column(0).getDouble(), 0.000001);
    assertTrue(reader.next());
    assertEquals(Double.MIN_VALUE, reader.column(0).getDouble(), 0.000001);
    assertFalse(reader.next());
    rs.clear();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSet.RowSetReader)

Example 12 with SchemaBuilder

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

the class RowSetTest method testMap.

@Test
public void testMap() {
    BatchSchema batchSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("b").add("c", MinorType.INT).add("d", MinorType.INT).buildMap().build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).add(10, 20, 30).add(40, 50, 60).build();
    RowSetReader reader = rs.reader();
    assertTrue(reader.next());
    assertEquals(10, reader.column(0).getInt());
    assertEquals(20, reader.column(1).getInt());
    assertEquals(30, reader.column(2).getInt());
    assertEquals(10, reader.column("a").getInt());
    assertEquals(30, reader.column("b.d").getInt());
    assertTrue(reader.next());
    assertEquals(40, reader.column(0).getInt());
    assertEquals(50, reader.column(1).getInt());
    assertEquals(60, reader.column(2).getInt());
    assertFalse(reader.next());
    rs.clear();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSet.RowSetReader) Test(org.junit.Test)

Example 13 with SchemaBuilder

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

the class RowSetTest method testLongRW.

private void testLongRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.BIGINT).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).add(0L).add(Long.MAX_VALUE).add(Long.MIN_VALUE).build();
    RowSetReader reader = rs.reader();
    assertTrue(reader.next());
    assertEquals(0, reader.column(0).getLong());
    assertTrue(reader.next());
    assertEquals(Long.MAX_VALUE, reader.column(0).getLong());
    assertTrue(reader.next());
    assertEquals(Long.MIN_VALUE, reader.column(0).getLong());
    assertFalse(reader.next());
    rs.clear();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSet.RowSetReader)

Example 14 with SchemaBuilder

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

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

the class RowSetTest method testSmallIntRW.

private void testSmallIntRW() {
    BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.SMALLINT).build();
    SingleRowSet rs = fixture.rowSetBuilder(batchSchema).add(0).add(Short.MAX_VALUE).add(Short.MIN_VALUE).build();
    RowSetReader reader = rs.reader();
    assertTrue(reader.next());
    assertEquals(0, reader.column(0).getInt());
    assertTrue(reader.next());
    assertEquals(Short.MAX_VALUE, reader.column(0).getInt());
    assertTrue(reader.next());
    assertEquals(Short.MIN_VALUE, reader.column(0).getInt());
    assertFalse(reader.next());
    rs.clear();
}
Also used : SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSet.RowSetReader)

Aggregations

BatchSchema (org.apache.drill.exec.record.BatchSchema)26 SchemaBuilder (org.apache.drill.test.rowSet.SchemaBuilder)26 Test (org.junit.Test)20 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)18 BatchValidator (org.apache.drill.exec.physical.impl.validate.BatchValidator)10 RowSetReader (org.apache.drill.test.rowSet.RowSet.RowSetReader)8 RecordBatch (org.apache.drill.exec.record.RecordBatch)4 VectorAccessible (org.apache.drill.exec.record.VectorAccessible)3 RepeatedVarCharVector (org.apache.drill.exec.vector.RepeatedVarCharVector)3 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)3 ValueVector (org.apache.drill.exec.vector.ValueVector)3 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)3 Filter (org.apache.drill.exec.physical.config.Filter)2 UnionAll (org.apache.drill.exec.physical.config.UnionAll)2 VarCharVector (org.apache.drill.exec.vector.VarCharVector)2 ClusterTest (org.apache.drill.test.ClusterTest)2 RowSet (org.apache.drill.test.rowSet.RowSet)2 RowSetBuilder (org.apache.drill.test.rowSet.RowSetBuilder)2 RowSetSchema (org.apache.drill.test.rowSet.RowSetSchema)2 PhysicalSchema (org.apache.drill.test.rowSet.RowSetSchema.PhysicalSchema)2