use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestSorter method testEmptyRowSet.
// Test degenerate case: no rows
@Test
public void testEmptyRowSet() throws Exception {
BatchSchema schema = SortTestUtilities.nonNullSchema();
SingleRowSet rowSet = new RowSetBuilder(fixture.allocator(), schema).withSv2().build();
SingleRowSet expected = new RowSetBuilder(fixture.allocator(), schema).build();
runSorterTest(rowSet, expected);
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestResultSetLoaderMaps method testNestedMapsRequired.
/**
* Create nested maps. Then, add columns to each map
* on the fly. Use required, variable-width columns since
* those require the most processing and are most likely to
* fail if anything is out of place.
*/
@Test
public void testNestedMapsRequired() {
TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMap("m1").add("b", MinorType.VARCHAR).addMap("m2").add("c", MinorType.VARCHAR).resumeMap().resumeSchema().buildSchema();
ResultSetLoaderImpl.ResultSetOptions options = new OptionBuilder().setSchema(schema).build();
ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
assertEquals(5, rsLoader.schemaVersion());
RowSetLoader rootWriter = rsLoader.writer();
rsLoader.startBatch();
rootWriter.addRow(10, objArray("b1", objArray("c1")));
// Validate first batch
RowSet actual = fixture.wrap(rsLoader.harvest());
assertEquals(5, rsLoader.schemaVersion());
SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, objArray("b1", objArray("c1"))).build();
new RowSetComparison(expected).verifyAndClearAll(actual);
// Now add columns in the second batch.
rsLoader.startBatch();
rootWriter.addRow(20, objArray("b2", objArray("c2")));
TupleWriter m1Writer = rootWriter.tuple("m1");
m1Writer.addColumn(SchemaBuilder.columnSchema("d", MinorType.VARCHAR, DataMode.REQUIRED));
TupleWriter m2Writer = m1Writer.tuple("m2");
m2Writer.addColumn(SchemaBuilder.columnSchema("e", MinorType.VARCHAR, DataMode.REQUIRED));
rootWriter.addRow(30, objArray("b3", objArray("c3", "e3"), "d3"));
// And another set while the write proceeds.
m1Writer.addColumn(SchemaBuilder.columnSchema("f", MinorType.VARCHAR, DataMode.REQUIRED));
m2Writer.addColumn(SchemaBuilder.columnSchema("g", MinorType.VARCHAR, DataMode.REQUIRED));
rootWriter.addRow(40, objArray("b4", objArray("c4", "e4", "g4"), "d4", "e4"));
// Validate second batch
actual = fixture.wrap(rsLoader.harvest());
assertEquals(9, rsLoader.schemaVersion());
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addMap("m1").add("b", MinorType.VARCHAR).addMap("m2").add("c", MinorType.VARCHAR).add("e", MinorType.VARCHAR).add("g", MinorType.VARCHAR).resumeMap().add("d", MinorType.VARCHAR).add("f", MinorType.VARCHAR).resumeSchema().buildSchema();
expected = fixture.rowSetBuilder(expectedSchema).addRow(20, objArray("b2", objArray("c2", "", ""), "", "")).addRow(30, objArray("b3", objArray("c3", "e3", ""), "d3", "")).addRow(40, objArray("b4", objArray("c4", "e4", "g4"), "d4", "e4")).build();
new RowSetComparison(expected).verifyAndClearAll(actual);
rsLoader.close();
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestBatchValidator method testValidFixed.
@Test
public void testValidFixed() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).addNullable("b", MinorType.INT).build();
SingleRowSet batch = fixture.rowSetBuilder(schema).addRow(10, 100).addRow(20, 120).addRow(30, null).addRow(40, 140).build();
BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
validator.validate();
assertTrue(validator.errors().isEmpty());
batch.clear();
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestBatchValidator method testVariableMissingLast.
@Test
public void testVariableMissingLast() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR).build();
SingleRowSet batch = fixture.rowSetBuilder(schema).addRow("x").addRow("y").addRow("z").build();
// Here we are evil: stomp on the last offset to simulate corruption.
// Don't do this in real code!
VectorAccessible va = batch.vectorAccessible();
ValueVector v = va.iterator().next().getValueVector();
VarCharVector vc = (VarCharVector) v;
UInt4Vector ov = vc.getOffsetVector();
assertTrue(ov.getAccessor().get(3) > 0);
ov.getMutator().set(3, 0);
// 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("Decreasing offsets"));
batch.clear();
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestBatchValidator method testValidRepeated.
@Test
public void testValidRepeated() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT, DataMode.REPEATED).add("b", MinorType.VARCHAR, DataMode.REPEATED).build();
SingleRowSet batch = fixture.rowSetBuilder(schema).addRow(intArray(), strArray()).addRow(intArray(1, 2, 3), strArray("fred", "barney", "wilma")).addRow(intArray(4), strArray("dino")).build();
BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
validator.validate();
assertTrue(validator.errors().isEmpty());
batch.clear();
}
Aggregations