ClickHouse/dbms/DataStreams/TotalsHavingBlockInputStream.h

63 lines
1.8 KiB
C++
Raw Normal View History

2014-02-27 12:49:21 +00:00
#pragma once
#include <DataStreams/IBlockInputStream.h>
2014-02-27 12:49:21 +00:00
namespace DB
{
class Arena;
using ArenaPtr = std::shared_ptr<Arena>;
2016-01-13 00:32:59 +00:00
class ExpressionActions;
enum class TotalsMode;
2014-02-27 12:49:21 +00:00
2017-05-13 22:19:04 +00:00
/** Takes blocks after grouping, with non-finalized aggregate functions.
* Calculates total values according to totals_mode.
* If necessary, evaluates the expression from HAVING and filters rows. Returns the finalized and filtered blocks.
2014-02-27 12:49:21 +00:00
*/
class TotalsHavingBlockInputStream : public IBlockInputStream
2014-02-27 12:49:21 +00:00
{
2016-01-13 00:32:59 +00:00
private:
using ExpressionActionsPtr = std::shared_ptr<ExpressionActions>;
2016-01-13 00:32:59 +00:00
2014-02-27 12:49:21 +00:00
public:
/// expression may be nullptr
TotalsHavingBlockInputStream(
const BlockInputStreamPtr & input_,
bool overflow_row_, const ExpressionActionsPtr & expression_,
2018-08-24 15:00:00 +00:00
const std::string & filter_column_, TotalsMode totals_mode_, double auto_include_threshold_, bool final_);
2014-02-27 12:49:21 +00:00
String getName() const override { return "TotalsHaving"; }
2014-02-27 12:49:21 +00:00
Block getTotals() override;
Block getHeader() const override;
2014-02-27 12:49:21 +00:00
protected:
Block readImpl() override;
2014-02-27 12:49:21 +00:00
private:
bool overflow_row;
ExpressionActionsPtr expression;
String filter_column_name;
TotalsMode totals_mode;
double auto_include_threshold;
2018-08-24 15:00:00 +00:00
bool final;
size_t passed_keys = 0;
size_t total_keys = 0;
2017-05-13 22:19:04 +00:00
/** Here are the values that did not pass max_rows_to_group_by.
* They are added or not added to the current_totals, depending on the totals_mode.
*/
Block overflow_aggregates;
/// Here, total values are accumulated. After the work is finished, they will be placed in IBlockInputStream::totals.
MutableColumns current_totals;
2017-05-13 22:19:04 +00:00
/// If filter == nullptr - add all rows. Otherwise, only the rows that pass the filter (HAVING).
2018-01-13 01:33:55 +00:00
void addToTotals(const Block & block, const IColumn::Filter * filter);
2014-02-27 12:49:21 +00:00
};
}