2020-06-03 10:28:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Parsers/IAST.h>
|
|
|
|
#include <Interpreters/InDepthNodeVisitor.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-07-22 17:13:05 +00:00
|
|
|
class ASTFunction;
|
|
|
|
|
2020-06-24 18:49:55 +00:00
|
|
|
/// Extract constant arguments out of aggregate functions from child functions
|
|
|
|
/// 'sum(a * 2)' -> 'sum(a) * 2'
|
|
|
|
/// Rewrites: sum([multiply|divide]) -> [multiply|divide](sum)
|
2021-02-07 14:41:41 +00:00
|
|
|
/// [min|max|avg]([multiply|divide|plus|minus]) -> [multiply|divide|plus|minus]([min|max|avg])
|
2020-06-24 18:49:55 +00:00
|
|
|
/// TODO: groupBitAnd, groupBitOr, groupBitXor
|
|
|
|
/// TODO: better constant detection: f(const) is not detected as const.
|
|
|
|
/// TODO: 'f((2 * n) * n)' -> '2 * f(n * n)'
|
2020-06-03 10:28:30 +00:00
|
|
|
class ArithmeticOperationsInAgrFuncMatcher
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Data {};
|
|
|
|
|
2020-06-24 18:49:55 +00:00
|
|
|
static void visit(ASTPtr & ast, Data & data);
|
|
|
|
static void visit(const ASTFunction &, ASTPtr & ast, Data & data);
|
2020-06-03 10:28:30 +00:00
|
|
|
|
2020-06-24 18:49:55 +00:00
|
|
|
static bool needChildVisit(const ASTPtr & node, const ASTPtr & child);
|
2020-06-03 10:28:30 +00:00
|
|
|
};
|
2020-06-24 18:49:55 +00:00
|
|
|
|
|
|
|
using ArithmeticOperationsInAgrFuncVisitor = InDepthNodeVisitor<ArithmeticOperationsInAgrFuncMatcher, false>;
|
|
|
|
|
2020-06-03 10:28:30 +00:00
|
|
|
}
|