2016-11-17 01:09:46 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2016-11-17 01:09:46 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Provides reading from a Buffer, taking exclusive ownership over it's lifetime,
|
2017-05-25 19:26:17 +00:00
|
|
|
* simplifies usage of ReadBufferFromFile (no need to manage buffer lifetime) etc.
|
|
|
|
*/
|
2016-11-17 01:09:46 +00:00
|
|
|
template <typename OwnType>
|
2019-01-23 14:48:50 +00:00
|
|
|
class OwningBlockInputStream : public IBlockInputStream
|
2016-11-17 01:09:46 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
OwningBlockInputStream(const BlockInputStreamPtr & stream, std::unique_ptr<OwnType> own)
|
|
|
|
: stream{stream}, own{std::move(own)}
|
|
|
|
{
|
|
|
|
children.push_back(stream);
|
|
|
|
}
|
2016-11-17 01:09:46 +00:00
|
|
|
|
2018-02-18 03:23:48 +00:00
|
|
|
Block getHeader() const override { return children.at(0)->getHeader(); }
|
2018-01-06 18:10:44 +00:00
|
|
|
|
2016-11-17 01:09:46 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
Block readImpl() override { return stream->read(); }
|
2016-11-17 01:09:46 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getName() const override { return "Owning"; }
|
2016-11-17 01:09:46 +00:00
|
|
|
|
2017-10-02 13:08:09 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreamPtr stream;
|
|
|
|
std::unique_ptr<OwnType> own;
|
2016-11-17 01:09:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|