mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-05 15:21:43 +00:00
35 lines
807 B
C++
35 lines
807 B
C++
|
#pragma once
|
||
|
|
||
|
#include <memory>
|
||
|
|
||
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
||
|
|
||
|
namespace DB
|
||
|
{
|
||
|
|
||
|
/** Provides reading from a Buffer, taking exclusive ownership over it's lifetime,
|
||
|
* simplifies usage of ReadBufferFromFile (no need to manage buffer lifetime) etc.
|
||
|
*/
|
||
|
template <typename OwnType>
|
||
|
class OwningBlockInputStream : public IProfilingBlockInputStream
|
||
|
{
|
||
|
public:
|
||
|
OwningBlockInputStream(const BlockInputStreamPtr & stream, std::unique_ptr<OwnType> own)
|
||
|
: stream{stream}, own{std::move(own)}
|
||
|
{
|
||
|
children.push_back(stream);
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
Block readImpl() override { return stream->read(); }
|
||
|
|
||
|
String getName() const override { return "Owning"; }
|
||
|
|
||
|
String getID() const override { return "Owning(" + stream->getID() + ")"; }
|
||
|
|
||
|
BlockInputStreamPtr stream;
|
||
|
std::unique_ptr<OwnType> own;
|
||
|
};
|
||
|
|
||
|
}
|