ClickHouse/src/Parsers/ParserExplainQuery.cpp

94 lines
3.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>
#include <Parsers/ParserInsertQuery.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");
2021-07-10 23:14:03 +00:00
ParserKeyword s_estimates("ESTIMATE");
ParserKeyword s_table_override("TABLE OVERRIDE");
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; //-V1048
2021-07-09 10:29:45 +00:00
else if (s_estimates.ignore(pos, expected))
kind = ASTExplainQuery::ExplainKind::QueryEstimates; //-V1048
else if (s_table_override.ignore(pos, expected))
kind = ASTExplainQuery::ExplainKind::TableOverride;
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;
ParserInsertQuery insert_p(end);
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
return false;
2020-12-16 10:00:21 +00:00
}
else if (kind == ASTExplainQuery::ExplainKind::TableOverride)
{
ASTPtr table_function;
if (!ParserFunction(true, true).parse(pos, table_function, expected))
return false;
ASTPtr table_override;
if (!ParserTableOverrideDeclaration(false).parse(pos, table_override, expected))
return false;
explain_query->setTableFunction(table_function);
explain_query->setTableOverride(table_override);
}
2020-12-16 10:00:21 +00:00
else if (select_p.parse(pos, query, expected) ||
create_p.parse(pos, query, expected) ||
insert_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;
}
}