Fix version column in replicated version collapsing merge tree (#12121)

This commit is contained in:
alesapin 2020-07-04 10:35:17 +03:00 committed by GitHub
parent 89034ed565
commit 8dc204350f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 6 deletions

View File

@ -40,13 +40,10 @@ ReplicatedMergeTreeTableMetadata::ReplicatedMergeTreeTableMetadata(const MergeTr
/// So rules in zookeeper metadata is following: /// So rules in zookeeper metadata is following:
/// - When we have only ORDER BY, than store it in "primary key:" row of /metadata /// - When we have only ORDER BY, than store it in "primary key:" row of /metadata
/// - When we have both, than store PRIMARY KEY in "primary key:" row and ORDER BY in "sorting key:" row of /metadata /// - When we have both, than store PRIMARY KEY in "primary key:" row and ORDER BY in "sorting key:" row of /metadata
if (!metadata_snapshot->isPrimaryKeyDefined())
primary_key = formattedAST(metadata_snapshot->getSortingKey().expression_list_ast);
else
{
primary_key = formattedAST(metadata_snapshot->getPrimaryKey().expression_list_ast); primary_key = formattedAST(metadata_snapshot->getPrimaryKey().expression_list_ast);
if (metadata_snapshot->isPrimaryKeyDefined())
sorting_key = formattedAST(metadata_snapshot->getSortingKey().expression_list_ast); sorting_key = formattedAST(metadata_snapshot->getSortingKey().expression_list_ast);
}
data_format_version = data.format_version; data_format_version = data.format_version;

View File

@ -0,0 +1,3 @@
metadata format version: 1\ndate column: \nsampling expression: \nindex granularity: 8192\nmode: 7\nsign column: sign\nprimary key: key1, key2\ndata format version: 1\npartition key: d\ngranularity bytes: 10485760\n
1
1

View File

@ -0,0 +1,26 @@
DROP TABLE IF EXISTS versioned_collapsing_table;
CREATE TABLE versioned_collapsing_table(
d Date,
key1 UInt64,
key2 UInt32,
value String,
sign Int8,
version UInt16
)
ENGINE = ReplicatedVersionedCollapsingMergeTree('/clickhouse/versioned_collapsing_table', '1', sign, version)
PARTITION BY d
ORDER BY (key1, key2);
INSERT INTO versioned_collapsing_table VALUES (toDate('2019-10-10'), 1, 1, 'Hello', -1, 1);
SELECT value FROM system.zookeeper WHERE path = '/clickhouse/versioned_collapsing_table' and name = 'metadata';
SELECT COUNT() FROM versioned_collapsing_table;
DETACH TABLE versioned_collapsing_table;
ATTACH TABLE versioned_collapsing_table;
SELECT COUNT() FROM versioned_collapsing_table;
DROP TABLE IF EXISTS versioned_collapsing_table;