2011-08-18 18:48:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-18 15:03:14 +00:00
|
|
|
#include <Parsers/ASTQueryWithTableAndOutput.h>
|
2017-04-21 12:39:28 +00:00
|
|
|
#include <Parsers/ASTQueryWithOnCluster.h>
|
2019-10-01 14:54:28 +00:00
|
|
|
#include <Parsers/ASTDictionary.h>
|
|
|
|
#include <Parsers/ASTDictionaryAttributeDeclaration.h>
|
2020-12-04 02:15:44 +00:00
|
|
|
#include <Parsers/ASTIdentifier.h>
|
2020-01-29 17:44:16 +00:00
|
|
|
#include <Parsers/ASTSelectWithUnionQuery.h>
|
2020-03-16 11:38:50 +00:00
|
|
|
#include <Interpreters/StorageID.h>
|
2011-08-18 18:48:00 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-03-23 22:45:28 +00:00
|
|
|
class ASTFunction;
|
|
|
|
class ASTSetQuery;
|
|
|
|
|
2017-09-17 18:49:43 +00:00
|
|
|
class ASTStorage : public IAST
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ASTFunction * engine = nullptr;
|
2017-09-18 14:18:29 +00:00
|
|
|
IAST * partition_by = nullptr;
|
2018-10-10 18:24:11 +00:00
|
|
|
IAST * primary_key = nullptr;
|
2017-09-18 14:18:29 +00:00
|
|
|
IAST * order_by = nullptr;
|
|
|
|
IAST * sample_by = nullptr;
|
2019-04-15 09:30:45 +00:00
|
|
|
IAST * ttl_table = nullptr;
|
2017-09-18 14:18:29 +00:00
|
|
|
ASTSetQuery * settings = nullptr;
|
2017-09-17 18:49:43 +00:00
|
|
|
|
2018-12-07 12:34:40 +00:00
|
|
|
String getID(char) const override { return "Storage definition"; }
|
2017-09-17 18:49:43 +00:00
|
|
|
|
2019-03-23 22:45:28 +00:00
|
|
|
ASTPtr clone() const override;
|
2017-09-17 18:49:43 +00:00
|
|
|
|
2019-03-23 22:45:28 +00:00
|
|
|
void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const override;
|
2017-09-17 18:49:43 +00:00
|
|
|
};
|
|
|
|
|
2011-08-18 18:48:00 +00:00
|
|
|
|
2019-03-23 22:45:28 +00:00
|
|
|
class ASTExpressionList;
|
2019-02-05 14:50:25 +00:00
|
|
|
|
2019-03-23 22:45:28 +00:00
|
|
|
class ASTColumns : public IAST
|
|
|
|
{
|
2019-02-05 14:50:25 +00:00
|
|
|
public:
|
|
|
|
ASTExpressionList * columns = nullptr;
|
|
|
|
ASTExpressionList * indices = nullptr;
|
2019-05-12 11:36:02 +00:00
|
|
|
ASTExpressionList * constraints = nullptr;
|
2020-10-12 13:55:41 +00:00
|
|
|
IAST * primary_key = nullptr;
|
2019-02-05 14:50:25 +00:00
|
|
|
|
|
|
|
String getID(char) const override { return "Columns definition"; }
|
|
|
|
|
2019-03-23 22:45:28 +00:00
|
|
|
ASTPtr clone() const override;
|
2019-02-05 14:50:25 +00:00
|
|
|
|
2019-03-23 22:45:28 +00:00
|
|
|
void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const override;
|
2019-02-05 14:50:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-04-13 16:12:56 +00:00
|
|
|
/// CREATE TABLE or ATTACH TABLE query
|
2018-10-18 15:03:14 +00:00
|
|
|
class ASTCreateQuery : public ASTQueryWithTableAndOutput, public ASTQueryWithOnCluster
|
2011-08-18 18:48:00 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-05-27 17:27:16 +00:00
|
|
|
bool attach{false}; /// Query ATTACH TABLE, not CREATE TABLE.
|
2017-04-01 07:20:54 +00:00
|
|
|
bool if_not_exists{false};
|
2020-12-16 03:19:38 +00:00
|
|
|
bool is_ordinary_view{false};
|
2017-04-01 07:20:54 +00:00
|
|
|
bool is_materialized_view{false};
|
2019-05-28 21:17:48 +00:00
|
|
|
bool is_live_view{false};
|
2017-04-01 07:20:54 +00:00
|
|
|
bool is_populate{false};
|
2019-03-11 16:50:31 +00:00
|
|
|
bool replace_view{false}; /// CREATE OR REPLACE VIEW
|
2019-02-05 14:50:25 +00:00
|
|
|
ASTColumns * columns_list = nullptr;
|
2019-10-01 14:54:28 +00:00
|
|
|
ASTExpressionList * tables = nullptr;
|
2020-12-25 16:28:10 +00:00
|
|
|
|
2020-01-15 16:17:04 +00:00
|
|
|
StorageID to_table_id = StorageID::createEmpty(); /// For CREATE MATERIALIZED VIEW mv TO table.
|
2017-09-17 18:49:43 +00:00
|
|
|
ASTStorage * storage = nullptr;
|
2017-04-01 07:20:54 +00:00
|
|
|
String as_database;
|
|
|
|
String as_table;
|
2019-07-18 18:29:49 +00:00
|
|
|
ASTPtr as_table_function;
|
2018-02-25 06:34:20 +00:00
|
|
|
ASTSelectWithUnionQuery * select = nullptr;
|
2020-08-05 02:21:33 +00:00
|
|
|
|
|
|
|
bool is_dictionary{false}; /// CREATE DICTIONARY
|
|
|
|
ASTExpressionList * dictionary_attributes_list = nullptr; /// attributes of
|
2019-10-08 13:26:15 +00:00
|
|
|
ASTDictionary * dictionary = nullptr; /// dictionary definition (layout, primary key, etc.)
|
2020-08-05 02:21:33 +00:00
|
|
|
|
2020-02-14 18:20:20 +00:00
|
|
|
std::optional<UInt64> live_view_timeout; /// For CREATE LIVE VIEW ... WITH TIMEOUT ...
|
2020-09-14 19:39:33 +00:00
|
|
|
std::optional<UInt64> live_view_periodic_refresh; /// For CREATE LIVE VIEW ... WITH [PERIODIC] REFRESH ...
|
|
|
|
|
2020-03-23 00:12:13 +00:00
|
|
|
bool attach_short_syntax{false};
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-12-08 14:13:35 +00:00
|
|
|
std::optional<String> attach_from_path = std::nullopt;
|
|
|
|
|
2020-12-25 16:28:10 +00:00
|
|
|
bool replace_table{false};
|
|
|
|
bool create_or_replace{false};
|
|
|
|
|
2017-05-27 17:27:16 +00:00
|
|
|
/** Get the text that identifies this element. */
|
2018-12-07 12:34:40 +00:00
|
|
|
String getID(char delim) const override { return (attach ? "AttachQuery" : "CreateQuery") + (delim + database) + delim + table; }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-03-23 22:45:28 +00:00
|
|
|
ASTPtr clone() const override;
|
2015-08-05 21:38:31 +00:00
|
|
|
|
2017-04-13 16:12:56 +00:00
|
|
|
ASTPtr getRewrittenASTWithoutOnCluster(const std::string & new_database) const override
|
|
|
|
{
|
2018-10-24 15:31:07 +00:00
|
|
|
return removeOnCluster<ASTCreateQuery>(clone(), new_database);
|
2017-04-13 16:12:56 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 04:07:50 +00:00
|
|
|
bool isView() const { return is_ordinary_view || is_materialized_view || is_live_view; }
|
2020-12-14 14:37:25 +00:00
|
|
|
|
2015-08-05 21:38:31 +00:00
|
|
|
protected:
|
2019-03-23 22:45:28 +00:00
|
|
|
void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
|
2011-08-18 18:48:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|