use of org.apache.drill.test.rowSet.RowSet.SingleRowSet 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();
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestBatchSerialization method verifySerialize.
/**
* Verify serialize and deserialize. Need to pass both the
* input and expected (even though the expected should be the same
* data as the input) because the act of serializing clears the
* input for obscure historical reasons.
*
* @param rowSet
* @param expected
* @throws IOException
*/
private void verifySerialize(SingleRowSet rowSet, SingleRowSet expected) throws IOException {
File dir = DirTestWatcher.createTempDir(dirTestWatcher.getDir());
FileChannel channel = FileChannel.open(new File(dir, "serialize.dat").toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
VectorSerializer.Writer writer = VectorSerializer.writer(channel);
VectorContainer container = rowSet.container();
SelectionVector2 sv2 = rowSet.getSv2();
writer.write(container, sv2);
container.clear();
if (sv2 != null) {
sv2.clear();
}
writer.close();
File outFile = new File(dir, "serialize.dat");
assertTrue(outFile.exists());
assertTrue(outFile.isFile());
RowSet result;
try (InputStream in = new BufferedInputStream(new FileInputStream(outFile))) {
Reader reader = VectorSerializer.reader(fixture.allocator(), in);
result = fixture.wrap(reader.read(), reader.sv2());
}
new RowSetComparison(expected).verifyAndClearAll(result);
outFile.delete();
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestOperatorRecordBatch method testBatchAccessor.
/**
* The record batch abstraction has a bunch of methods to work with a vector container.
* Rather than simply exposing the container itself, the batch instead exposes various
* container operations. Probably an artifact of its history. In any event, make
* sure those methods are passed through to the container accessor.
*/
@Test
public void testBatchAccessor() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).build();
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(10, "fred").addRow(20, "wilma").build();
MockOperatorExec opExec = new MockOperatorExec(rs.container());
opExec.nextCalls = 1;
try (OperatorRecordBatch opBatch = makeOpBatch(opExec)) {
assertEquals(IterOutcome.OK_NEW_SCHEMA, opBatch.next());
assertEquals(schema, opBatch.getSchema());
assertEquals(2, opBatch.getRecordCount());
assertSame(rs.container(), opBatch.getOutgoingContainer());
Iterator<VectorWrapper<?>> iter = opBatch.iterator();
assertEquals("a", iter.next().getValueVector().getField().getName());
assertEquals("b", iter.next().getValueVector().getField().getName());
// Not a full test of the schema path; just make sure that the
// pass-through to the Vector Container works.
SchemaPath path = SchemaPath.create(NamePart.newBuilder().setName("a").build());
TypedFieldId id = opBatch.getValueVectorId(path);
assertEquals(MinorType.INT, id.getFinalType().getMinorType());
assertEquals(1, id.getFieldIds().length);
assertEquals(0, id.getFieldIds()[0]);
path = SchemaPath.create(NamePart.newBuilder().setName("b").build());
id = opBatch.getValueVectorId(path);
assertEquals(MinorType.VARCHAR, id.getFinalType().getMinorType());
assertEquals(1, id.getFieldIds().length);
assertEquals(1, id.getFieldIds()[0]);
// Sanity check of getValueAccessorById()
VectorWrapper<?> w = opBatch.getValueAccessorById(IntVector.class, 0);
assertNotNull(w);
assertEquals("a", w.getValueVector().getField().getName());
w = opBatch.getValueAccessorById(VarCharVector.class, 1);
assertNotNull(w);
assertEquals("b", w.getValueVector().getField().getName());
try {
opBatch.getSelectionVector2();
fail();
} catch (UnsupportedOperationException e) {
// Expected
}
try {
opBatch.getSelectionVector4();
fail();
} catch (UnsupportedOperationException e) {
// Expected
}
} catch (Exception e) {
fail(e.getMessage());
}
assertTrue(opExec.closeCalled);
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestOperatorRecordBatch method testSv2.
/**
* Test that an SV2 is properly handled by the proper container accessor.
*/
@Test
public void testSv2() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.INT).add("b", MinorType.VARCHAR).build();
SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(10, "fred").addRow(20, "wilma").withSv2().build();
ContainerAndSv2Accessor accessor = new ContainerAndSv2Accessor();
accessor.setContainer(rs.container());
accessor.setSelectionVector(rs.getSv2());
MockOperatorExec opExec = new MockOperatorExec(accessor);
opExec.nextCalls = 1;
try (OperatorRecordBatch opBatch = makeOpBatch(opExec)) {
assertEquals(IterOutcome.OK_NEW_SCHEMA, opBatch.next());
assertSame(rs.getSv2(), opBatch.getSelectionVector2());
} catch (Exception e) {
fail();
}
assertTrue(opExec.closeCalled);
// Must release SV2
rs.clear();
}
use of org.apache.drill.test.rowSet.RowSet.SingleRowSet in project drill by axbaretto.
the class TestBatchValidator method testVariableCorruptFirst.
@Test
public void testVariableCorruptFirst() {
BatchSchema schema = new SchemaBuilder().add("a", MinorType.VARCHAR).build();
SingleRowSet batch = fixture.rowSetBuilder(schema).addRow("x").addRow("y").addRow("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