ClickHouse/dbms/src/Processors/Executors/TreeExecutorBlockInputStream.h

55 lines
1.7 KiB
C++
Raw Normal View History

2019-09-13 12:34:05 +00:00
#pragma once
#include <DataStreams/IBlockInputStream.h>
#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())
{
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:
OutputPort & output_port;
2019-09-13 12:34:05 +00:00
Processors processors;
IProcessor * root = nullptr;
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();
};
}