Implemented changing comment to a ReplicatedMergeTree table

This commit is contained in:
Vasily Nemkov 2022-05-21 15:59:14 +03:00
parent 128a0e15eb
commit c12f826d22
5 changed files with 61 additions and 3 deletions

View File

@ -73,6 +73,7 @@ ReplicatedMergeTreeTableMetadata::ReplicatedMergeTreeTableMetadata(const MergeTr
index_granularity_bytes = 0;
constraints = metadata_snapshot->getConstraints().toString();
comment = metadata_snapshot->comment;
}
void ReplicatedMergeTreeTableMetadata::write(WriteBuffer & out) const
@ -108,6 +109,9 @@ void ReplicatedMergeTreeTableMetadata::write(WriteBuffer & out) const
if (!constraints.empty())
out << "constraints: " << constraints << "\n";
if (!comment.empty())
out << "comment: " << quote << comment << "\n";
}
String ReplicatedMergeTreeTableMetadata::toString() const
@ -155,8 +159,18 @@ void ReplicatedMergeTreeTableMetadata::read(ReadBuffer & in)
else
index_granularity_bytes = 0;
if (checkString("constraints: ", in))
in >> constraints >> "\n";
String verb;
readStringUntilWhitespace(verb, in);
if (verb == "constraints:")
{
in >> " " >> constraints >> "\n";
readStringUntilWhitespace(verb, in);
}
if (verb == "comment:")
in >> " " >> quote >> comment >> "\n";
}
ReplicatedMergeTreeTableMetadata ReplicatedMergeTreeTableMetadata::parse(const String & s)
@ -350,6 +364,12 @@ ReplicatedMergeTreeTableMetadata::checkAndFindDiff(const ReplicatedMergeTreeTabl
diff.new_constraints = from_zk.constraints;
}
if (comment != from_zk.comment)
{
diff.comment_changed = true;
diff.comment = from_zk.comment;
}
return diff;
}

View File

@ -30,6 +30,7 @@ struct ReplicatedMergeTreeTableMetadata
String projections;
String constraints;
String ttl_table;
String comment;
UInt64 index_granularity_bytes;
ReplicatedMergeTreeTableMetadata() = default;
@ -61,10 +62,13 @@ struct ReplicatedMergeTreeTableMetadata
bool ttl_table_changed = false;
String new_ttl_table;
bool comment_changed = false;
String comment;
bool empty() const
{
return !sorting_key_changed && !sampling_expression_changed && !skip_indices_changed && !projections_changed
&& !ttl_table_changed && !constraints_changed;
&& !ttl_table_changed && !constraints_changed && !comment_changed;
}
};

View File

@ -1151,6 +1151,9 @@ void StorageReplicatedMergeTree::setTableStructure(
new_metadata.table_ttl = TTLTableDescription{};
}
}
if (metadata_diff.comment_changed)
new_metadata.comment = metadata_diff.comment;
}
/// Changes in columns may affect following metadata fields
@ -4776,6 +4779,11 @@ void StorageReplicatedMergeTree::alter(
future_metadata_in_zk.ttl_table = "";
}
if (future_metadata.comment != current_metadata->comment)
{
future_metadata_in_zk.comment = future_metadata.comment;
}
String new_indices_str = future_metadata.secondary_indices.toString();
if (new_indices_str != current_metadata->secondary_indices.toString())
future_metadata_in_zk.skip_indices = new_indices_str;

View File

@ -0,0 +1,3 @@
Comment text for test table
Some new more detailed text of comment

View File

@ -0,0 +1,23 @@
-- Validate that setting/removing and getting comments on ReplicatedMergeTree works
-- https://github.com/ClickHouse/ClickHouse/issues/36377
CREATE TABLE 02302_ReplicatedMergeTree_comment
(
key UInt64 COMMENT 'The PK'
)
ENGINE = ReplicatedMergeTree('/test/02302_ReplicatedMergeTree_comment/{database}/source', '1')
PARTITION BY key
ORDER BY tuple()
COMMENT 'Comment text for test table';
# Check that comment is present
SELECT comment FROM system.tables WHERE database = currentDatabase() AND name == '02302_ReplicatedMergeTree_comment';
# Change to a different value and check if it was changed
ALTER TABLE 02302_ReplicatedMergeTree_comment MODIFY COMMENT 'Some new more detailed text of comment';
SELECT comment FROM system.tables WHERE database = currentDatabase() AND name == '02302_ReplicatedMergeTree_comment';
# Remove the comment and check if it is empty now
ALTER TABLE 02302_ReplicatedMergeTree_comment MODIFY COMMENT '';
SELECT comment FROM system.tables WHERE database = currentDatabase() AND name == '02302_ReplicatedMergeTree_comment';