1#pragma once
2
3#include <Parsers/IAST.h>
4#include <Parsers/ASTQueryWithOutput.h>
5
6
7namespace DB
8{
9
10
11/** Query specifying table name and, possibly, the database and the FORMAT section.
12 */
13class ASTQueryWithTableAndOutput : public ASTQueryWithOutput
14{
15public:
16 String database;
17 String table;
18 bool temporary{false};
19
20protected:
21 void formatHelper(const FormatSettings & settings, const char * name) const;
22};
23
24
25template <typename AstIDAndQueryNames>
26class ASTQueryWithTableAndOutputImpl : public ASTQueryWithTableAndOutput
27{
28public:
29 String getID(char delim) const override { return AstIDAndQueryNames::ID + (delim + database) + delim + table; }
30
31 ASTPtr clone() const override
32 {
33 auto res = std::make_shared<ASTQueryWithTableAndOutputImpl<AstIDAndQueryNames>>(*this);
34 res->children.clear();
35 cloneOutputOptions(*res);
36 return res;
37 }
38
39protected:
40 void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override
41 {
42 formatHelper(settings, temporary ? AstIDAndQueryNames::QueryTemporary : AstIDAndQueryNames::Query);
43 }
44};
45
46}
47