Skip to content

Commit

Permalink
Added check for constants in primary key [#METR-2944].
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-milovidov committed Jun 21, 2016
1 parent a50ad89 commit b8ca97a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions dbms/src/Storages/MergeTree/MergeTreeData.cpp
Expand Up @@ -77,7 +77,7 @@ MergeTreeData::MergeTreeData(

merging_params.check(*columns);

/// создаём директорию, если её нет
/// Creating directories, if not exist.
Poco::File(full_path).createDirectories();
Poco::File(full_path + "detached").createDirectory();

Expand All @@ -90,7 +90,7 @@ MergeTreeData::MergeTreeData(

void MergeTreeData::initPrimaryKey()
{
/// инициализируем описание сортировки
/// Initialize description of sorting.
sort_descr.clear();
sort_descr.reserve(primary_expr_ast->children.size());
for (const ASTPtr & ast : primary_expr_ast->children)
Expand All @@ -105,6 +105,16 @@ void MergeTreeData::initPrimaryKey()
primary_key_sample = projected_expr->getSampleBlock();

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);
for (size_t i = 0; i < primary_key_size; ++i)
primary_key_data_types[i] = primary_key_sample.unsafeGetByPosition(i).type;
Expand Down

0 comments on commit b8ca97a

Please sign in to comment.