2021-08-18 21:54:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Interpreters/Aliases.h>
|
|
|
|
#include <Interpreters/InDepthNodeVisitor.h>
|
|
|
|
|
|
|
|
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;
|
|
|
|
*/
|
2021-09-07 23:55:17 +00:00
|
|
|
class UserDefinedSQLFunctionMatcher
|
2021-08-18 21:54:55 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-09-07 23:55:17 +00:00
|
|
|
using Visitor = InDepthNodeVisitor<UserDefinedSQLFunctionMatcher, true>;
|
2021-08-18 21:54:55 +00:00
|
|
|
|
|
|
|
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).
|
2021-09-07 23:55:17 +00:00
|
|
|
using UserDefinedSQLFunctionVisitor = UserDefinedSQLFunctionMatcher::Visitor;
|
2021-08-18 21:54:55 +00:00
|
|
|
|
|
|
|
}
|