ClickHouse/dbms/src/DataStreams/NullAndDoCopyBlockInputStream.h

52 lines
1.4 KiB
C++
Raw Normal View History

#pragma once
#include <DataStreams/IBlockInputStream.h>
#include <DataStreams/copyData.h>
namespace DB
{
class IBlockOutputStream;
using BlockOutputStreamPtr = std::shared_ptr<IBlockOutputStream>;
2017-05-13 22:19:04 +00:00
/** An empty stream of blocks.
* But at the first read attempt, copies the data from the passed `input` to the `output`.
* This is necessary to execute the query INSERT SELECT - the query copies data, but returns nothing.
* The query could be executed without wrapping it in an empty BlockInputStream,
* but the progress of query execution and the ability to cancel the query would not work.
*/
class NullAndDoCopyBlockInputStream : public IBlockInputStream
{
public:
NullAndDoCopyBlockInputStream(const BlockInputStreamPtr & input_, BlockOutputStreamPtr output_)
: input(input_), output(output_)
{
children.push_back(input_);
}
2019-02-06 21:44:17 +00:00
/// Suppress readPrefix and readSuffix, because they are called by copyData.
void readPrefix() override {}
2019-02-06 21:44:17 +00:00
void readSuffix() override {}
String getName() const override { return "NullAndDoCopy"; }
2019-08-08 00:48:43 +00:00
Block getHeader() const override { return {}; }
Block getTotals() override { return {}; }
Block getExtremes() override { return {}; }
protected:
Block readImpl() override
{
copyData(*input, *output);
return Block();
}
private:
BlockInputStreamPtr input;
BlockOutputStreamPtr output;
};
}