ClickHouse/dbms/src/DataStreams/AggregatingBlockInputStream.cpp
2012-12-25 19:28:59 +00:00

38 lines
837 B
C++

#include <DB/Columns/ColumnsNumber.h>
#include <DB/DataStreams/AggregatingBlockInputStream.h>
namespace DB
{
AggregatingBlockInputStream::AggregatingBlockInputStream(BlockInputStreamPtr input_, ExpressionPtr expression,
size_t max_rows_to_group_by_, Limits::OverflowMode group_by_overflow_mode_)
: input(input_), has_been_read(false)
{
children.push_back(input);
Names key_names;
AggregateDescriptions aggregates;
expression->getAggregateInfo(key_names, aggregates);
aggregator = new Aggregator(key_names, aggregates, max_rows_to_group_by_, group_by_overflow_mode_);
}
Block AggregatingBlockInputStream::readImpl()
{
if (has_been_read)
return Block();
has_been_read = true;
AggregatedDataVariants data_variants;
aggregator->execute(input, data_variants);
return aggregator->convertToBlock(data_variants);
}
}