1#include <Parsers/ASTQueryWithOnCluster.h>
2#include <Parsers/queryToString.h>
3#include <Parsers/CommonParsers.h>
4#include <Parsers/ExpressionElementParsers.h>
5#include <Parsers/parseIdentifierOrStringLiteral.h>
6#include <Common/typeid_cast.h>
7#include <Common/quoteString.h>
8#include <Interpreters/evaluateConstantExpression.h>
9
10
11namespace DB
12{
13
14std::string ASTQueryWithOnCluster::getRewrittenQueryWithoutOnCluster(const std::string & new_database) const
15{
16 return queryToString(getRewrittenASTWithoutOnCluster(new_database));
17}
18
19
20bool ASTQueryWithOnCluster::parse(Pos & pos, std::string & cluster_str, Expected & expected)
21{
22 if (!ParserKeyword{"CLUSTER"}.ignore(pos, expected))
23 return false;
24
25 return parseIdentifierOrStringLiteral(pos, expected, cluster_str);
26}
27
28
29void ASTQueryWithOnCluster::formatOnCluster(const IAST::FormatSettings & settings) const
30{
31 if (!cluster.empty())
32 {
33 settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << " ON CLUSTER " << (settings.hilite ? IAST::hilite_none : "")
34 << backQuoteIfNeed(cluster);
35 }
36}
37
38
39}
40