Move partition key initialization into registerMergeTree

This commit is contained in:
alesapin 2020-06-19 18:14:08 +03:00
parent ad443d9d0c
commit 3c47faa9da
5 changed files with 10 additions and 9 deletions

View File

@ -138,7 +138,9 @@ public:
public:
StorageInMemoryMetadata getInMemoryMetadata() const { return *metadata.get(); }
StorageMetadataPtr getInMemoryMetadataPtr() const { return metadata.get(); }
void setInMemoryMetadata(const StorageInMemoryMetadata & metadata_)
{
metadata.set(std::make_unique<StorageInMemoryMetadata>(metadata_));

View File

@ -118,7 +118,7 @@ const char * DELETE_ON_DESTROY_MARKER_PATH = "delete-on-destroy.txt";
MergeTreeData::MergeTreeData(
const StorageID & table_id_,
const String & relative_data_path_,
StorageInMemoryMetadata metadata_,
const StorageInMemoryMetadata & metadata_,
Context & context_,
const String & date_column_name,
const MergingParams & merging_params_,
@ -143,15 +143,11 @@ MergeTreeData::MergeTreeData(
throw Exception("MergeTree storages require data path", ErrorCodes::INCORRECT_FILE_NAME);
MergeTreeDataFormatVersion min_format_version(0);
/// TODO(alesap) Move to register methods
if (!date_column_name.empty())
{
try
{
auto partition_by_ast = makeASTFunction("toYYYYMM", std::make_shared<ASTIdentifier>(date_column_name));
metadata_.partition_key = KeyDescription::getKeyFromAST(partition_by_ast, metadata_.columns, global_context);
initPartitionKey(metadata_.partition_key);
if (minmax_idx_date_column_pos == -1)
throw Exception("Could not find Date column", ErrorCodes::BAD_TYPE_OF_FIELD);
}

View File

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

View File

@ -570,6 +570,12 @@ static StoragePtr create(const StorageFactory::Arguments & args)
throw Exception(
"Date column name must be an unquoted string" + getMergeTreeVerboseHelp(is_extended_storage_def),
ErrorCodes::BAD_ARGUMENTS);
auto partition_by_ast = makeASTFunction("toYYYYMM", std::make_shared<ASTIdentifier>(date_column_name));
metadata.partition_key = KeyDescription::getKeyFromAST(partition_by_ast, metadata.columns, args.context);
++arg_num;
/// If there is an expression for sampling

View File

@ -14,9 +14,6 @@
namespace DB
{
/// Structure represent table metadata stored in memory.
/// Only one storage engine support all fields -- MergeTree.
/// Complete table AST can be recreated from this struct.
struct StorageInMemoryMetadata
{
/// Columns of table with their names, types,