aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Analyzer/Passes/RewriteAggregateFunctionWithIfPass.h
blob: be8ad3ac34d9c5a2fb784f26ea82b9fca11926b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#pragma once

#include <Analyzer/IQueryTreePass.h>

namespace DB
{

/// Rewrite '<aggregate-function>(if())' to '<aggregate-function>If[OrNull]()'
/// sum(if(cond, a, 0)) -> sumIf[OrNull](a, cond)
/// sum(if(cond, a, null)) -> sumIf[OrNull](a, cond)
/// avg(if(cond, a, null)) -> avgIf[OrNull](a, cond)
/// ...
class RewriteAggregateFunctionWithIfPass final : public IQueryTreePass
{
public:
    String getName() override { return "RewriteAggregateFunctionWithIf"; }

    String getDescription() override
    {
        return "Rewrite aggregate functions with if expression as argument when logically equivalent";
    }

    void run(QueryTreeNodePtr query_tree_node, ContextPtr context) override;

};

}