ClickHouse/dbms/src/DataStreams/AggregatingBlockInputStream.h

67 lines
2.1 KiB
C++
Raw Normal View History

2011-09-19 03:34:23 +00:00
#pragma once
#include <Interpreters/Aggregator.h>
#include <IO/ReadBufferFromFile.h>
#include <IO/CompressedReadBuffer.h>
#include <DataStreams/IProfilingBlockInputStream.h>
2011-09-19 03:34:23 +00:00
namespace DB
{
2017-05-13 22:19:04 +00:00
/** Aggregates the stream of blocks using the specified key columns and aggregate functions.
* Columns with aggregate functions adds to the end of the block.
* If final = false, the aggregate functions are not finalized, that is, they are not replaced by their value, but contain an intermediate state of calculations.
* This is necessary so that aggregation can continue (for example, by combining streams of partially aggregated data).
2011-09-19 03:34:23 +00:00
*/
class AggregatingBlockInputStream : public IProfilingBlockInputStream
{
public:
2017-05-13 22:19:04 +00:00
/** keys are taken from the GROUP BY part of the query
* Aggregate functions are searched everywhere in the expression.
* Columns corresponding to keys and arguments of aggregate functions must already be computed.
*/
AggregatingBlockInputStream(BlockInputStreamPtr input_, const Aggregator::Params & params_, bool final_)
: params(params_), aggregator(params), final(final_)
{
children.push_back(input_);
}
2011-09-24 20:32:41 +00:00
String getName() const override { return "Aggregating"; }
2011-09-19 03:34:23 +00:00
String getID() const override
{
std::stringstream res;
res << "Aggregating(" << children.back()->getID() << ", " << aggregator.getID() << ")";
return res.str();
}
2012-10-20 02:10:47 +00:00
protected:
Block readImpl() override;
2012-10-20 02:10:47 +00:00
Aggregator::Params params;
Aggregator aggregator;
bool final;
bool executed = false;
2017-05-13 22:19:04 +00:00
/// To read the data that was flushed into the temporary data file.
struct TemporaryFileStream
{
ReadBufferFromFile file_in;
CompressedReadBuffer compressed_in;
BlockInputStreamPtr block_in;
TemporaryFileStream(const std::string & path);
};
std::vector<std::unique_ptr<TemporaryFileStream>> temporary_inputs;
2017-05-13 22:19:04 +00:00
/** From here we will get the completed blocks after the aggregation. */
std::unique_ptr<IBlockInputStream> impl;
Logger * log = &Logger::get("AggregatingBlockInputStream");
2011-09-19 03:34:23 +00:00
};
}