aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Processors/Executors/PushingAsyncPipelineExecutor.h
blob: 4b4b83a90b5a75e94684fe65598cd125fcf63354 (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
59
60
#pragma once
#include <memory>
#include <atomic>
#include <vector>

namespace DB
{

class Block;
class Chunk;
class QueryPipeline;
class PushingAsyncSource;

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 using several background threads.
/// Typical usage is:
///
/// PushingAsyncPipelineExecutor executor(chain);
/// executor.start();
/// while (auto chunk = ...)
///     executor.push(std::move(chunk));
/// executor.finish();
class PushingAsyncPipelineExecutor
{
public:
    explicit PushingAsyncPipelineExecutor(QueryPipeline & pipeline_);
    ~PushingAsyncPipelineExecutor();

    /// 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();

    struct Data;

private:
    QueryPipeline & pipeline;
    std::shared_ptr<PushingAsyncSource> pushing_source;

    bool started = false;
    bool finished = false;

    std::unique_ptr<Data> data;
};

}