ClickHouse/src/Parsers/ParserExplainQuery.cpp

72 lines
2.0 KiB
C++
Raw Normal View History

2020-06-22 13:26:55 +00:00
#include <Parsers/ParserExplainQuery.h>
2020-06-22 13:26:55 +00:00
#include <Parsers/ASTExplainQuery.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ParserCreateQuery.h>
2020-06-22 13:26:55 +00:00
#include <Parsers/ParserSelectWithUnionQuery.h>
2020-06-23 11:26:06 +00:00
#include <Parsers/ParserSetQuery.h>
2020-12-16 10:00:21 +00:00
#include <Parsers/ParserQuery.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;
}
ParserCreateTableQuery create_p;
2020-06-22 13:26:55 +00:00
ParserSelectWithUnionQuery select_p;
2020-06-23 11:26:06 +00:00
ASTPtr query;
2020-12-16 10:00:21 +00:00
if (kind == ASTExplainQuery::ExplainKind::ParsedAST)
{
ParserQuery p(end);
if (p.parse(pos, query, expected))
explain_query->setExplainedQuery(std::move(query));
}
else if (select_p.parse(pos, query, expected) ||
create_p.parse(pos, query, expected))
explain_query->setExplainedQuery(std::move(query));
else
2020-06-22 13:26:55 +00:00
return false;
node = std::move(explain_query);
return true;
}
}