ClickHouse/src/Parsers/ASTExplainQuery.h

57 lines
1.3 KiB
C++
Raw Normal View History

2018-09-21 15:20:23 +00:00
#pragma once
#include <Parsers/IAST.h>
namespace DB
{
/// AST, EXPLAIN or other query with meaning of explanation query instead of execution
class ASTExplainQuery : public IAST
{
public:
enum ExplainKind
{
ParsedAST,
AnalyzedSyntax,
2018-09-21 15:20:23 +00:00
};
ASTExplainQuery(ExplainKind kind_)
2018-09-21 15:20:23 +00:00
: kind(kind_)
{}
String getID(char delim) const override { return "Explain" + (delim + toString(kind)); }
ExplainKind getKind() const { return kind; }
ASTPtr clone() const override
{
auto res = std::make_shared<ASTExplainQuery>(*this);
res->children.clear();
res->children.push_back(children[0]->clone());
return res;
}
2018-09-21 15:20:23 +00:00
protected:
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
2018-09-21 15:20:23 +00:00
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << toString(kind) << (settings.hilite ? hilite_none : "") << " ";
children.at(0)->formatImpl(settings, state, frame);
2018-09-21 15:20:23 +00:00
}
private:
ExplainKind kind;
static String toString(ExplainKind kind)
{
switch (kind)
{
case ParsedAST: return "AST";
case AnalyzedSyntax: return "ANALYZE";
2018-09-21 15:20:23 +00:00
}
2019-02-15 10:15:56 +00:00
__builtin_unreachable();
2018-09-21 15:20:23 +00:00
}
};
}