mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
make MergeTree work with comments
This commit is contained in:
parent
035049d1a8
commit
d9e6789f78
@ -477,4 +477,15 @@ void AlterCommands::validate(const IStorage & table, const Context & context)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AlterCommands::is_mutable() const
|
||||||
|
{
|
||||||
|
for (const auto & param : *this)
|
||||||
|
{
|
||||||
|
if (param.is_mutable())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@ public:
|
|||||||
void apply(ColumnsDescription & columns_description) const;
|
void apply(ColumnsDescription & columns_description) const;
|
||||||
|
|
||||||
void validate(const IStorage & table, const Context & context);
|
void validate(const IStorage & table, const Context & context);
|
||||||
|
bool is_mutable() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -908,7 +908,7 @@ void MergeTreeData::checkAlter(const AlterCommands & commands)
|
|||||||
|
|
||||||
for (const AlterCommand & command : commands)
|
for (const AlterCommand & command : commands)
|
||||||
{
|
{
|
||||||
if (command.type == AlterCommand::COMMENT_COLUMN)
|
if (!command.is_mutable())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,16 @@ void StorageMergeTree::alter(
|
|||||||
const String & table_name,
|
const String & table_name,
|
||||||
const Context & context)
|
const Context & context)
|
||||||
{
|
{
|
||||||
|
if (!params.is_mutable())
|
||||||
|
{
|
||||||
|
auto table_soft_lock = lockStructureForAlter(__PRETTY_FUNCTION__);
|
||||||
|
auto new_columns = getColumns();
|
||||||
|
params.apply(new_columns);
|
||||||
|
context.getDatabase(database_name)->alterTable(context, table_name, new_columns, {});
|
||||||
|
setColumns(std::move(new_columns));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/// NOTE: Here, as in ReplicatedMergeTree, you can do ALTER which does not block the writing of data for a long time.
|
/// NOTE: Here, as in ReplicatedMergeTree, you can do ALTER which does not block the writing of data for a long time.
|
||||||
auto merge_blocker = merger_mutator.actions_blocker.cancel();
|
auto merge_blocker = merger_mutator.actions_blocker.cancel();
|
||||||
|
|
||||||
|
@ -1,28 +1,38 @@
|
|||||||
CREATE TABLE test.check_query_comment_column ( first_column UInt8 DEFAULT 1 COMMENT \'first comment\', fourth_column UInt8 COMMENT \'fourth comment\', fifth_column UInt8, second_column UInt8 MATERIALIZED first_column COMMENT \'second comment\', third_column UInt8 ALIAS second_column COMMENT \'third comment\') ENGINE = TinyLog
|
CREATE TABLE test.check_query_comment_column ( first_column UInt8 DEFAULT 1 COMMENT \'comment 1\', fourth_column UInt8 COMMENT \'comment 4\', fifth_column UInt8, second_column UInt8 MATERIALIZED first_column COMMENT \'comment 2\', third_column UInt8 ALIAS second_column COMMENT \'comment 3\') ENGINE = TinyLog
|
||||||
┌─table──────────────────────┬─name──────────┬─comment────────┐
|
first_column UInt8 DEFAULT 1 comment 1
|
||||||
│ check_query_comment_column │ first_column │ first comment │
|
fourth_column UInt8 comment 4
|
||||||
│ check_query_comment_column │ fourth_column │ fourth comment │
|
fifth_column UInt8
|
||||||
│ check_query_comment_column │ fifth_column │ │
|
second_column UInt8 MATERIALIZED first_column comment 2
|
||||||
│ check_query_comment_column │ second_column │ second comment │
|
third_column UInt8 ALIAS second_column comment 3
|
||||||
│ check_query_comment_column │ third_column │ third comment │
|
┌─table──────────────────────┬─name──────────┬─comment───┐
|
||||||
└────────────────────────────┴───────────────┴────────────────┘
|
│ check_query_comment_column │ first_column │ comment 1 │
|
||||||
CREATE TABLE test.check_query_comment_column ( first_column UInt8 DEFAULT 1 COMMENT \'another first column\', fourth_column UInt8 COMMENT \'another fourth column\', fifth_column UInt8 COMMENT \'another fifth column\', second_column UInt8 MATERIALIZED first_column COMMENT \'another second column\', third_column UInt8 ALIAS second_column COMMENT \'another third column\') ENGINE = TinyLog
|
│ check_query_comment_column │ fourth_column │ comment 4 │
|
||||||
┌─table──────────────────────┬─name──────────┬─comment───────────────┐
|
│ check_query_comment_column │ fifth_column │ │
|
||||||
│ check_query_comment_column │ first_column │ another first column │
|
│ check_query_comment_column │ second_column │ comment 2 │
|
||||||
│ check_query_comment_column │ fourth_column │ another fourth column │
|
│ check_query_comment_column │ third_column │ comment 3 │
|
||||||
│ check_query_comment_column │ fifth_column │ another fifth column │
|
└────────────────────────────┴───────────────┴───────────┘
|
||||||
│ check_query_comment_column │ second_column │ another second column │
|
CREATE TABLE test.check_query_comment_column ( first_column UInt8 DEFAULT 1 COMMENT \'comment 1_1\', fourth_column UInt8 COMMENT \'comment 4_1\', fifth_column UInt8 COMMENT \'comment 5_1\', second_column UInt8 MATERIALIZED first_column COMMENT \'comment 2_1\', third_column UInt8 ALIAS second_column COMMENT \'comment 3_1\') ENGINE = TinyLog
|
||||||
│ check_query_comment_column │ third_column │ another third column │
|
┌─table──────────────────────┬─name──────────┬─comment─────┐
|
||||||
└────────────────────────────┴───────────────┴───────────────────────┘
|
│ check_query_comment_column │ first_column │ comment 1_2 │
|
||||||
CREATE TABLE test.check_query_comment_column ( first_column Date COMMENT \'first comment\', second_column UInt8 COMMENT \'second comment\', third_column UInt8 COMMENT \'third comment\') ENGINE = MergeTree(first_column, (second_column, second_column), 8192)
|
│ check_query_comment_column │ fourth_column │ comment 4_2 │
|
||||||
┌─table──────────────────────┬─name──────────┬─comment────────┐
|
│ check_query_comment_column │ fifth_column │ comment 5_2 │
|
||||||
│ check_query_comment_column │ first_column │ first comment │
|
│ check_query_comment_column │ second_column │ comment 2_2 │
|
||||||
│ check_query_comment_column │ second_column │ second comment │
|
│ check_query_comment_column │ third_column │ comment 3_2 │
|
||||||
│ check_query_comment_column │ third_column │ third comment │
|
└────────────────────────────┴───────────────┴─────────────┘
|
||||||
└────────────────────────────┴───────────────┴────────────────┘
|
CREATE TABLE test.check_query_comment_column ( first_column UInt8 DEFAULT 1 COMMENT \'comment 1_2\', fourth_column UInt8 COMMENT \'comment 4_2\', fifth_column UInt8 COMMENT \'comment 5_2\', second_column UInt8 MATERIALIZED first_column COMMENT \'comment 2_2\', third_column UInt8 ALIAS second_column COMMENT \'comment 3_2\') ENGINE = TinyLog
|
||||||
CREATE TABLE test.check_query_comment_column ( first_column Date COMMENT \'another first comment\', second_column UInt8 COMMENT \'another second comment\', third_column UInt8 COMMENT \'another third comment\') ENGINE = MergeTree(first_column, (second_column, second_column), 8192)
|
CREATE TABLE test.check_query_comment_column ( first_column UInt8 COMMENT \'comment 1\', second_column UInt8 COMMENT \'comment 2\', third_column UInt8 COMMENT \'comment 3\') ENGINE = MergeTree() PARTITION BY second_column ORDER BY first_column SAMPLE BY first_column SETTINGS index_granularity = 8192
|
||||||
┌─table──────────────────────┬─name──────────┬─comment────────────────┐
|
first_column UInt8 comment 1
|
||||||
│ check_query_comment_column │ first_column │ another first comment │
|
second_column UInt8 comment 2
|
||||||
│ check_query_comment_column │ second_column │ another second comment │
|
third_column UInt8 comment 3
|
||||||
│ check_query_comment_column │ third_column │ another third comment │
|
┌─table──────────────────────┬─name──────────┬─comment───┐
|
||||||
└────────────────────────────┴───────────────┴────────────────────────┘
|
│ check_query_comment_column │ first_column │ comment 1 │
|
||||||
|
│ check_query_comment_column │ second_column │ comment 2 │
|
||||||
|
│ check_query_comment_column │ third_column │ comment 3 │
|
||||||
|
└────────────────────────────┴───────────────┴───────────┘
|
||||||
|
CREATE TABLE test.check_query_comment_column ( first_column UInt8 COMMENT \'comment 1_2\', second_column UInt8 COMMENT \'comment 2_2\', third_column UInt8 COMMENT \'comment 3_2\') ENGINE = MergeTree() PARTITION BY second_column ORDER BY first_column SAMPLE BY first_column SETTINGS index_granularity = 8192
|
||||||
|
CREATE TABLE test.check_query_comment_column ( first_column UInt8 COMMENT \'comment 1_3\', second_column UInt8 COMMENT \'comment 2_3\', third_column UInt8 COMMENT \'comment 3_3\') ENGINE = MergeTree() PARTITION BY second_column ORDER BY first_column SAMPLE BY first_column SETTINGS index_granularity = 8192
|
||||||
|
┌─table──────────────────────┬─name──────────┬─comment─────┐
|
||||||
|
│ check_query_comment_column │ first_column │ comment 1_3 │
|
||||||
|
│ check_query_comment_column │ second_column │ comment 2_3 │
|
||||||
|
│ check_query_comment_column │ third_column │ comment 3_3 │
|
||||||
|
└────────────────────────────┴───────────────┴─────────────┘
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
CREATE DATABASE IF NOT EXISTS test;
|
CREATE DATABASE IF NOT EXISTS test;
|
||||||
DROP TABLE IF EXISTS test.check_query_comment_column;
|
DROP TABLE IF EXISTS test.check_query_comment_column;
|
||||||
|
|
||||||
|
-- Check COMMENT COLUMN and MODIFY COLUMN statements with simple engine
|
||||||
CREATE TABLE test.check_query_comment_column
|
CREATE TABLE test.check_query_comment_column
|
||||||
(
|
(
|
||||||
first_column UInt8 DEFAULT 1 COMMENT 'first comment',
|
first_column UInt8 DEFAULT 1 COMMENT 'comment 1',
|
||||||
second_column UInt8 MATERIALIZED first_column COMMENT 'second comment',
|
second_column UInt8 MATERIALIZED first_column COMMENT 'comment 2',
|
||||||
third_column UInt8 ALIAS second_column COMMENT 'third comment',
|
third_column UInt8 ALIAS second_column COMMENT 'comment 3',
|
||||||
fourth_column UInt8 COMMENT 'fourth comment',
|
fourth_column UInt8 COMMENT 'comment 4',
|
||||||
fifth_column UInt8
|
fifth_column UInt8
|
||||||
) ENGINE = TinyLog;
|
) ENGINE = TinyLog;
|
||||||
|
|
||||||
SHOW CREATE TABLE test.check_query_comment_column;
|
SHOW CREATE TABLE test.check_query_comment_column;
|
||||||
|
DESCRIBE TABLE test.check_query_comment_column;
|
||||||
|
|
||||||
SELECT table, name, comment
|
SELECT table, name, comment
|
||||||
FROM system.columns
|
FROM system.columns
|
||||||
@ -18,30 +20,42 @@ WHERE table = 'check_query_comment_column' AND database = 'test'
|
|||||||
FORMAT PrettyCompactNoEscapes;
|
FORMAT PrettyCompactNoEscapes;
|
||||||
|
|
||||||
ALTER TABLE test.check_query_comment_column
|
ALTER TABLE test.check_query_comment_column
|
||||||
COMMENT COLUMN first_column 'another first column',
|
COMMENT COLUMN first_column 'comment 1_1',
|
||||||
COMMENT COLUMN second_column 'another second column',
|
COMMENT COLUMN second_column 'comment 2_1',
|
||||||
COMMENT COLUMN third_column 'another third column',
|
COMMENT COLUMN third_column 'comment 3_1',
|
||||||
COMMENT COLUMN fourth_column 'another fourth column',
|
COMMENT COLUMN fourth_column 'comment 4_1',
|
||||||
COMMENT COLUMN fifth_column 'another fifth column';
|
COMMENT COLUMN fifth_column 'comment 5_1';
|
||||||
|
|
||||||
SHOW CREATE TABLE test.check_query_comment_column;
|
SHOW CREATE TABLE test.check_query_comment_column;
|
||||||
|
|
||||||
|
ALTER TABLE test.check_query_comment_column
|
||||||
|
MODIFY COLUMN first_column COMMENT 'comment 1_2',
|
||||||
|
MODIFY COLUMN second_column COMMENT 'comment 2_2',
|
||||||
|
MODIFY COLUMN third_column COMMENT 'comment 3_2',
|
||||||
|
MODIFY COLUMN fourth_column COMMENT 'comment 4_2',
|
||||||
|
MODIFY COLUMN fifth_column COMMENT 'comment 5_2';
|
||||||
|
|
||||||
SELECT table, name, comment
|
SELECT table, name, comment
|
||||||
FROM system.columns
|
FROM system.columns
|
||||||
WHERE table = 'check_query_comment_column' AND database = 'test'
|
WHERE table = 'check_query_comment_column' AND database = 'test'
|
||||||
FORMAT PrettyCompactNoEscapes;
|
FORMAT PrettyCompactNoEscapes;
|
||||||
|
|
||||||
|
SHOW CREATE TABLE test.check_query_comment_column;
|
||||||
DROP TABLE IF EXISTS test.check_query_comment_column;
|
DROP TABLE IF EXISTS test.check_query_comment_column;
|
||||||
|
|
||||||
|
-- Check `ALTER TABLE table_name COMMENT COLUMN 'comment'` statement with MergeTree engine
|
||||||
CREATE TABLE test.check_query_comment_column
|
CREATE TABLE test.check_query_comment_column
|
||||||
(
|
(
|
||||||
first_column Date COMMENT 'first comment',
|
first_column UInt8 COMMENT 'comment 1',
|
||||||
second_column UInt8 COMMENT 'second comment',
|
second_column UInt8 COMMENT 'comment 2',
|
||||||
third_column UInt8 COMMENT 'third comment'
|
third_column UInt8 COMMENT 'comment 3'
|
||||||
) ENGINE = MergeTree(first_column, (second_column, second_column), 8192);
|
) ENGINE = MergeTree()
|
||||||
|
ORDER BY first_column
|
||||||
|
PARTITION BY second_column
|
||||||
|
SAMPLE BY first_column;
|
||||||
|
|
||||||
SHOW CREATE TABLE test.check_query_comment_column;
|
SHOW CREATE TABLE test.check_query_comment_column;
|
||||||
|
DESCRIBE TABLE test.check_query_comment_column;
|
||||||
|
|
||||||
SELECT table, name, comment
|
SELECT table, name, comment
|
||||||
FROM system.columns
|
FROM system.columns
|
||||||
@ -49,25 +63,23 @@ WHERE table = 'check_query_comment_column' AND database = 'test'
|
|||||||
FORMAT PrettyCompactNoEscapes;
|
FORMAT PrettyCompactNoEscapes;
|
||||||
|
|
||||||
ALTER TABLE test.check_query_comment_column
|
ALTER TABLE test.check_query_comment_column
|
||||||
COMMENT COLUMN first_column 'another first comment',
|
COMMENT COLUMN first_column 'comment 1_2',
|
||||||
COMMENT COLUMN second_column 'another second comment',
|
COMMENT COLUMN second_column 'comment 2_2',
|
||||||
COMMENT COLUMN third_column 'another third comment';
|
COMMENT COLUMN third_column 'comment 3_2';
|
||||||
|
|
||||||
SHOW CREATE TABLE test.check_query_comment_column;
|
SHOW CREATE TABLE test.check_query_comment_column;
|
||||||
|
|
||||||
SELECT table, name, comment
|
ALTER TABLE test.check_query_comment_column
|
||||||
FROM system.columns
|
MODIFY COLUMN first_column COMMENT 'comment 1_3',
|
||||||
WHERE table = 'check_query_comment_column' and database = 'test'
|
MODIFY COLUMN second_column COMMENT 'comment 2_3',
|
||||||
FORMAT PrettyCompactNoEscapes;
|
MODIFY COLUMN third_column COMMENT 'comment 3_3';
|
||||||
|
|
||||||
DROP TABLE IF test.check_query_comment_column;
|
SHOW CREATE TABLE test.check_query_comment_column;
|
||||||
|
|
||||||
CREATE TABLE test.check_query_comment_column
|
ALTER TABLE test.check_query_comment_column
|
||||||
(
|
MODIFY COLUMN first_column DEFAULT 1 COMMENT 'comment 1_3',
|
||||||
first_column UInt8 COMMENT 'first comment'
|
MODIFY COLUMN second_column COMMENT 'comment 2_3', -- We can't change default value of partition key.
|
||||||
) ENGINE = TinyLog;
|
MODIFY COLUMN third_column DEFAULT 1 COMMENT 'comment 3_3';
|
||||||
|
|
||||||
ALTER TABLE test.check_query_comment_column MODIFY COLUMN first_column COMMENT 'another comment';
|
|
||||||
|
|
||||||
SELECT table, name, comment
|
SELECT table, name, comment
|
||||||
FROM system.columns
|
FROM system.columns
|
||||||
@ -75,3 +87,5 @@ WHERE table = 'check_query_comment_column' and database = 'test'
|
|||||||
FORMAT PrettyCompactNoEscapes;
|
FORMAT PrettyCompactNoEscapes;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS test.check_query_comment_column;
|
DROP TABLE IF EXISTS test.check_query_comment_column;
|
||||||
|
|
||||||
|
-- TODO: add here tests with ReplicatedMergeTree
|
||||||
|
Loading…
Reference in New Issue
Block a user