use of org.apache.drill.test.rowSet.SchemaBuilder 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());
}
use of org.apache.drill.test.rowSet.SchemaBuilder in project drill by apache.
the class RowSetTest method testFloatRW.
private void testFloatRW() {
BatchSchema batchSchema = new SchemaBuilder().add("col", MinorType.FLOAT4).build();
SingleRowSet rs = fixture.rowSetBuilder(batchSchema).add(0F).add(Float.MAX_VALUE).add(Float.MIN_VALUE).build();
RowSetReader reader = rs.reader();
assertTrue(reader.next());
assertEquals(0, reader.column(0).getDouble(), 0.000001);
assertTrue(reader.next());
assertEquals(Float.MAX_VALUE, reader.column(0).getDouble(), 0.000001);
assertTrue(reader.next());
assertEquals(Float.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 TestCsv method testInvalidCsvHeaders.
@Test
public void testInvalidCsvHeaders() throws IOException {
String fileName = "case3.csv";
buildFile(fileName, invalidHeaders);
RowSet actual = client.queryBuilder().sql(makeStatement(fileName)).rowSet();
BatchSchema expectedSchema = new SchemaBuilder().add("column_1", MinorType.VARCHAR).add("column_2", MinorType.VARCHAR).add("col_9b", MinorType.VARCHAR).add("c", MinorType.VARCHAR).add("c_2", MinorType.VARCHAR).add("c_2_2", MinorType.VARCHAR).build();
assertEquals(expectedSchema, actual.batchSchema());
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).add("10", "foo", "bar", "fourth", "fifth", "sixth").build();
new RowSetComparison(expected).verifyAndClear(actual);
}
use of org.apache.drill.test.rowSet.SchemaBuilder in project drill by apache.
the class TestCsv method testValidCsvHeaders.
@Test
public void testValidCsvHeaders() throws IOException {
String fileName = "case2.csv";
buildFile(fileName, validHeaders);
RowSet actual = client.queryBuilder().sql(makeStatement(fileName)).rowSet();
BatchSchema expectedSchema = new SchemaBuilder().add("a", MinorType.VARCHAR).add("b", MinorType.VARCHAR).add("c", MinorType.VARCHAR).build();
assertEquals(expectedSchema, actual.batchSchema());
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).add("10", "foo", "bar").build();
new RowSetComparison(expected).verifyAndClear(actual);
}
use of org.apache.drill.test.rowSet.SchemaBuilder in project drill by apache.
the class TestBatchValidator method testVariableCorruptFirst.
@Test
public void testVariableCorruptFirst() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR).build();
SingleRowSet batch = fixture.rowSetBuilder(schema).add("x").add("y").add("z").build();
zapOffset(batch, 0, 1);
// Validator should catch the error.
BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
validator.validate();
List<String> errors = validator.errors();
assertEquals(1, errors.size());
assertTrue(errors.get(0).contains("Offset (0) must be 0"));
batch.clear();
}
Aggregations