Added check for constants in primary key [#METR-2944].

This commit is contained in:
Alexey Milovidov 2016-06-21 20:06:12 +03:00
parent a50ad899a1
commit b8ca97a891

View File

@ -77,7 +77,7 @@ MergeTreeData::MergeTreeData(
merging_params.check(*columns); merging_params.check(*columns);
/// создаём директорию, если её нет /// Creating directories, if not exist.
Poco::File(full_path).createDirectories(); Poco::File(full_path).createDirectories();
Poco::File(full_path + "detached").createDirectory(); Poco::File(full_path + "detached").createDirectory();
@ -90,7 +90,7 @@ MergeTreeData::MergeTreeData(
void MergeTreeData::initPrimaryKey() void MergeTreeData::initPrimaryKey()
{ {
/// инициализируем описание сортировки /// Initialize description of sorting.
sort_descr.clear(); sort_descr.clear();
sort_descr.reserve(primary_expr_ast->children.size()); sort_descr.reserve(primary_expr_ast->children.size());
for (const ASTPtr & ast : primary_expr_ast->children) for (const ASTPtr & ast : primary_expr_ast->children)
@ -105,6 +105,16 @@ void MergeTreeData::initPrimaryKey()
primary_key_sample = projected_expr->getSampleBlock(); primary_key_sample = projected_expr->getSampleBlock();
size_t primary_key_size = primary_key_sample.columns(); size_t primary_key_size = primary_key_sample.columns();
/// Primary key cannot contain constants. It is meaningless.
/// (And also couldn't work because primary key is serialized with method of IDataType that doesn't support constants).
for (size_t i = 0; i < primary_key_size; ++i)
{
const ColumnPtr & column = primary_key_sample.unsafeGetByPosition(i).column;
if (column && column->isConst())
throw Exception("Primary key cannot contain constants", ErrorCodes::ILLEGAL_COLUMN);
}
primary_key_data_types.resize(primary_key_size); primary_key_data_types.resize(primary_key_size);
for (size_t i = 0; i < primary_key_size; ++i) for (size_t i = 0; i < primary_key_size; ++i)
primary_key_data_types[i] = primary_key_sample.unsafeGetByPosition(i).type; primary_key_data_types[i] = primary_key_sample.unsafeGetByPosition(i).type;