ClickHouse/src/Processors/Transforms/AggregatingInOrderTransform.h

93 lines
2.4 KiB
C++
Raw Normal View History

2020-04-18 09:51:21 +00:00
#pragma once
2020-05-12 14:50:13 +00:00
#include <Core/SortDescription.h>
2020-04-18 09:51:21 +00:00
#include <Interpreters/Aggregator.h>
2020-05-13 13:49:10 +00:00
#include <Processors/ISimpleTransform.h>
2020-04-18 09:51:21 +00:00
#include <Processors/Transforms/AggregatingTransform.h>
2020-05-13 13:49:10 +00:00
#include <Processors/Transforms/TotalsHavingTransform.h>
2020-04-18 09:51:21 +00:00
namespace DB
{
class AggregatingInOrderTransform : public IProcessor
{
public:
2020-05-12 14:50:13 +00:00
AggregatingInOrderTransform(Block header, AggregatingTransformParamsPtr params,
const SortDescription & group_by_description, size_t res_block_size,
ManyAggregatedDataPtr many_data, size_t current_variant);
AggregatingInOrderTransform(Block header, AggregatingTransformParamsPtr params,
const SortDescription & group_by_description, size_t res_block_size);
2020-04-18 09:51:21 +00:00
~AggregatingInOrderTransform() override;
String getName() const override { return "AggregatingInOrderTransform"; }
Status prepare() override;
void work() override;
void consume(Chunk chunk);
private:
void generate();
2020-05-12 14:50:13 +00:00
size_t res_block_size;
size_t cur_block_size = 0;
2020-05-07 20:13:51 +00:00
2020-04-18 09:51:21 +00:00
MutableColumns res_key_columns;
MutableColumns res_aggregate_columns;
AggregatingTransformParamsPtr params;
SortDescription group_by_description;
Aggregator::AggregateColumns aggregate_columns;
ManyAggregatedDataPtr many_data;
AggregatedDataVariants & variants;
2020-06-02 20:38:10 +00:00
UInt64 src_rows = 0;
UInt64 src_bytes = 0;
UInt64 res_rows = 0;
2020-05-08 19:46:52 +00:00
bool need_generate = false;
bool block_end_reached = false;
2020-06-02 20:38:10 +00:00
bool is_consume_started = false;
2020-04-18 09:51:21 +00:00
bool is_consume_finished = false;
2020-05-12 14:50:13 +00:00
Block res_header;
2020-04-18 09:51:21 +00:00
Chunk current_chunk;
2020-05-08 19:46:52 +00:00
Chunk to_push_chunk;
2020-06-03 21:58:51 +00:00
Poco::Logger * log = &Poco::Logger::get("AggregatingInOrderTransform");
2020-04-18 09:51:21 +00:00
};
2020-05-12 14:50:13 +00:00
2020-05-13 13:49:10 +00:00
class FinalizingSimpleTransform : public ISimpleTransform
2020-05-12 14:50:13 +00:00
{
public:
FinalizingSimpleTransform(Block header, AggregatingTransformParamsPtr params_)
: ISimpleTransform({std::move(header)}, {params_->getHeader()}, true)
, params(params_) {}
2020-05-12 14:50:13 +00:00
2020-05-13 13:49:10 +00:00
void transform(Chunk & chunk) override
{
2020-05-26 19:20:02 +00:00
if (params->final)
finalizeChunk(chunk);
else if (!chunk.getChunkInfo())
{
auto info = std::make_shared<AggregatedChunkInfo>();
chunk.setChunkInfo(std::move(info));
}
2020-05-13 13:49:10 +00:00
}
2020-05-12 14:50:13 +00:00
2020-05-13 13:49:10 +00:00
String getName() const override { return "FinalizingSimpleTransform"; }
private:
AggregatingTransformParamsPtr params;
2020-05-13 13:49:10 +00:00
};
2020-05-12 14:50:13 +00:00
2020-04-18 09:51:21 +00:00
}