ISimpleTransform.h 1.6 KB
Newer Older
1 2 3 4 5 6 7 8
#pragma once

#include <Processors/IProcessor.h>


namespace DB
{

N
Nikolai Kochetov 已提交
9 10 11 12 13
namespace ErrorCodes
{
    extern const int NOT_IMPLEMENTED;
}

14 15 16 17 18 19 20 21 22
/** Has one input and one output.
  * Simply pull a block from input, transform it, and push it to output.
  */
class ISimpleTransform : public IProcessor
{
protected:
    InputPort & input;
    OutputPort & output;

N
Nikolai Kochetov 已提交
23 24
    Port::Data input_data;
    Port::Data output_data;
N
Nikolai Kochetov 已提交
25
    bool has_input = false;
N
Nikolai Kochetov 已提交
26
    bool has_output = false;
N
Nikolai Kochetov 已提交
27
    bool no_more_data_needed = false;
28
    const bool skip_empty_chunks;
29

30 31 32
    /// Set input port NotNeeded after chunk was pulled.
    /// Input port will become needed again only after data was transformed.
    /// This allows to escape caching chunks in input port, which can lead to uneven data distribution.
N
Nikolai Kochetov 已提交
33 34 35 36 37 38 39 40 41 42 43 44
    bool set_input_not_needed_after_read = true;

    virtual void transform(Chunk &)
    {
        throw Exception("Method transform is not implemented for " + getName(), ErrorCodes::NOT_IMPLEMENTED);
    }

    virtual void transform(Chunk & input_chunk, Chunk & output_chunk)
    {
        transform(input_chunk);
        output_chunk.swap(input_chunk);
    }
45

C
chertus 已提交
46
    virtual bool needInputData() const { return true; }
N
Nikolai Kochetov 已提交
47
    void stopReading() { no_more_data_needed = true; }
48 49

public:
K
kreuzerkrieg 已提交
50
    ISimpleTransform(Block input_header_, Block output_header_, bool skip_empty_chunks_);
51 52 53 54 55 56

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

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

    void setInputNotNeededAfterRead(bool value) { set_input_not_needed_after_read = value; }
59 60 61
};

}