2012-05-08 11:19:00 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <DB/Interpreters/Aggregator.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:
|
2014-02-26 11:44:54 +00:00
|
|
|
|
MergingAggregatedBlockInputStream(BlockInputStreamPtr input_, const ColumnNumbers & keys_,
|
2015-01-03 03:18:49 +00:00
|
|
|
|
const AggregateDescriptions & aggregates_, bool overflow_row_, bool final_, size_t max_threads_)
|
2015-01-10 02:30:03 +00:00
|
|
|
|
: aggregator(keys_, aggregates_, overflow_row_, 0, OverflowMode::THROW, nullptr, 0),
|
|
|
|
|
final(final_), max_threads(max_threads_)
|
2012-05-08 11:19:00 +00:00
|
|
|
|
{
|
2013-05-04 04:05:15 +00:00
|
|
|
|
children.push_back(input_);
|
2012-05-08 11:19:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-26 11:44:54 +00:00
|
|
|
|
MergingAggregatedBlockInputStream(BlockInputStreamPtr input_, const Names & keys_names_,
|
2015-01-03 03:18:49 +00:00
|
|
|
|
const AggregateDescriptions & aggregates_, bool overflow_row_, bool final_, size_t max_threads_)
|
2015-01-10 02:30:03 +00:00
|
|
|
|
: aggregator(keys_names_, aggregates_, overflow_row_, 0, OverflowMode::THROW, nullptr, 0),
|
|
|
|
|
final(final_), max_threads(max_threads_)
|
2013-05-27 14:02:55 +00:00
|
|
|
|
{
|
|
|
|
|
children.push_back(input_);
|
|
|
|
|
}
|
2012-05-08 11:19:00 +00:00
|
|
|
|
|
2014-11-08 23:52:18 +00:00
|
|
|
|
String getName() const override { return "MergingAggregatedBlockInputStream"; }
|
2012-05-08 11:19:00 +00:00
|
|
|
|
|
2014-11-08 23:52:18 +00:00
|
|
|
|
String getID() const override
|
2013-05-03 10:20:53 +00:00
|
|
|
|
{
|
|
|
|
|
std::stringstream res;
|
2015-01-10 02:30:03 +00:00
|
|
|
|
res << "MergingAggregated(" << children.back()->getID() << ", " << aggregator.getID() << ")";
|
2013-05-03 10:20:53 +00:00
|
|
|
|
return res.str();
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 02:10:47 +00:00
|
|
|
|
protected:
|
2014-11-08 23:52:18 +00:00
|
|
|
|
Block readImpl() override;
|
2012-10-20 02:10:47 +00:00
|
|
|
|
|
2012-05-08 11:19:00 +00:00
|
|
|
|
private:
|
2015-01-10 02:30:03 +00:00
|
|
|
|
Aggregator aggregator;
|
2014-02-26 11:44:54 +00:00
|
|
|
|
bool final;
|
2015-01-03 03:18:49 +00:00
|
|
|
|
size_t max_threads;
|
2015-01-02 03:16:28 +00:00
|
|
|
|
|
|
|
|
|
bool executed = false;
|
|
|
|
|
BlocksList blocks;
|
|
|
|
|
BlocksList::iterator it;
|
2012-05-08 11:19:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|