ClickHouse/src/Processors/QueryPipeline.h

129 lines
3.5 KiB
C++
Raw Normal View History

2021-09-15 19:35:48 +00:00
#pragma once
#include <Processors/PipelineResourcesHolder.h>
2021-09-21 10:35:41 +00:00
#include <functional>
2021-09-15 19:35:48 +00:00
namespace DB
{
class InputPort;
class OutputPort;
class IProcessor;
using ProcessorPtr = std::shared_ptr<IProcessor>;
using Processors = std::vector<ProcessorPtr>;
class QueryStatus;
struct Progress;
using ProgressCallback = std::function<void(const Progress & progress)>;
struct StreamLocalLimits;
class EnabledQuota;
class Block;
class Pipe;
class Chain;
class IOutputFormat;
class SinkToStorage;
class ISource;
2021-09-21 06:57:55 +00:00
class ISink;
2021-09-15 19:35:48 +00:00
class QueryPipeline
{
public:
QueryPipeline();
QueryPipeline(QueryPipeline &&);
QueryPipeline(const QueryPipeline &) = delete;
QueryPipeline & operator=(QueryPipeline &&);
QueryPipeline & operator=(const QueryPipeline &) = delete;
~QueryPipeline();
/// pulling
explicit QueryPipeline(Pipe pipe);
explicit QueryPipeline(std::shared_ptr<ISource> source);
/// pushing
explicit QueryPipeline(Chain chain);
explicit QueryPipeline(std::shared_ptr<SinkToStorage> sink);
2021-09-22 19:31:12 +00:00
explicit QueryPipeline(std::shared_ptr<IOutputFormat> format);
2021-09-15 19:35:48 +00:00
/// completed
QueryPipeline(
PipelineResourcesHolder resources_,
Processors processors_);
/// pushing
QueryPipeline(
PipelineResourcesHolder resources_,
Processors processors_,
InputPort * input_);
/// pulling
QueryPipeline(
PipelineResourcesHolder resources_,
Processors processors_,
OutputPort * output_,
OutputPort * totals_ = nullptr,
OutputPort * extremes_ = nullptr);
bool initialized() const { return !processors.empty(); }
2021-09-17 11:40:03 +00:00
/// When initialized, exactly one of the following is true.
2021-09-15 19:35:48 +00:00
/// Use PullingPipelineExecutor or PullingAsyncPipelineExecutor.
bool pulling() const { return output != nullptr; }
/// Use PushingPipelineExecutor or PushingAsyncPipelineExecutor.
bool pushing() const { return input != nullptr; }
/// Use PipelineExecutor. Call execute() to build one.
2021-09-17 11:40:03 +00:00
bool completed() const { return initialized() && !pulling() && !pushing(); }
2021-09-15 19:35:48 +00:00
/// Only for pushing.
void complete(Pipe pipe);
/// Only for pulling.
void complete(std::shared_ptr<IOutputFormat> format);
2021-09-16 17:40:42 +00:00
void complete(Chain chain);
void complete(std::shared_ptr<SinkToStorage> sink);
2021-09-21 06:57:55 +00:00
void complete(std::shared_ptr<ISink> sink);
2021-09-15 19:35:48 +00:00
/// Only for pushing and pulling.
Block getHeader() const;
size_t getNumThreads() const { return num_threads; }
void setNumThreads(size_t num_threads_) { num_threads = num_threads_; }
void setProcessListElement(QueryStatus * elem);
void setProgressCallback(const ProgressCallback & callback);
void setLimitsAndQuota(const StreamLocalLimits & limits, std::shared_ptr<const EnabledQuota> quota);
2021-09-22 19:31:12 +00:00
bool tryGetResultRowsAndBytes(UInt64 & result_rows, UInt64 & result_bytes) const;
2021-09-15 19:35:48 +00:00
2021-09-19 18:53:36 +00:00
void addStorageHolder(StoragePtr storage);
2021-09-15 19:35:48 +00:00
const Processors & getProcessors() const { return processors; }
void reset();
private:
PipelineResourcesHolder resources;
Processors processors;
InputPort * input = nullptr;
OutputPort * output = nullptr;
OutputPort * totals = nullptr;
OutputPort * extremes = nullptr;
QueryStatus * process_list_element = nullptr;
2021-09-20 09:05:34 +00:00
IOutputFormat * output_format = nullptr;
2021-09-15 19:35:48 +00:00
size_t num_threads = 0;
friend class PushingPipelineExecutor;
friend class PullingPipelineExecutor;
friend class PushingAsyncPipelineExecutor;
friend class PullingAsyncPipelineExecutor;
friend class CompletedPipelineExecutor;
2021-09-16 17:40:42 +00:00
friend class QueryPipelineBuilder;
2021-09-15 19:35:48 +00:00
};
}