2011-08-18 20:33:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/IInterpreter.h>
|
2018-03-06 20:18:34 +00:00
|
|
|
#include <Storages/ColumnsDescription.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Storages/IStorage_fwd.h>
|
2019-02-05 14:50:25 +00:00
|
|
|
#include <Storages/IndicesDescription.h>
|
2019-05-17 04:08:03 +00:00
|
|
|
#include <Storages/ConstraintsDescription.h>
|
2019-01-11 19:12:36 +00:00
|
|
|
#include <Common/ThreadPool.h>
|
2020-02-10 15:50:12 +00:00
|
|
|
#include <Access/AccessRightsElement.h>
|
2011-08-18 20:33:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2019-01-11 16:58:43 +00:00
|
|
|
|
2017-05-23 18:33:48 +00:00
|
|
|
class Context;
|
2016-03-19 01:18:49 +00:00
|
|
|
class ASTCreateQuery;
|
2017-09-17 18:49:43 +00:00
|
|
|
class ASTExpressionList;
|
2019-08-24 21:20:20 +00:00
|
|
|
class ASTConstraintDeclaration;
|
2016-03-19 01:18:49 +00:00
|
|
|
|
2011-08-18 20:33:20 +00:00
|
|
|
|
2016-08-09 21:48:05 +00:00
|
|
|
/** Allows to create new table or database,
|
|
|
|
* or create an object for existing table or database.
|
2011-08-18 20:33:20 +00:00
|
|
|
*/
|
2015-06-18 02:11:05 +00:00
|
|
|
class InterpreterCreateQuery : public IInterpreter
|
2011-08-18 20:33:20 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-05-23 18:33:48 +00:00
|
|
|
InterpreterCreateQuery(const ASTPtr & query_ptr_, Context & context_);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
BlockIO execute() override;
|
|
|
|
|
|
|
|
/// List of columns and their types in AST.
|
2017-12-25 21:57:29 +00:00
|
|
|
static ASTPtr formatColumns(const NamesAndTypesList & columns);
|
2018-03-06 20:18:34 +00:00
|
|
|
static ASTPtr formatColumns(const ColumnsDescription & columns);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-02-05 14:50:25 +00:00
|
|
|
static ASTPtr formatIndices(const IndicesDescription & indices);
|
2019-05-17 04:08:03 +00:00
|
|
|
static ASTPtr formatConstraints(const ConstraintsDescription & constraints);
|
2019-02-05 14:50:25 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void setForceRestoreData(bool has_force_restore_data_flag_)
|
|
|
|
{
|
|
|
|
has_force_restore_data_flag = has_force_restore_data_flag_;
|
|
|
|
}
|
|
|
|
|
2018-01-18 23:40:32 +00:00
|
|
|
void setInternal(bool internal_)
|
|
|
|
{
|
|
|
|
internal = internal_;
|
|
|
|
}
|
|
|
|
|
2018-10-14 15:30:06 +00:00
|
|
|
/// Obtain information about columns, their types, default values and column comments, for case when columns in CREATE query is specified explicitly.
|
2018-03-06 20:18:34 +00:00
|
|
|
static ColumnsDescription getColumnsDescription(const ASTExpressionList & columns, const Context & context);
|
2019-08-24 21:20:20 +00:00
|
|
|
static ConstraintsDescription getConstraintsDescription(const ASTExpressionList * constraints);
|
2016-03-19 01:18:49 +00:00
|
|
|
|
|
|
|
private:
|
2019-10-23 18:39:07 +00:00
|
|
|
struct TableProperties
|
|
|
|
{
|
|
|
|
ColumnsDescription columns;
|
|
|
|
IndicesDescription indices;
|
|
|
|
ConstraintsDescription constraints;
|
|
|
|
};
|
|
|
|
|
2017-04-25 15:21:03 +00:00
|
|
|
BlockIO createDatabase(ASTCreateQuery & create);
|
2017-04-21 12:39:28 +00:00
|
|
|
BlockIO createTable(ASTCreateQuery & create);
|
2019-10-11 13:21:52 +00:00
|
|
|
BlockIO createDictionary(ASTCreateQuery & create);
|
2017-04-13 13:42:29 +00:00
|
|
|
|
2019-10-23 18:39:07 +00:00
|
|
|
/// Calculate list of columns, constraints, indices, etc... of table. Rewrite query in canonical way.
|
|
|
|
TableProperties setProperties(ASTCreateQuery & create) const;
|
|
|
|
void validateTableStructure(const ASTCreateQuery & create, const TableProperties & properties) const;
|
2017-10-25 19:52:32 +00:00
|
|
|
void setEngine(ASTCreateQuery & create) const;
|
2020-01-24 16:20:36 +00:00
|
|
|
AccessRightsElements getRequiredAccess() const;
|
2017-12-25 21:10:46 +00:00
|
|
|
|
2019-10-23 18:39:07 +00:00
|
|
|
/// Create IStorage and add it to database. If table already exists and IF NOT EXISTS specified, do nothing and return false.
|
2019-12-05 11:42:13 +00:00
|
|
|
bool doCreateTable(/*const*/ ASTCreateQuery & create, const TableProperties & properties);
|
2019-10-23 18:39:07 +00:00
|
|
|
/// Inserts data in created table if it's CREATE ... SELECT
|
2019-12-16 18:29:18 +00:00
|
|
|
BlockIO fillTableIfNeeded(const ASTCreateQuery & create);
|
2019-10-23 18:39:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr query_ptr;
|
2017-05-23 18:33:48 +00:00
|
|
|
Context & context;
|
2016-03-19 01:18:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Skip safety threshold when loading tables.
|
|
|
|
bool has_force_restore_data_flag = false;
|
2018-01-18 23:40:32 +00:00
|
|
|
/// Is this an internal query - not from the user.
|
|
|
|
bool internal = false;
|
2011-08-18 20:33:20 +00:00
|
|
|
};
|
|
|
|
}
|