2021-02-14 11:09:36 +00:00
|
|
|
#include <Interpreters/FunctionNameNormalizer.h>
|
|
|
|
|
2021-02-14 12:53:50 +00:00
|
|
|
#include <Parsers/ASTColumnDeclaration.h>
|
|
|
|
#include <Parsers/ASTCreateQuery.h>
|
2021-11-26 17:21:54 +00:00
|
|
|
#include <Parsers/ASTFunction.h>
|
2021-02-14 12:53:50 +00:00
|
|
|
|
2021-02-14 11:09:36 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
const String & getFunctionCanonicalNameIfAny(const String & name);
|
|
|
|
const String & getAggregateFunctionCanonicalNameIfAny(const String & name);
|
|
|
|
|
2021-02-14 12:53:50 +00:00
|
|
|
void FunctionNameNormalizer::visit(IAST * ast)
|
2021-02-14 11:09:36 +00:00
|
|
|
{
|
2021-02-14 12:53:50 +00:00
|
|
|
if (!ast)
|
|
|
|
return;
|
|
|
|
|
2021-02-20 08:45:25 +00:00
|
|
|
// Normalize only selected children. Avoid normalizing engine clause because some engine might
|
|
|
|
// have the same name as function, e.g. Log.
|
2021-02-14 12:53:50 +00:00
|
|
|
if (auto * node_storage = ast->as<ASTStorage>())
|
|
|
|
{
|
|
|
|
visit(node_storage->partition_by);
|
|
|
|
visit(node_storage->primary_key);
|
|
|
|
visit(node_storage->order_by);
|
|
|
|
visit(node_storage->sample_by);
|
|
|
|
visit(node_storage->ttl_table);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-20 08:45:25 +00:00
|
|
|
// Normalize only selected children. Avoid normalizing type clause because some type might
|
|
|
|
// have the same name as function, e.g. Date.
|
2021-02-14 12:53:50 +00:00
|
|
|
if (auto * node_decl = ast->as<ASTColumnDeclaration>())
|
|
|
|
{
|
|
|
|
visit(node_decl->default_expression.get());
|
|
|
|
visit(node_decl->ttl.get());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-14 11:09:36 +00:00
|
|
|
if (auto * node_func = ast->as<ASTFunction>())
|
|
|
|
node_func->name = getAggregateFunctionCanonicalNameIfAny(getFunctionCanonicalNameIfAny(node_func->name));
|
|
|
|
|
|
|
|
for (auto & child : ast->children)
|
2021-02-14 12:53:50 +00:00
|
|
|
visit(child.get());
|
2021-02-14 11:09:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|