2013-02-21 10:02:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/IAST.h>
|
|
|
|
#include <Parsers/ASTQueryWithOutput.h>
|
2013-02-21 10:02:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2015-08-06 03:26:27 +00:00
|
|
|
|
|
|
|
|
2017-05-27 17:27:16 +00:00
|
|
|
/** Query specifying table name and, possibly, the database and the FORMAT section.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
2015-08-05 21:38:31 +00:00
|
|
|
class ASTQueryWithTableAndOutput : public ASTQueryWithOutput
|
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
String database;
|
|
|
|
String table;
|
2015-08-05 21:38:31 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTQueryWithTableAndOutput() = default;
|
2017-11-01 14:34:05 +00:00
|
|
|
explicit ASTQueryWithTableAndOutput(const StringRange range_) : ASTQueryWithOutput(range_) {}
|
2015-08-06 03:26:27 +00:00
|
|
|
|
|
|
|
protected:
|
2017-12-01 18:36:55 +00:00
|
|
|
void formatHelper(const FormatSettings & settings, const char * name) const
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << name << " " << (settings.hilite ? hilite_none : "")
|
|
|
|
<< (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table);
|
|
|
|
}
|
2015-08-05 21:38:31 +00:00
|
|
|
};
|
2015-08-06 03:26:27 +00:00
|
|
|
|
|
|
|
|
2017-11-01 14:34:05 +00:00
|
|
|
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-11-01 14:34:05 +00:00
|
|
|
{
|
2017-12-11 18:38:43 +00:00
|
|
|
formatHelper(settings, AstIDAndQueryNames::Query);
|
2017-11-01 14:34:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-21 10:02:33 +00:00
|
|
|
}
|