ClickHouse/src/Parsers/ParserExplainQuery.cpp

61 lines
1.6 KiB
C++
Raw Normal View History

2020-06-22 13:26:55 +00:00
#include <Parsers/ParserExplainQuery.h>
#include <Parsers/ASTExplainQuery.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ParserSelectWithUnionQuery.h>
2020-06-23 11:26:06 +00:00
#include <Parsers/ParserSetQuery.h>
2020-06-22 13:26:55 +00:00
namespace DB
{
bool ParserExplainQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
ASTExplainQuery::ExplainKind kind;
ParserKeyword s_ast("AST");
ParserKeyword s_explain("EXPLAIN");
ParserKeyword s_syntax("SYNTAX");
2020-06-25 09:39:17 +00:00
ParserKeyword s_pipeline("PIPELINE");
2020-07-02 08:40:41 +00:00
ParserKeyword s_plan("PLAN");
2020-06-22 13:26:55 +00:00
if (s_explain.ignore(pos, expected))
2020-06-22 13:26:55 +00:00
{
kind = ASTExplainQuery::QueryPlan;
if (s_ast.ignore(pos, expected))
kind = ASTExplainQuery::ExplainKind::ParsedAST;
else if (s_syntax.ignore(pos, expected))
kind = ASTExplainQuery::ExplainKind::AnalyzedSyntax;
2020-06-25 09:39:17 +00:00
else if (s_pipeline.ignore(pos, expected))
kind = ASTExplainQuery::ExplainKind::QueryPipeline;
2020-07-02 08:40:41 +00:00
else if (s_plan.ignore(pos, expected))
kind = ASTExplainQuery::ExplainKind::QueryPlan;
2020-06-22 13:26:55 +00:00
}
else
return false;
auto explain_query = std::make_shared<ASTExplainQuery>(kind);
2020-06-22 13:26:55 +00:00
2020-06-23 11:26:06 +00:00
{
ASTPtr settings;
ParserSetQuery parser_settings(true);
auto begin = pos;
if (parser_settings.parse(pos, settings, expected))
explain_query->setSettings(std::move(settings));
else
pos = begin;
}
2020-06-22 13:26:55 +00:00
ParserSelectWithUnionQuery select_p;
2020-06-23 11:26:06 +00:00
ASTPtr query;
if (!select_p.parse(pos, query, expected))
2020-06-22 13:26:55 +00:00
return false;
2020-06-23 11:26:06 +00:00
explain_query->setExplainedQuery(std::move(query));
2020-06-22 13:26:55 +00:00
node = std::move(explain_query);
return true;
}
}