ClickHouse/dbms/include/DB/Interpreters/Aggregator.h

44 lines
934 B
C
Raw Normal View History

2011-09-19 01:42:16 +00:00
#pragma once
#include <DB/Core/ColumnNumbers.h>
#include <DB/DataStreams/IBlockInputStream.h>
#include <DB/AggregateFunctions/IAggregateFunction.h>
namespace DB
{
struct AggregateDescription
{
AggregateFunctionPtr function;
ColumnNumbers arguments;
};
typedef std::vector<AggregateDescription> AggregateDescriptions;
typedef std::map<Row, AggregateFunctions> AggregatedData;
/** Агрегирует поток блоков.
*/
2011-09-19 03:34:23 +00:00
class Aggregator
2011-09-19 01:42:16 +00:00
{
public:
2011-09-19 03:34:23 +00:00
Aggregator(const ColumnNumbers & keys_, AggregateDescriptions & aggregates_) : keys(keys_), aggregates(aggregates_) {};
2011-09-19 01:42:16 +00:00
AggregatedData execute(BlockInputStreamPtr stream);
2011-09-19 03:34:23 +00:00
/// Получить пример блока, описывающего результат. Следует вызывать только после execute.
Block getSampleBlock() { return sample; }
2011-09-19 01:42:16 +00:00
private:
ColumnNumbers keys;
AggregateDescriptions aggregates;
2011-09-19 03:34:23 +00:00
Block sample;
2011-09-19 01:42:16 +00:00
};
}