2011-10-30 05:19:41 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-03-13 10:30:55 +00:00
|
|
|
#include <Interpreters/StorageID.h>
|
2021-06-28 20:43:37 +00:00
|
|
|
#include <Parsers/IAST.h>
|
2011-10-30 05:19:41 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-02-15 18:57:35 +00:00
|
|
|
class ReadBuffer;
|
2011-10-30 05:19:41 +00:00
|
|
|
|
2021-06-28 20:43:37 +00:00
|
|
|
/// INSERT query
|
2011-10-30 05:19:41 +00:00
|
|
|
class ASTInsertQuery : public IAST
|
|
|
|
{
|
|
|
|
public:
|
2020-03-02 20:23:58 +00:00
|
|
|
StorageID table_id = StorageID::createEmpty();
|
2021-10-12 23:51:11 +00:00
|
|
|
|
|
|
|
ASTPtr database;
|
|
|
|
ASTPtr table;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr columns;
|
|
|
|
String format;
|
2017-11-02 14:01:11 +00:00
|
|
|
ASTPtr table_function;
|
2021-04-14 08:00:17 +00:00
|
|
|
ASTPtr partition_by;
|
2019-02-19 19:26:41 +00:00
|
|
|
ASTPtr settings_ast;
|
2017-10-03 23:43:55 +00:00
|
|
|
|
2021-03-04 11:10:21 +00:00
|
|
|
ASTPtr select;
|
|
|
|
ASTPtr watch;
|
2021-08-26 00:31:46 +00:00
|
|
|
ASTPtr infile;
|
2021-09-15 14:47:22 +00:00
|
|
|
ASTPtr compression;
|
2021-03-04 11:10:21 +00:00
|
|
|
|
2021-06-28 20:43:37 +00:00
|
|
|
/// Data inlined into query
|
2017-04-01 07:20:54 +00:00
|
|
|
const char * data = nullptr;
|
|
|
|
const char * end = nullptr;
|
|
|
|
|
2021-06-28 20:43:37 +00:00
|
|
|
/// Data from buffer to insert after inlined one - may be nullptr.
|
|
|
|
ReadBuffer * tail = nullptr;
|
|
|
|
|
2021-10-12 23:51:11 +00:00
|
|
|
String getDatabase() const;
|
|
|
|
String getTable() const;
|
|
|
|
|
|
|
|
void setDatabase(const String & name);
|
|
|
|
void setTable(const String & name);
|
|
|
|
|
2021-09-14 23:54:10 +00:00
|
|
|
bool hasInlinedData() const { return data || tail; }
|
2019-02-08 13:24:24 +00:00
|
|
|
|
2019-05-30 20:12:44 +00:00
|
|
|
/// Try to find table function input() in SELECT part
|
2019-05-30 21:33:06 +00:00
|
|
|
void tryFindInputFunction(ASTPtr & input_function) const;
|
2019-05-30 20:12:44 +00:00
|
|
|
|
2017-05-27 17:27:16 +00:00
|
|
|
/** Get the text that identifies this element. */
|
2020-03-02 20:23:58 +00:00
|
|
|
String getID(char delim) const override { return "InsertQuery" + (delim + table_id.database_name) + delim + table_id.table_name; }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
ASTPtr clone() const override
|
|
|
|
{
|
|
|
|
auto res = std::make_shared<ASTInsertQuery>(*this);
|
|
|
|
res->children.clear();
|
|
|
|
|
2021-10-12 23:51:11 +00:00
|
|
|
if (database) { res->database = database->clone(); res->children.push_back(res->database); }
|
|
|
|
if (table) { res->columns = columns->clone(); res->children.push_back(res->table); }
|
2017-07-10 03:28:12 +00:00
|
|
|
if (columns) { res->columns = columns->clone(); res->children.push_back(res->columns); }
|
2018-11-26 00:56:50 +00:00
|
|
|
if (select) { res->select = select->clone(); res->children.push_back(res->select); }
|
2020-04-25 11:33:47 +00:00
|
|
|
if (watch) { res->watch = watch->clone(); res->children.push_back(res->watch); }
|
2019-02-19 19:26:41 +00:00
|
|
|
if (table_function) { res->table_function = table_function->clone(); res->children.push_back(res->table_function); }
|
2021-04-14 08:00:17 +00:00
|
|
|
if (partition_by) { res->partition_by = partition_by->clone(); res->children.push_back(res->partition_by); }
|
2019-02-19 19:26:41 +00:00
|
|
|
if (settings_ast) { res->settings_ast = settings_ast->clone(); res->children.push_back(res->settings_ast); }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2015-08-05 21:38:31 +00:00
|
|
|
|
2021-08-04 14:09:23 +00:00
|
|
|
const char * getQueryKindString() const override { return "Insert"; }
|
|
|
|
|
2015-08-05 21:38:31 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
|
2021-08-31 02:16:02 +00:00
|
|
|
void updateTreeHashImpl(SipHash & hash_state) const override;
|
2011-10-30 05:19:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|