ClickHouse/src/Interpreters/ReplaceQueryParameterVisitor.h
Alexander Tokmakov 08e4e2bb0b fix
2023-08-16 22:35:45 +02:00

36 lines
840 B
C++

#pragma once
#include <Core/Names.h>
#include <Core/Types.h>
#include <Parsers/IAST_fwd.h>
namespace DB
{
class ASTQueryParameter;
/// Visit substitutions in a query, replace ASTQueryParameter with ASTLiteral.
/// Rebuild ASTIdentifiers if some parts are ASTQueryParameter.
class ReplaceQueryParameterVisitor
{
public:
explicit ReplaceQueryParameterVisitor(const NameToNameMap & parameters)
: query_parameters(parameters)
{}
void visit(ASTPtr & ast);
size_t getNumberOfReplacedParameters() const { return num_replaced_parameters; }
private:
const NameToNameMap & query_parameters;
size_t num_replaced_parameters = 0;
const String & getParamValue(const String & name);
void visitIdentifier(ASTPtr & ast);
void visitQueryParameter(ASTPtr & ast);
void visitChildren(ASTPtr & ast);
};
}