1#pragma once
2
3#include <Parsers/ASTQueryWithTableAndOutput.h>
4#include <Parsers/ASTQueryWithOnCluster.h>
5#include <Parsers/ASTDictionary.h>
6#include <Parsers/ASTDictionaryAttributeDeclaration.h>
7
8
9namespace DB
10{
11
12class ASTFunction;
13class ASTSetQuery;
14
15class ASTStorage : public IAST
16{
17public:
18 ASTFunction * engine = nullptr;
19 IAST * partition_by = nullptr;
20 IAST * primary_key = nullptr;
21 IAST * order_by = nullptr;
22 IAST * sample_by = nullptr;
23 IAST * ttl_table = nullptr;
24 ASTSetQuery * settings = nullptr;
25
26 String getID(char) const override { return "Storage definition"; }
27
28 ASTPtr clone() const override;
29
30 void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const override;
31};
32
33
34class ASTExpressionList;
35
36class ASTColumns : public IAST
37{
38public:
39 ASTExpressionList * columns = nullptr;
40 ASTExpressionList * indices = nullptr;
41 ASTExpressionList * constraints = nullptr;
42
43 String getID(char) const override { return "Columns definition"; }
44
45 ASTPtr clone() const override;
46
47 void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const override;
48};
49
50
51class ASTSelectWithUnionQuery;
52
53/// CREATE TABLE or ATTACH TABLE query
54class ASTCreateQuery : public ASTQueryWithTableAndOutput, public ASTQueryWithOnCluster
55{
56public:
57 bool attach{false}; /// Query ATTACH TABLE, not CREATE TABLE.
58 bool if_not_exists{false};
59 bool is_view{false};
60 bool is_materialized_view{false};
61 bool is_live_view{false};
62 bool is_populate{false};
63 bool is_dictionary{false}; /// CREATE DICTIONARY
64 bool replace_view{false}; /// CREATE OR REPLACE VIEW
65 ASTColumns * columns_list = nullptr;
66 ASTExpressionList * dictionary_attributes_list = nullptr; /// attributes of dictionary
67 ASTExpressionList * tables = nullptr;
68 String to_database; /// For CREATE MATERIALIZED VIEW mv TO table.
69 String to_table;
70 ASTStorage * storage = nullptr;
71 String as_database;
72 String as_table;
73 ASTPtr as_table_function;
74 ASTSelectWithUnionQuery * select = nullptr;
75 ASTDictionary * dictionary = nullptr; /// dictionary definition (layout, primary key, etc.)
76
77 /** Get the text that identifies this element. */
78 String getID(char delim) const override { return (attach ? "AttachQuery" : "CreateQuery") + (delim + database) + delim + table; }
79
80 ASTPtr clone() const override;
81
82 ASTPtr getRewrittenASTWithoutOnCluster(const std::string & new_database) const override
83 {
84 return removeOnCluster<ASTCreateQuery>(clone(), new_database);
85 }
86
87protected:
88 void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
89};
90
91}
92