2011-08-18 20:33:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Storages/IStorage.h>
|
|
|
|
#include <DB/Interpreters/Context.h>
|
2015-06-18 02:11:05 +00:00
|
|
|
#include <DB/Interpreters/IInterpreter.h>
|
2014-09-29 14:58:48 +00:00
|
|
|
#include <DB/Storages/ColumnDefault.h>
|
2016-08-02 01:46:05 +00:00
|
|
|
#include <DB/Common/ThreadPool.h>
|
2011-08-18 20:33:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-03-19 01:18:49 +00:00
|
|
|
class ASTCreateQuery;
|
|
|
|
|
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:
|
2012-03-05 00:09:41 +00:00
|
|
|
InterpreterCreateQuery(ASTPtr query_ptr_, Context & context_);
|
2014-09-25 15:01:09 +00:00
|
|
|
|
2016-03-19 01:18:49 +00:00
|
|
|
BlockIO execute() override;
|
2014-07-10 11:13:45 +00:00
|
|
|
|
2016-08-09 21:48:05 +00:00
|
|
|
/// List of columns and their types in AST.
|
2014-07-10 11:13:45 +00:00
|
|
|
static ASTPtr formatColumns(const NamesAndTypesList & columns);
|
2014-09-30 03:08:47 +00:00
|
|
|
static ASTPtr formatColumns(
|
|
|
|
NamesAndTypesList columns,
|
2014-10-03 15:30:10 +00:00
|
|
|
const NamesAndTypesList & materialized_columns,
|
2014-09-30 03:08:47 +00:00
|
|
|
const NamesAndTypesList & alias_columns,
|
|
|
|
const ColumnDefaults & column_defaults);
|
2014-09-25 15:01:09 +00:00
|
|
|
|
2016-08-02 01:46:05 +00:00
|
|
|
void setDatabaseLoadingThreadpool(ThreadPool & thread_pool_)
|
2016-03-19 01:18:49 +00:00
|
|
|
{
|
|
|
|
thread_pool = &thread_pool_;
|
|
|
|
}
|
2015-06-18 02:11:05 +00:00
|
|
|
|
2016-08-09 21:48:05 +00:00
|
|
|
void setForceRestoreData(bool has_force_restore_data_flag_)
|
|
|
|
{
|
|
|
|
has_force_restore_data_flag = has_force_restore_data_flag_;
|
|
|
|
}
|
|
|
|
|
2016-03-19 01:18:49 +00:00
|
|
|
struct ColumnsInfo
|
|
|
|
{
|
2016-05-28 08:11:52 +00:00
|
|
|
NamesAndTypesListPtr columns = std::make_shared<NamesAndTypesList>();
|
2016-03-19 01:18:49 +00:00
|
|
|
NamesAndTypesList materialized_columns;
|
|
|
|
NamesAndTypesList alias_columns;
|
|
|
|
ColumnDefaults column_defaults;
|
|
|
|
};
|
2014-09-25 15:01:09 +00:00
|
|
|
|
2016-08-09 21:48:05 +00:00
|
|
|
/// Obtain information about columns, their types and default values, for case when columns in CREATE query is specified explicitly.
|
2016-03-19 01:18:49 +00:00
|
|
|
static ColumnsInfo getColumnsInfo(const ASTPtr & columns, const Context & context);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void createDatabase(ASTCreateQuery & create);
|
|
|
|
BlockIO createTable(ASTCreateQuery & create);
|
|
|
|
|
2016-08-09 21:48:05 +00:00
|
|
|
/// Calculate list of columns of table and return it.
|
2016-03-19 01:18:49 +00:00
|
|
|
ColumnsInfo setColumns(ASTCreateQuery & create, const Block & as_select_sample, const StoragePtr & as_storage) const;
|
|
|
|
String setEngine(ASTCreateQuery & create, const StoragePtr & as_storage) const;
|
2014-09-25 15:01:09 +00:00
|
|
|
|
2011-11-01 15:16:04 +00:00
|
|
|
ASTPtr query_ptr;
|
|
|
|
Context context;
|
2016-03-19 01:18:49 +00:00
|
|
|
|
2016-08-09 21:48:05 +00:00
|
|
|
/// Using while loading database.
|
2016-08-02 01:46:05 +00:00
|
|
|
ThreadPool * thread_pool = nullptr;
|
2016-08-09 21:48:05 +00:00
|
|
|
|
|
|
|
/// Skip safety threshold when loading tables.
|
|
|
|
bool has_force_restore_data_flag = false;
|
2011-08-18 20:33:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|