ClickHouse/dbms/include/DB/DataStreams/MergingAggregatedBlockInputStream.h

55 lines
1.7 KiB
C
Raw Normal View History

2012-05-08 11:19:00 +00:00
#pragma once
#include <DB/Interpreters/Aggregator.h>
#include <DB/Interpreters/Expression.h>
#include <DB/DataStreams/IProfilingBlockInputStream.h>
namespace DB
{
using Poco::SharedPtr;
2012-05-30 01:38:02 +00:00
/** Доагрегирует поток блоков, в котором каждый блок уже агрегирован.
* Агрегатные функции в блоках не должны быть финализированы, чтобы их состояния можно было объединить.
* Сам тоже не финализирует агрегатные функции.
2012-05-08 11:19:00 +00:00
*/
2012-05-30 01:38:02 +00:00
class MergingAggregatedBlockInputStream : public IProfilingBlockInputStream
2012-05-08 11:19:00 +00:00
{
public:
2012-05-30 01:38:02 +00:00
MergingAggregatedBlockInputStream(BlockInputStreamPtr input_, const ColumnNumbers & keys_, AggregateDescriptions & aggregates_)
2013-05-04 04:05:15 +00:00
: aggregator(new Aggregator(keys_, aggregates_)), has_been_read(false)
2012-05-08 11:19:00 +00:00
{
2013-05-04 04:05:15 +00:00
children.push_back(input_);
input = &*children.back();
2012-05-08 11:19:00 +00:00
}
/** keys берутся из GROUP BY части запроса
* Агрегатные функции ищутся везде в выражении.
*/
2012-05-30 01:38:02 +00:00
MergingAggregatedBlockInputStream(BlockInputStreamPtr input_, ExpressionPtr expression);
2012-05-08 11:19:00 +00:00
2012-05-30 01:38:02 +00:00
String getName() const { return "MergingAggregatedBlockInputStream"; }
2012-05-08 11:19:00 +00:00
String getID() const
{
std::stringstream res;
res << "MergingAggregated(" << input->getID() << ", " << aggregator->getID() << ")";
return res.str();
}
2012-10-20 02:10:47 +00:00
protected:
Block readImpl();
2012-05-08 11:19:00 +00:00
private:
2012-05-30 01:38:02 +00:00
MergingAggregatedBlockInputStream(const MergingAggregatedBlockInputStream & src)
2012-05-08 11:19:00 +00:00
: input(src.input), aggregator(src.aggregator), has_been_read(src.has_been_read) {}
2013-05-04 04:05:15 +00:00
IBlockInputStream * input;
2012-05-08 11:19:00 +00:00
SharedPtr<Aggregator> aggregator;
bool has_been_read;
};
}