Search in sources :

Example 1 with Reader

use of org.apache.drill.exec.cache.VectorSerializer.Reader 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();
}
Also used : RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) BufferedInputStream(java.io.BufferedInputStream) FileChannel(java.nio.channels.FileChannel) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) SelectionVector2(org.apache.drill.exec.record.selection.SelectionVector2) Reader(org.apache.drill.exec.cache.VectorSerializer.Reader) File(java.io.File) FileInputStream(java.io.FileInputStream) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Example 2 with Reader

use of org.apache.drill.exec.cache.VectorSerializer.Reader in project drill by apache.

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());
    }
    RowSetUtilities.verify(expected, result);
    outFile.delete();
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileChannel(java.nio.channels.FileChannel) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SelectionVector2(org.apache.drill.exec.record.selection.SelectionVector2) Reader(org.apache.drill.exec.cache.VectorSerializer.Reader) File(java.io.File) FileInputStream(java.io.FileInputStream) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 FileChannel (java.nio.channels.FileChannel)2 Reader (org.apache.drill.exec.cache.VectorSerializer.Reader)2 VectorContainer (org.apache.drill.exec.record.VectorContainer)2 SelectionVector2 (org.apache.drill.exec.record.selection.SelectionVector2)2 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)1 ExtendableRowSet (org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)1 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)1 RowSet (org.apache.drill.test.rowSet.RowSet)1 ExtendableRowSet (org.apache.drill.test.rowSet.RowSet.ExtendableRowSet)1 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)1 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)1