Added constraints description to MergeTree and related storages

This commit is contained in:
Gleb Novikov 2019-05-18 11:05:52 +03:00
parent 1f5715b985
commit ce93896608
7 changed files with 16 additions and 5 deletions

View File

@ -93,6 +93,7 @@ MergeTreeData::MergeTreeData(
const String & database_, const String & table_, const String & database_, const String & table_,
const String & full_path_, const ColumnsDescription & columns_, const String & full_path_, const ColumnsDescription & columns_,
const IndicesDescription & indices_, const IndicesDescription & indices_,
const ConstraintsDescription & constraints_,
Context & context_, Context & context_,
const String & date_column_name, const String & date_column_name,
const ASTPtr & partition_by_ast_, const ASTPtr & partition_by_ast_,
@ -121,6 +122,7 @@ MergeTreeData::MergeTreeData(
data_parts_by_state_and_info(data_parts_indexes.get<TagByStateAndInfo>()) data_parts_by_state_and_info(data_parts_indexes.get<TagByStateAndInfo>())
{ {
setPrimaryKeyIndicesAndColumns(order_by_ast_, primary_key_ast_, columns_, indices_); setPrimaryKeyIndicesAndColumns(order_by_ast_, primary_key_ast_, columns_, indices_);
setConstraints(constraints_);
/// NOTE: using the same columns list as is read when performing actual merges. /// NOTE: using the same columns list as is read when performing actual merges.
merging_params.check(getColumns().getAllPhysical()); merging_params.check(getColumns().getAllPhysical());

View File

@ -332,6 +332,7 @@ public:
const String & full_path_, const String & full_path_,
const ColumnsDescription & columns_, const ColumnsDescription & columns_,
const IndicesDescription & indices_, const IndicesDescription & indices_,
const ConstraintsDescription & constraints_,
Context & context_, Context & context_,
const String & date_column_name, const String & date_column_name,
const ASTPtr & partition_by_ast_, const ASTPtr & partition_by_ast_,

View File

@ -574,6 +574,7 @@ static StoragePtr create(const StorageFactory::Arguments & args)
ASTPtr sample_by_ast; ASTPtr sample_by_ast;
ASTPtr ttl_table_ast; ASTPtr ttl_table_ast;
IndicesDescription indices_description; IndicesDescription indices_description;
ConstraintsDescription constraints_description;
MergeTreeSettings storage_settings = args.context.getMergeTreeSettings(); MergeTreeSettings storage_settings = args.context.getMergeTreeSettings();
if (is_extended_storage_def) if (is_extended_storage_def)
@ -602,7 +603,10 @@ static StoragePtr create(const StorageFactory::Arguments & args)
indices_description.indices.push_back( indices_description.indices.push_back(
std::dynamic_pointer_cast<ASTIndexDeclaration>(index->clone())); std::dynamic_pointer_cast<ASTIndexDeclaration>(index->clone()));
if (args.query.columns_list && args.query.columns_list->constraints)
for (const auto & constraint : args.query.columns_list->constraints->children)
constraints_description.constraints.push_back(
std::dynamic_pointer_cast<ASTConstraintDeclaration>(constraint->clone()));
storage_settings.loadFromQuery(*args.storage_def); storage_settings.loadFromQuery(*args.storage_def);
} }
else else
@ -639,14 +643,14 @@ static StoragePtr create(const StorageFactory::Arguments & args)
if (replicated) if (replicated)
return StorageReplicatedMergeTree::create( return StorageReplicatedMergeTree::create(
zookeeper_path, replica_name, args.attach, args.data_path, args.database_name, args.table_name, zookeeper_path, replica_name, args.attach, args.data_path, args.database_name, args.table_name,
args.columns, indices_description, args.columns, indices_description, constraints_description,
args.context, date_column_name, partition_by_ast, order_by_ast, primary_key_ast, args.context, date_column_name, partition_by_ast, order_by_ast, primary_key_ast,
sample_by_ast, ttl_table_ast, merging_params, storage_settings, sample_by_ast, ttl_table_ast, merging_params, storage_settings,
args.has_force_restore_data_flag); args.has_force_restore_data_flag);
else else
return StorageMergeTree::create( return StorageMergeTree::create(
args.data_path, args.database_name, args.table_name, args.columns, indices_description, args.data_path, args.database_name, args.table_name, args.columns, indices_description,
args.attach, args.context, date_column_name, partition_by_ast, order_by_ast, constraints_description, args.attach, args.context, date_column_name, partition_by_ast, order_by_ast,
primary_key_ast, sample_by_ast, ttl_table_ast, merging_params, storage_settings, primary_key_ast, sample_by_ast, ttl_table_ast, merging_params, storage_settings,
args.has_force_restore_data_flag); args.has_force_restore_data_flag);
} }

View File

@ -53,6 +53,7 @@ StorageMergeTree::StorageMergeTree(
const String & table_name_, const String & table_name_,
const ColumnsDescription & columns_, const ColumnsDescription & columns_,
const IndicesDescription & indices_, const IndicesDescription & indices_,
const ConstraintsDescription & constraints_,
bool attach, bool attach,
Context & context_, Context & context_,
const String & date_column_name, const String & date_column_name,
@ -66,7 +67,7 @@ StorageMergeTree::StorageMergeTree(
bool has_force_restore_data_flag) bool has_force_restore_data_flag)
: MergeTreeData(database_name_, table_name_, : MergeTreeData(database_name_, table_name_,
path_ + escapeForFileName(table_name_) + '/', path_ + escapeForFileName(table_name_) + '/',
columns_, indices_, columns_, indices_, constraints_,
context_, date_column_name, partition_by_ast_, order_by_ast_, primary_key_ast_, context_, date_column_name, partition_by_ast_, order_by_ast_, primary_key_ast_,
sample_by_ast_, ttl_table_ast_, merging_params_, sample_by_ast_, ttl_table_ast_, merging_params_,
settings_, false, attach), settings_, false, attach),

View File

@ -139,6 +139,7 @@ protected:
const String & table_name_, const String & table_name_,
const ColumnsDescription & columns_, const ColumnsDescription & columns_,
const IndicesDescription & indices_, const IndicesDescription & indices_,
const ConstraintsDescription & constraints_,
bool attach, bool attach,
Context & context_, Context & context_,
const String & date_column_name, const String & date_column_name,

View File

@ -199,6 +199,7 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree(
const String & table_name_, const String & table_name_,
const ColumnsDescription & columns_, const ColumnsDescription & columns_,
const IndicesDescription & indices_, const IndicesDescription & indices_,
const ConstraintsDescription & constraints_,
Context & context_, Context & context_,
const String & date_column_name, const String & date_column_name,
const ASTPtr & partition_by_ast_, const ASTPtr & partition_by_ast_,
@ -211,7 +212,7 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree(
bool has_force_restore_data_flag) bool has_force_restore_data_flag)
: MergeTreeData(database_name_, table_name_, : MergeTreeData(database_name_, table_name_,
path_ + escapeForFileName(table_name_) + '/', path_ + escapeForFileName(table_name_) + '/',
columns_, indices_, columns_, indices_, constraints_,
context_, date_column_name, partition_by_ast_, order_by_ast_, primary_key_ast_, context_, date_column_name, partition_by_ast_, order_by_ast_, primary_key_ast_,
sample_by_ast_, ttl_table_ast_, merging_params_, sample_by_ast_, ttl_table_ast_, merging_params_,
settings_, true, attach, settings_, true, attach,

View File

@ -513,6 +513,7 @@ protected:
const String & path_, const String & database_name_, const String & name_, const String & path_, const String & database_name_, const String & name_,
const ColumnsDescription & columns_, const ColumnsDescription & columns_,
const IndicesDescription & indices_, const IndicesDescription & indices_,
const ConstraintsDescription & constraints_,
Context & context_, Context & context_,
const String & date_column_name, const String & date_column_name,
const ASTPtr & partition_by_ast_, const ASTPtr & partition_by_ast_,