2019-09-13 12:34:05 +00:00
|
|
|
#pragma once
|
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2019-10-20 09:12:42 +00:00
|
|
|
#include <Processors/Pipe.h>
|
2019-09-13 12:34:05 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-10-04 15:40:05 +00:00
|
|
|
class ISourceWithProgress;
|
|
|
|
|
2019-10-10 14:16:15 +00:00
|
|
|
/// It's a wrapper from processors tree-shaped pipeline to block input stream.
|
|
|
|
/// Execute all processors in a single thread, by in-order tree traverse.
|
2019-10-21 16:26:29 +00:00
|
|
|
/// Also, support for progress and quotas.
|
|
|
|
class TreeExecutorBlockInputStream : public IBlockInputStream
|
2019-09-13 12:34:05 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-10-10 14:16:15 +00:00
|
|
|
/// Last processor in list must be a tree root.
|
|
|
|
/// It is checked that
|
|
|
|
/// * processors form a tree
|
|
|
|
/// * all processors are attainable from root
|
|
|
|
/// * there is no other connected processors
|
2019-10-21 16:26:29 +00:00
|
|
|
explicit TreeExecutorBlockInputStream(Pipe pipe) : output_port(pipe.getPort()), processors(std::move(pipe).detachProcessors())
|
2019-10-20 09:12:42 +00:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
2019-09-13 12:34:05 +00:00
|
|
|
|
|
|
|
String getName() const override { return root->getName(); }
|
|
|
|
Block getHeader() const override { return root->getOutputs().front().getHeader(); }
|
|
|
|
|
2019-10-04 15:40:05 +00:00
|
|
|
/// This methods does not affect TreeExecutor as IBlockInputStream itself.
|
|
|
|
/// They just passed to all SourceWithProgress processors.
|
|
|
|
void setProgressCallback(const ProgressCallback & callback) final;
|
|
|
|
void setProcessListElement(QueryStatus * elem) final;
|
|
|
|
void setLimits(const LocalLimits & limits_) final;
|
|
|
|
void setQuota(QuotaForIntervals & quota_) final;
|
|
|
|
void addTotalRowsApprox(size_t value) final;
|
|
|
|
|
2019-09-13 12:34:05 +00:00
|
|
|
protected:
|
|
|
|
Block readImpl() override;
|
|
|
|
|
|
|
|
private:
|
2019-10-20 09:12:42 +00:00
|
|
|
OutputPort & output_port;
|
2019-09-13 12:34:05 +00:00
|
|
|
Processors processors;
|
|
|
|
IProcessor * root = nullptr;
|
2019-10-20 09:12:42 +00:00
|
|
|
std::unique_ptr<InputPort> input_port;
|
2019-09-13 12:34:05 +00:00
|
|
|
|
2019-10-04 15:40:05 +00:00
|
|
|
/// Remember sources that support progress.
|
|
|
|
std::vector<ISourceWithProgress *> sources_with_progress;
|
|
|
|
|
2019-09-13 12:34:05 +00:00
|
|
|
void init();
|
2019-10-10 14:16:15 +00:00
|
|
|
/// Execute tree step-by-step until root returns next chunk or execution is finished.
|
2019-09-13 12:34:05 +00:00
|
|
|
void execute();
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|