explain ast support nonselect queries

This commit is contained in:
taiyang-li 2020-12-16 18:00:21 +08:00
parent eed767bbab
commit cd7827f70c
7 changed files with 26 additions and 3 deletions

View File

@ -5,6 +5,7 @@
#include <Parsers/ParserCreateQuery.h>
#include <Parsers/ParserSelectWithUnionQuery.h>
#include <Parsers/ParserSetQuery.h>
#include <Parsers/ParserQuery.h>
namespace DB
{
@ -51,7 +52,13 @@ bool ParserExplainQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected
ParserCreateTableQuery create_p;
ParserSelectWithUnionQuery select_p;
ASTPtr query;
if (select_p.parse(pos, query, expected) ||
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

View File

@ -9,8 +9,12 @@ namespace DB
class ParserExplainQuery : public IParserBase
{
protected:
const char * end;
const char * getName() const override { return "EXPLAIN"; }
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
public:
ParserExplainQuery(const char* end_) : end(end_) {}
};
}

View File

@ -26,7 +26,7 @@ namespace DB
bool ParserQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
ParserQueryWithOutput query_with_output_p;
ParserQueryWithOutput query_with_output_p(end);
ParserInsertQuery insert_p(end);
ParserUseQuery use_p;
ParserSetQuery set_p;

View File

@ -48,7 +48,7 @@ bool ParserQueryWithOutput::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
ParserShowCreateAccessEntityQuery show_create_access_entity_p;
ParserShowGrantsQuery show_grants_p;
ParserShowPrivilegesQuery show_privileges_p;
ParserExplainQuery explain_p;
ParserExplainQuery explain_p(end);
ASTPtr query;

View File

@ -11,8 +11,11 @@ namespace DB
class ParserQueryWithOutput : public IParserBase
{
protected:
const char * end;
const char * getName() const override { return "Query with output"; }
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
public:
ParserQueryWithOutput(const char * end_) : end(end_) {}
};
}

View File

@ -0,0 +1,8 @@
AlterQuery t1 (children 1)
ExpressionList (children 1)
AlterCommand 25 (children 1)
Function equals (children 1)
ExpressionList (children 2)
Identifier date
Function today (children 1)
ExpressionList

View File

@ -0,0 +1 @@
explain ast alter table t1 delete where date = today();