ClickHouse/dbms/src/Parsers/ASTQueryWithTableAndOutput.h

57 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
#include <Parsers/IAST.h>
#include <Parsers/ASTQueryWithOutput.h>
namespace DB
{
2017-05-27 17:27:16 +00:00
/** Query specifying table name and, possibly, the database and the FORMAT section.
*/
class ASTQueryWithTableAndOutput : public ASTQueryWithOutput
{
public:
String database;
String table;
ASTQueryWithTableAndOutput() = default;
explicit ASTQueryWithTableAndOutput(const StringRange range_) : ASTQueryWithOutput(range_) {}
protected:
2017-12-01 18:36:55 +00:00
void formatHelper(const FormatSettings & settings, const char * name) const
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << name << " " << (settings.hilite ? hilite_none : "")
<< (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table);
}
};
template <typename AstIDAndQueryNames>
class ASTQueryWithTableAndOutputImpl : public ASTQueryWithTableAndOutput
{
public:
ASTQueryWithTableAndOutputImpl() = default;
explicit ASTQueryWithTableAndOutputImpl(const StringRange range_) : ASTQueryWithTableAndOutput(range_) {}
String getID() const override { return AstIDAndQueryNames::ID + ("_" + database) + "_" + table; };
ASTPtr clone() const override
{
auto res = std::make_shared<ASTQueryWithTableAndOutputImpl<AstIDAndQueryNames>>(*this);
res->children.clear();
cloneOutputOptions(*res);
return res;
}
protected:
2017-12-11 18:40:28 +00:00
void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override
{
2017-12-11 18:38:43 +00:00
formatHelper(settings, AstIDAndQueryNames::Query);
}
};
}