2014-11-08 23:52:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataStreams/copyData.h>
|
2014-11-08 23:52:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
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.
|
2014-11-08 23:52:18 +00:00
|
|
|
*/
|
2019-01-23 14:48:50 +00:00
|
|
|
class NullAndDoCopyBlockInputStream : public IBlockInputStream
|
2014-11-08 23:52:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-09-08 02:29:47 +00:00
|
|
|
NullAndDoCopyBlockInputStream(const BlockInputStreamPtr & input_, BlockOutputStreamPtr output_)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-12-12 10:49:15 +00:00
|
|
|
input_streams.push_back(input_);
|
|
|
|
output_streams.push_back(output_);
|
|
|
|
|
|
|
|
for (auto & input_stream : input_streams)
|
|
|
|
children.push_back(input_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
NullAndDoCopyBlockInputStream(const BlockInputStreams & input_, BlockOutputStreams & output_)
|
|
|
|
: input_streams(input_), output_streams(output_)
|
|
|
|
{
|
|
|
|
for (auto & input_stream : input_)
|
|
|
|
children.push_back(input_stream);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2014-11-08 23:52:18 +00:00
|
|
|
|
2019-02-06 21:44:17 +00:00
|
|
|
/// Suppress readPrefix and readSuffix, because they are called by copyData.
|
2019-02-06 21:40:49 +00:00
|
|
|
void readPrefix() override {}
|
2019-02-06 21:44:17 +00:00
|
|
|
void readSuffix() override {}
|
2019-02-06 21:40:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getName() const override { return "NullAndDoCopy"; }
|
2014-11-08 23:52:18 +00:00
|
|
|
|
2019-08-08 00:48:43 +00:00
|
|
|
Block getHeader() const override { return {}; }
|
2019-08-08 14:46:30 +00:00
|
|
|
Block getTotals() override { return {}; }
|
|
|
|
Block getExtremes() override { return {}; }
|
2018-01-06 18:10:44 +00:00
|
|
|
|
2014-11-08 23:52:18 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
Block readImpl() override
|
|
|
|
{
|
2019-12-19 14:44:58 +00:00
|
|
|
/// We do not use cancel flag here.
|
|
|
|
/// If query was cancelled, it will be processed by child streams.
|
|
|
|
/// Part of the data will be processed.
|
|
|
|
|
2019-12-12 10:49:15 +00:00
|
|
|
if (input_streams.size() == 1 && output_streams.size() == 1)
|
|
|
|
copyData(*input_streams.at(0), *output_streams.at(0));
|
|
|
|
else
|
|
|
|
copyData(input_streams, output_streams);
|
2017-04-01 07:20:54 +00:00
|
|
|
return Block();
|
|
|
|
}
|
2014-11-08 23:52:18 +00:00
|
|
|
|
|
|
|
private:
|
2019-12-12 10:49:15 +00:00
|
|
|
BlockInputStreams input_streams;
|
|
|
|
BlockOutputStreams output_streams;
|
2014-11-08 23:52:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|