mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-04 05:22:17 +00:00
44 lines
1.0 KiB
C++
44 lines
1.0 KiB
C++
|
#pragma once
|
||
|
|
||
|
|
||
|
#include <DataTypes/Serializations/ISerialization.h>
|
||
|
#include <Interpreters/InDepthNodeVisitor.h>
|
||
|
#include <Parsers/ASTFunction.h>
|
||
|
#include <Parsers/ASTIdentifier.h>
|
||
|
|
||
|
namespace DB
|
||
|
{
|
||
|
|
||
|
/// Checks from bottom to top if a function's alias shadows the name
|
||
|
/// of one of it's arguments
|
||
|
class FunctionMaskingArgumentCheckMatcher
|
||
|
{
|
||
|
public:
|
||
|
struct Data
|
||
|
{
|
||
|
const String& alias;
|
||
|
bool is_rejected = false;
|
||
|
void reject() { is_rejected = true; }
|
||
|
};
|
||
|
|
||
|
static void visit(const ASTPtr & ast, Data & data)
|
||
|
{
|
||
|
if (data.is_rejected)
|
||
|
return;
|
||
|
if (const auto & identifier = ast->as<ASTIdentifier>())
|
||
|
visit(*identifier, data);
|
||
|
}
|
||
|
|
||
|
static void visit(const ASTIdentifier & ast, Data & data)
|
||
|
{
|
||
|
if (ast.getAliasOrColumnName() == data.alias)
|
||
|
data.reject();
|
||
|
}
|
||
|
|
||
|
static bool needChildVisit(const ASTPtr &, const ASTPtr &) { return true; }
|
||
|
};
|
||
|
|
||
|
using FunctionMaskingArgumentCheckVisitor = ConstInDepthNodeVisitor<FunctionMaskingArgumentCheckMatcher, false>;
|
||
|
|
||
|
}
|