#pragma once #include #include namespace DB { class ASTFunction; /** Visits ASTFunction nodes and if it is used defined function replace it with function body. * Example: * * CREATE FUNCTION test_function AS a -> a + 1; * * Before applying visitor: * SELECT test_function(number) FROM system.numbers LIMIT 10; * * After applying visitor: * SELECT number + 1 FROM system.numbers LIMIT 10; */ class UserDefinedFunctionsMatcher { public: using Visitor = InDepthNodeVisitor; struct Data { }; static void visit(ASTPtr & ast, Data & data); static bool needChildVisit(const ASTPtr & node, const ASTPtr & child); private: static void visit(ASTFunction & func, const Data & data); static ASTPtr tryToReplaceFunction(const ASTFunction & function); }; /// Visits AST nodes and collect their aliases in one map (with links to source nodes). using UserDefinedFunctionsVisitor = UserDefinedFunctionsMatcher::Visitor; }