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();
}
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();
}
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();
}
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());
}
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();
}
Aggregations