2015-01-28 16:23:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/IO/ReadBuffer.h>
|
|
|
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2015-02-10 14:50:43 +00:00
|
|
|
/** Provides reading from a Buffer, taking exclusive ownership over it's lifetime,
|
|
|
|
* simplifies usage of ReadBufferFromFile (no need to manage buffer lifetime) etc.
|
|
|
|
*/
|
2015-01-28 16:23:52 +00:00
|
|
|
class OwningBufferBlockInputStream : public IProfilingBlockInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OwningBufferBlockInputStream(const BlockInputStreamPtr & stream, std::unique_ptr<ReadBuffer> buffer)
|
|
|
|
: stream{stream}, buffer{std::move(buffer)}
|
|
|
|
{
|
|
|
|
children.push_back(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Block readImpl() override { return stream->read(); }
|
|
|
|
|
2015-06-08 20:22:02 +00:00
|
|
|
String getName() const override { return "OwningBuffer"; }
|
2015-01-28 16:23:52 +00:00
|
|
|
|
2015-02-10 14:50:43 +00:00
|
|
|
String getID() const override { return "OwningBuffer(" + stream->getID() + ")"; }
|
2015-01-28 16:23:52 +00:00
|
|
|
|
|
|
|
BlockInputStreamPtr stream;
|
|
|
|
std::unique_ptr<ReadBuffer> buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|