From 65629ef560a1eb50ee87b551f5570c1c24b25439 Mon Sep 17 00:00:00 2001 From: Andrey Mironov Date: Tue, 11 Nov 2014 19:29:21 +0300 Subject: [PATCH] Merge --- dbms/src/Storages/MergeTree/MergeTreeData.cpp | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/dbms/src/Storages/MergeTree/MergeTreeData.cpp b/dbms/src/Storages/MergeTree/MergeTreeData.cpp index 4cab03b3eb9..cf0bf3edd20 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeData.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeData.cpp @@ -45,23 +45,27 @@ MergeTreeData::MergeTreeData( log_name(log_name_), log(&Logger::get(log_name + " (Data)")) { /// Проверяем, что столбец с датой существует и имеет тип Date. - { - auto it = columns->begin(); - for (; it != columns->end(); ++it) + const auto check_date_exists = [this] (const NamesAndTypesList & columns) { + for (const auto & column : columns) { - if (it->name == date_column_name) + if (column.name == date_column_name) { - if (!typeid_cast(&*it->type)) + if (!typeid_cast(column.type.get())) throw Exception("Date column (" + date_column_name + ") for storage of MergeTree family must have type Date." - " Provided column of type " + it->type->getName() + "." - " You may have separate column with type " + it->type->getName() + ".", ErrorCodes::BAD_TYPE_OF_FIELD); - break; + " Provided column of type " + column.type->getName() + "." + " You may have separate column with type " + column.type->getName() + ".", ErrorCodes::BAD_TYPE_OF_FIELD); + return true; } } - if (it == columns->end()) - throw Exception("Date column (" + date_column_name + ") does not exist in table declaration.", ErrorCodes::NO_SUCH_COLUMN_IN_TABLE); - } + return false; + }; + + if (!check_date_exists(*columns) && !check_date_exists(materialized_columns)) + throw Exception{ + "Date column (" + date_column_name + ") does not exist in table declaration.", + ErrorCodes::NO_SUCH_COLUMN_IN_TABLE + }; /// создаём директорию, если её нет Poco::File(full_path).createDirectories(); @@ -75,9 +79,9 @@ MergeTreeData::MergeTreeData( sort_descr.push_back(SortColumnDescription(name, 1)); } - primary_expr = ExpressionAnalyzer(primary_expr_ast, context, *columns).getActions(false); + primary_expr = ExpressionAnalyzer(primary_expr_ast, context, getColumnsList()).getActions(false); - ExpressionActionsPtr projected_expr = ExpressionAnalyzer(primary_expr_ast, context, *columns).getActions(true); + ExpressionActionsPtr projected_expr = ExpressionAnalyzer(primary_expr_ast, context, getColumnsList()).getActions(true); primary_key_sample = projected_expr->getSampleBlock(); }