2014-02-27 12:49:21 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataStreams/IProfilingBlockInputStream.h>
|
2018-06-05 19:46:49 +00:00
|
|
|
#include <Common/Arena.h>
|
2014-02-27 12:49:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-01-13 00:32:59 +00:00
|
|
|
class ExpressionActions;
|
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 IProfilingBlockInputStream
|
|
|
|
{
|
2016-01-13 00:32:59 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
using ExpressionActionsPtr = std::shared_ptr<ExpressionActions>;
|
2016-01-13 00:32:59 +00:00
|
|
|
|
2014-02-27 12:49:21 +00:00
|
|
|
public:
|
2018-01-09 00:19:58 +00:00
|
|
|
/// expression may be nullptr
|
2017-04-01 07:20:54 +00:00
|
|
|
TotalsHavingBlockInputStream(
|
2017-09-08 03:47:27 +00:00
|
|
|
const BlockInputStreamPtr & input_,
|
|
|
|
bool overflow_row_, const ExpressionActionsPtr & expression_,
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string & filter_column_, TotalsMode totals_mode_, double auto_include_threshold_);
|
2014-02-27 12:49:21 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getName() const override { return "TotalsHaving"; }
|
2014-02-27 12:49:21 +00:00
|
|
|
|
2018-02-23 10:43:24 +00:00
|
|
|
Block getTotals() override;
|
2014-03-06 19:27:11 +00:00
|
|
|
|
2018-02-18 03:23:48 +00:00
|
|
|
Block getHeader() const override;
|
2018-01-06 18:10:44 +00:00
|
|
|
|
2014-02-27 12:49:21 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
Block readImpl() override;
|
2014-02-27 12:49:21 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
bool overflow_row;
|
|
|
|
ExpressionActionsPtr expression;
|
|
|
|
String filter_column_name;
|
|
|
|
TotalsMode totals_mode;
|
|
|
|
double auto_include_threshold;
|
|
|
|
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.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
Block overflow_aggregates;
|
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/// Here, total values are accumulated. After the work is finished, they will be placed in IProfilingBlockInputStream::totals.
|
2017-12-15 02:04:28 +00:00
|
|
|
MutableColumns current_totals;
|
2018-01-13 01:33:55 +00:00
|
|
|
/// Arena for aggregate function states in totals.
|
|
|
|
ArenaPtr arena;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|