aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Processors/IAccumulatingTransform.h
blob: 67063da4e11cbfbd577858eef8607cbd95baf466 (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
#pragma once

#include <Processors/IProcessor.h>


namespace DB
{

/** Has one input and one output.
  * Pulls all blocks from input, and only then produce output.
  * Examples: ORDER BY, GROUP BY.
  */
class IAccumulatingTransform : public IProcessor
{
protected:
    InputPort & input;
    OutputPort & output;

    Chunk current_input_chunk;
    Chunk current_output_chunk;
    Chunk totals;
    bool has_input = false;
    bool finished_input = false;
    bool finished_generate = false;

    virtual void consume(Chunk chunk) = 0;
    virtual Chunk generate() = 0;

    /// This method can be called once per consume call. In case if some chunks are ready.
    void setReadyChunk(Chunk chunk);
    void finishConsume() { finished_input = true; }

public:
    IAccumulatingTransform(Block input_header, Block output_header);

    Status prepare() override;
    void work() override;

    InputPort & getInputPort() { return input; }
    OutputPort & getOutputPort() { return output; }
};

}