Working set*Keys methods

This commit is contained in:
alesapin 2020-06-15 20:24:49 +03:00
parent 5fc41c7ecc
commit e667eb57b2
2 changed files with 20 additions and 18 deletions

View File

@ -118,7 +118,7 @@ const char * DELETE_ON_DESTROY_MARKER_PATH = "delete-on-destroy.txt";
MergeTreeData::MergeTreeData( MergeTreeData::MergeTreeData(
const StorageID & table_id_, const StorageID & table_id_,
const String & relative_data_path_, const String & relative_data_path_,
const StorageInMemoryMetadata & metadata_, StorageInMemoryMetadata metadata_,
Context & context_, Context & context_,
const String & date_column_name, const String & date_column_name,
const MergingParams & merging_params_, const MergingParams & merging_params_,
@ -142,28 +142,15 @@ MergeTreeData::MergeTreeData(
if (relative_data_path.empty()) if (relative_data_path.empty())
throw Exception("MergeTree storages require data path", ErrorCodes::INCORRECT_FILE_NAME); throw Exception("MergeTree storages require data path", ErrorCodes::INCORRECT_FILE_NAME);
setProperties(metadata_, attach);
const auto settings = getSettings();
/// NOTE: using the same columns list as is read when performing actual merges.
merging_params.check(getColumns().getAllPhysical());
if (metadata_.sampling_key.definition_ast != nullptr)
{
const auto & pk_sample_block = getPrimaryKey().sample_block;
if (!pk_sample_block.has(metadata_.sampling_key.column_names[0]) && !attach
&& !settings->compatibility_allow_sampling_expression_not_in_primary_key) /// This is for backward compatibility.
throw Exception("Sampling expression must be present in the primary key", ErrorCodes::BAD_ARGUMENTS);
}
MergeTreeDataFormatVersion min_format_version(0); MergeTreeDataFormatVersion min_format_version(0);
/// TODO(alesap) Move to register methods
if (!date_column_name.empty()) if (!date_column_name.empty())
{ {
try try
{ {
auto partition_by_ast = makeASTFunction("toYYYYMM", std::make_shared<ASTIdentifier>(date_column_name)); auto partition_by_ast = makeASTFunction("toYYYYMM", std::make_shared<ASTIdentifier>(date_column_name));
auto partition_key = KeyDescription::getKeyFromAST(partition_by_ast, getColumns(), global_context); metadata_.partition_key = KeyDescription::getKeyFromAST(partition_by_ast, metadata_.columns, global_context);
initPartitionKey(partition_key); initPartitionKey(metadata_.partition_key);
if (minmax_idx_date_column_pos == -1) if (minmax_idx_date_column_pos == -1)
throw Exception("Could not find Date column", ErrorCodes::BAD_TYPE_OF_FIELD); throw Exception("Could not find Date column", ErrorCodes::BAD_TYPE_OF_FIELD);
@ -182,6 +169,21 @@ MergeTreeData::MergeTreeData(
min_format_version = MERGE_TREE_DATA_MIN_FORMAT_VERSION_WITH_CUSTOM_PARTITIONING; min_format_version = MERGE_TREE_DATA_MIN_FORMAT_VERSION_WITH_CUSTOM_PARTITIONING;
} }
setProperties(metadata_, attach);
const auto settings = getSettings();
/// NOTE: using the same columns list as is read when performing actual merges.
merging_params.check(getColumns().getAllPhysical());
if (metadata_.sampling_key.definition_ast != nullptr)
{
const auto & pk_sample_block = getPrimaryKey().sample_block;
if (!pk_sample_block.has(metadata_.sampling_key.column_names[0]) && !attach
&& !settings->compatibility_allow_sampling_expression_not_in_primary_key) /// This is for backward compatibility.
throw Exception("Sampling expression must be present in the primary key", ErrorCodes::BAD_ARGUMENTS);
}
setTTLExpressions(metadata_); setTTLExpressions(metadata_);
/// format_file always contained on any data path /// format_file always contained on any data path

View File

@ -323,7 +323,7 @@ public:
/// attach - whether the existing table is attached or the new table is created. /// attach - whether the existing table is attached or the new table is created.
MergeTreeData(const StorageID & table_id_, MergeTreeData(const StorageID & table_id_,
const String & relative_data_path_, const String & relative_data_path_,
const StorageInMemoryMetadata & metadata_, StorageInMemoryMetadata metadata_,
Context & context_, Context & context_,
const String & date_column_name, const String & date_column_name,
const MergingParams & merging_params_, const MergingParams & merging_params_,