2018-05-23 20:19:33 +00:00
|
|
|
#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;
|
|
|
|
|
2019-02-18 16:36:07 +00:00
|
|
|
Chunk current_input_chunk;
|
|
|
|
Chunk current_output_chunk;
|
2020-09-04 08:36:47 +00:00
|
|
|
Chunk totals;
|
2019-02-07 18:51:53 +00:00
|
|
|
bool has_input = false;
|
|
|
|
bool finished_input = false;
|
|
|
|
bool finished_generate = false;
|
2018-05-23 20:19:33 +00:00
|
|
|
|
2019-02-18 16:36:07 +00:00
|
|
|
virtual void consume(Chunk chunk) = 0;
|
|
|
|
virtual Chunk generate() = 0;
|
2018-05-23 20:19:33 +00:00
|
|
|
|
2019-02-26 18:40:08 +00:00
|
|
|
/// This method can be called once per consume call. In case if some chunks are ready.
|
|
|
|
void setReadyChunk(Chunk chunk);
|
2019-03-04 14:56:09 +00:00
|
|
|
void finishConsume() { finished_input = true; }
|
2019-02-26 18:40:08 +00:00
|
|
|
|
2018-05-23 20:19:33 +00:00
|
|
|
public:
|
|
|
|
IAccumulatingTransform(Block input_header, Block output_header);
|
|
|
|
|
|
|
|
Status prepare() override;
|
|
|
|
void work() override;
|
2020-09-07 09:47:59 +00:00
|
|
|
|
2020-10-27 11:04:03 +00:00
|
|
|
/// Adds additional port for totals.
|
2020-09-07 09:47:59 +00:00
|
|
|
/// If added, totals will have been ready by the first generate() call (in totals chunk).
|
2020-09-04 08:36:47 +00:00
|
|
|
InputPort * addTotalsPort();
|
2018-05-23 20:19:33 +00:00
|
|
|
|
|
|
|
InputPort & getInputPort() { return input; }
|
|
|
|
OutputPort & getOutputPort() { return output; }
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|