aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Processors/Executors/PushingPipelineExecutor.h
blob: f549c9482dbe868b2174c1474e5d72ff1ba84ad7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <memory>
#include <atomic>
#include <vector>

namespace DB
{

class Block;
class Chunk;
class QueryPipeline;
class PushingSource;

class PipelineExecutor;
using PipelineExecutorPtr = std::shared_ptr<PipelineExecutor>;

class IProcessor;
using ProcessorPtr = std::shared_ptr<IProcessor>;
using Processors = std::vector<ProcessorPtr>;

/// Pushing executor for Chain of processors. Always executed in single thread.
/// Typical usage is:
///
/// PushingPipelineExecutor executor(chain);
/// executor.start();
/// while (auto chunk = ...)
///     executor.push(std::move(chunk));
/// executor.finish();
class PushingPipelineExecutor
{
public:
    explicit PushingPipelineExecutor(QueryPipeline & pipeline_);
    ~PushingPipelineExecutor();

    /// Get structure of returned block or chunk.
    const Block & getHeader() const;

    void start();

    void push(Chunk chunk);
    void push(Block block);

    void finish();

    /// Stop execution. It is not necessary, but helps to stop execution before executor is destroyed.
    void cancel();

private:
    QueryPipeline & pipeline;
    std::atomic_bool input_wait_flag = false;
    std::shared_ptr<PushingSource> pushing_source;

    PipelineExecutorPtr executor;
    bool started = false;
    bool finished = false;
};

}