mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 19:42:00 +00:00
62 lines
1.6 KiB
C++
62 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <Parsers/IAST.h>
|
|
#include <Parsers/ASTQueryWithOutput.h>
|
|
#include <Core/UUID.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
|
|
/** Query specifying table name and, possibly, the database and the FORMAT section.
|
|
*/
|
|
class ASTQueryWithTableAndOutput : public ASTQueryWithOutput
|
|
{
|
|
public:
|
|
ASTPtr database;
|
|
ASTPtr table;
|
|
|
|
UUID uuid = UUIDHelpers::Nil;
|
|
bool temporary{false};
|
|
|
|
String getDatabase() const;
|
|
String getTable() const;
|
|
|
|
// Once database or table are set they cannot be assigned with empty value
|
|
void setDatabase(const String & name);
|
|
void setTable(const String & name);
|
|
|
|
void cloneTableOptions(ASTQueryWithTableAndOutput & cloned) const;
|
|
|
|
protected:
|
|
void formatHelper(const FormatSettings & settings, const char * name) const;
|
|
};
|
|
|
|
|
|
template <typename AstIDAndQueryNames>
|
|
class ASTQueryWithTableAndOutputImpl : public ASTQueryWithTableAndOutput
|
|
{
|
|
public:
|
|
String getID(char delim) const override { return AstIDAndQueryNames::ID + (delim + getDatabase()) + delim + getTable(); }
|
|
|
|
ASTPtr clone() const override
|
|
{
|
|
auto res = std::make_shared<ASTQueryWithTableAndOutputImpl<AstIDAndQueryNames>>(*this);
|
|
res->children.clear();
|
|
cloneOutputOptions(*res);
|
|
cloneTableOptions(*res);
|
|
return res;
|
|
}
|
|
|
|
QueryKind getQueryKind() const override { return QueryKind::Show; }
|
|
|
|
protected:
|
|
void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override
|
|
{
|
|
formatHelper(settings, temporary ? AstIDAndQueryNames::QueryTemporary : AstIDAndQueryNames::Query);
|
|
}
|
|
};
|
|
|
|
}
|