fix metadata editing

This commit is contained in:
Nikita Vasilev 2019-01-16 22:47:21 +03:00
parent 62dde8c327
commit f8fa36c6bd
2 changed files with 14 additions and 4 deletions

View File

@ -447,7 +447,10 @@ void StorageReplicatedMergeTree::setTableStructure(ColumnsDescription new_column
if (metadata_diff.skip_indices_changed)
{
ParserIndexDeclaration parser;
new_indices_ast = parseQuery(parser, metadata_diff.new_skip_indices, 0);
if (metadata_diff.new_skip_indices.empty())
new_indices_ast.reset();
else
new_indices_ast = parseQuery(parser, metadata_diff.new_skip_indices, 0);
}
storage_modifier = [&](IAST & ast)
@ -464,7 +467,10 @@ void StorageReplicatedMergeTree::setTableStructure(ColumnsDescription new_column
storage_ast.set(storage_ast.order_by, new_order_by_ast);
storage_ast.set(storage_ast.indexes, new_indices_ast);
if (new_indices_ast)
storage_ast.set(storage_ast.indexes, new_indices_ast);
else
storage_ast.indexes = nullptr;
};
}
@ -3082,6 +3088,10 @@ void StorageReplicatedMergeTree::alter(const AlterCommands & params,
ASTPtr new_primary_key_ast = data.primary_key_ast;
ASTPtr new_indexes_ast = data.skip_indexes_ast;
params.apply(new_columns, new_order_by_ast, new_primary_key_ast, new_indexes_ast);
if (new_indexes_ast && new_indexes_ast->children.empty())
{
new_indexes_ast.reset();
}
String new_columns_str = new_columns.toString();
if (new_columns_str != data.getColumns().toString())
@ -3092,7 +3102,7 @@ void StorageReplicatedMergeTree::alter(const AlterCommands & params,
new_metadata.sorting_key = serializeAST(*MergeTreeData::extractKeyExpressionList(new_order_by_ast));
if (new_indexes_ast.get() != data.skip_indexes_ast.get())
{
if (new_indexes_ast && !new_indexes_ast->children.empty())
if (new_indexes_ast)
new_metadata.skip_indexes = serializeAST(*new_indexes_ast.get());
else
new_metadata.skip_indexes = {};

View File

@ -25,4 +25,4 @@ CREATE TABLE test.minmax_idx ( u64 UInt64, i32 Int32) ENGINE = MergeTree() ORDE
1 2
CREATE TABLE test.minmax_idx2 ( u64 UInt64, i32 Int32) ENGINE = MergeTree() ORDER BY u64 SETTINGS index_granularity = 8192
1 2
1 2
1 2