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>
|
2011-08-18 20:33:20 +00:00
|
|
|
|
|
|
|
|
2017-05-23 18:33:48 +00:00
|
|
|
class ThreadPool;
|
|
|
|
|
2011-08-18 20:33:20 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
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;
|
2017-05-23 18:33:48 +00:00
|
|
|
class IStorage;
|
|
|
|
using StoragePtr = std::shared_ptr<IStorage>;
|
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
|
|
|
|
|
|
|
void setDatabaseLoadingThreadpool(ThreadPool & thread_pool_)
|
|
|
|
{
|
|
|
|
thread_pool = &thread_pool_;
|
|
|
|
}
|
|
|
|
|
|
|
|
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_;
|
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Obtain information about columns, their types and default values, 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);
|
2016-03-19 01:18:49 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-25 15:21:03 +00:00
|
|
|
BlockIO createDatabase(ASTCreateQuery & create);
|
2017-04-21 12:39:28 +00:00
|
|
|
BlockIO createTable(ASTCreateQuery & create);
|
2017-04-13 13:42:29 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Calculate list of columns of table and return it.
|
2018-03-06 20:18:34 +00:00
|
|
|
ColumnsDescription setColumns(ASTCreateQuery & create, const Block & as_select_sample, const StoragePtr & as_storage) const;
|
2017-10-25 19:52:32 +00:00
|
|
|
void setEngine(ASTCreateQuery & create) const;
|
2017-12-20 07:39:52 +00:00
|
|
|
void checkAccess(const ASTCreateQuery & create);
|
2017-12-25 21:10:46 +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
|
|
|
/// Using while loading database.
|
|
|
|
ThreadPool * thread_pool = nullptr;
|
2016-08-09 21:48:05 +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
|
|
|
};
|
|
|
|
}
|