2014-11-08 23:52:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataStreams/IProfilingBlockInputStream.h>
|
|
|
|
#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
|
|
|
*/
|
|
|
|
class NullAndDoCopyBlockInputStream : public IProfilingBlockInputStream
|
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
NullAndDoCopyBlockInputStream(BlockInputStreamPtr input_, BlockOutputStreamPtr output_)
|
|
|
|
: input(input_), output(output_)
|
|
|
|
{
|
|
|
|
children.push_back(input_);
|
|
|
|
}
|
2014-11-08 23:52:18 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getName() const override { return "NullAndDoCopy"; }
|
2014-11-08 23:52:18 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getID() const override
|
|
|
|
{
|
|
|
|
std::stringstream res;
|
|
|
|
res << "copy from " << input->getID();
|
|
|
|
return res.str();
|
|
|
|
}
|
2014-11-08 23:52:18 +00:00
|
|
|
|
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
Block readImpl() override
|
|
|
|
{
|
|
|
|
copyData(*input, *output);
|
|
|
|
return Block();
|
|
|
|
}
|
2014-11-08 23:52:18 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreamPtr input;
|
|
|
|
BlockOutputStreamPtr output;
|
2014-11-08 23:52:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|