2011-08-18 20:33:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/IInterpreter.h>
|
|
|
|
#include <Storages/ColumnDefault.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.
|
|
|
|
static ASTPtr formatColumns(const NamesAndTypesList & columns);
|
|
|
|
static ASTPtr formatColumns(
|
|
|
|
NamesAndTypesList columns,
|
|
|
|
const NamesAndTypesList & materialized_columns,
|
|
|
|
const NamesAndTypesList & alias_columns,
|
|
|
|
const ColumnDefaults & column_defaults);
|
|
|
|
|
|
|
|
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_;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ColumnsInfo
|
|
|
|
{
|
|
|
|
NamesAndTypesListPtr columns = std::make_shared<NamesAndTypesList>();
|
|
|
|
NamesAndTypesList materialized_columns;
|
|
|
|
NamesAndTypesList alias_columns;
|
|
|
|
ColumnDefaults column_defaults;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Obtain information about columns, their types and default values, for case when columns in CREATE query is specified explicitly.
|
2017-09-17 18:49:43 +00:00
|
|
|
static ColumnsInfo getColumnsInfo(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.
|
|
|
|
ColumnsInfo 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;
|
2014-09-25 15:01:09 +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;
|
2011-08-18 20:33:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|