From 763669f3dcbc75d2350cef61780eac898ba668b1 Mon Sep 17 00:00:00 2001 From: alesapin Date: Fri, 3 Apr 2020 12:53:20 +0300 Subject: [PATCH] Better test and correct access rights --- dbms/Access/AccessFlags.h | 12 ++++- dbms/Access/AccessType.h | 2 + dbms/Interpreters/InterpreterAlterQuery.cpp | 1 + ...13_alter_rename_column_zookeeper.reference | 2 + .../01213_alter_rename_column_zookeeper.sh | 52 +++++++++++++++++++ .../01213_alter_rename_column_zookeeper.sql | 37 ------------- 6 files changed, 68 insertions(+), 38 deletions(-) create mode 100755 tests/queries/0_stateless/01213_alter_rename_column_zookeeper.sh delete mode 100644 tests/queries/0_stateless/01213_alter_rename_column_zookeeper.sql diff --git a/dbms/Access/AccessFlags.h b/dbms/Access/AccessFlags.h index f15e7d1e274..2c5307bbd1a 100644 --- a/dbms/Access/AccessFlags.h +++ b/dbms/Access/AccessFlags.h @@ -274,7 +274,17 @@ private: comment_column->aliases.push_back("ALTER COMMENT COLUMN"); auto clear_column = std::make_unique("CLEAR COLUMN", next_flag++, COLUMN); clear_column->aliases.push_back("ALTER CLEAR COLUMN"); - auto alter_column = std::make_unique("ALTER COLUMN", std::move(add_column), std::move(modify_column), std::move(drop_column), std::move(comment_column), std::move(clear_column)); + auto rename_column = std::make_unique("RENAME COLUMN", next_flag++, COLUMN); + rename_column->aliases.push_back("ALTER RENAME COLUMN"); + + auto alter_column = std::make_unique( + "ALTER COLUMN", + std::move(add_column), + std::move(modify_column), + std::move(drop_column), + std::move(comment_column), + std::move(clear_column), + std::move(rename_column)); auto alter_order_by = std::make_unique("ALTER ORDER BY", next_flag++, TABLE); alter_order_by->aliases.push_back("MODIFY ORDER BY"); diff --git a/dbms/Access/AccessType.h b/dbms/Access/AccessType.h index 27892076d59..df8839f64ce 100644 --- a/dbms/Access/AccessType.h +++ b/dbms/Access/AccessType.h @@ -30,6 +30,7 @@ enum class AccessType MODIFY_COLUMN, COMMENT_COLUMN, CLEAR_COLUMN, + RENAME_COLUMN, ALTER_COLUMN, /// allow to execute ALTER {ADD|DROP|MODIFY...} COLUMN ALTER_ORDER_BY, @@ -197,6 +198,7 @@ namespace impl ACCESS_TYPE_TO_KEYWORD_CASE(MODIFY_COLUMN); ACCESS_TYPE_TO_KEYWORD_CASE(COMMENT_COLUMN); ACCESS_TYPE_TO_KEYWORD_CASE(CLEAR_COLUMN); + ACCESS_TYPE_TO_KEYWORD_CASE(RENAME_COLUMN); ACCESS_TYPE_TO_KEYWORD_CASE(ALTER_COLUMN); ACCESS_TYPE_TO_KEYWORD_CASE(ALTER_ORDER_BY); diff --git a/dbms/Interpreters/InterpreterAlterQuery.cpp b/dbms/Interpreters/InterpreterAlterQuery.cpp index ff2afeab8ef..7411537601f 100644 --- a/dbms/Interpreters/InterpreterAlterQuery.cpp +++ b/dbms/Interpreters/InterpreterAlterQuery.cpp @@ -282,6 +282,7 @@ AccessRightsElements InterpreterAlterQuery::getRequiredAccessForCommand(const AS } case ASTAlterCommand::RENAME_COLUMN: { + required_access.emplace_back(AccessType::RENAME_COLUMN, database, table, column_name()); break; } case ASTAlterCommand::NO_TYPE: break; diff --git a/tests/queries/0_stateless/01213_alter_rename_column_zookeeper.reference b/tests/queries/0_stateless/01213_alter_rename_column_zookeeper.reference index 36be6811171..a2c0e0d7d77 100644 --- a/tests/queries/0_stateless/01213_alter_rename_column_zookeeper.reference +++ b/tests/queries/0_stateless/01213_alter_rename_column_zookeeper.reference @@ -4,3 +4,5 @@ CREATE TABLE default.table_for_rename_replicated (`date` Date, `key` UInt64, `re 1 date key renamed_value1 value2 value3 2019-10-02 1 1 1 1 +date key renamed_value1 value2 value3 +2019-10-02 1 1 1 1 diff --git a/tests/queries/0_stateless/01213_alter_rename_column_zookeeper.sh b/tests/queries/0_stateless/01213_alter_rename_column_zookeeper.sh new file mode 100755 index 00000000000..b7a4738d417 --- /dev/null +++ b/tests/queries/0_stateless/01213_alter_rename_column_zookeeper.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +. $CURDIR/../shell_config.sh + +$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS table_for_rename_replicated" + +$CLICKHOUSE_CLIENT -n --query " +CREATE TABLE table_for_rename_replicated +( + date Date, + key UInt64, + value1 String, + value2 String, + value3 String +) +ENGINE = ReplicatedMergeTree('/clickhouse/tables/table_for_rename_replicated', '1') +PARTITION BY date +ORDER BY key; +" + + +$CLICKHOUSE_CLIENT --query "INSERT INTO table_for_rename_replicated SELECT toDate('2019-10-01') + number % 3, number, toString(number), toString(number), toString(number) from numbers(9);" + +$CLICKHOUSE_CLIENT --query "SELECT value1 FROM table_for_rename_replicated WHERE key = 1;" + +$CLICKHOUSE_CLIENT --query "SYSTEM STOP MERGES;" + +$CLICKHOUSE_CLIENT --query "SHOW CREATE TABLE table_for_rename_replicated;" + +$CLICKHOUSE_CLIENT --query "ALTER TABLE table_for_rename_replicated RENAME COLUMN value1 to renamed_value1" --replication_alter_partitions_sync=0 + + +while [[ -z $($CLICKHOUSE_CLIENT --query "SELECT name FROM system.columns WHERE name = 'renamed_value1' and table = 'table_for_rename_replicated'" 2>/dev/null) ]]; do + sleep 0.5 +done + +# RENAME on fly works + +$CLICKHOUSE_CLIENT --query "SHOW CREATE TABLE table_for_rename_replicated;" + +$CLICKHOUSE_CLIENT --query "SELECT renamed_value1 FROM table_for_rename_replicated WHERE key = 1;" + +$CLICKHOUSE_CLIENT --query "SELECT * FROM table_for_rename_replicated WHERE key = 1 FORMAT TSVWithNames;" + +$CLICKHOUSE_CLIENT --query "SYSTEM START MERGES;" + +$CLICKHOUSE_CLIENT --query "SYSTEM SYNC REPLICA table_for_rename_replicated;" + +$CLICKHOUSE_CLIENT --query "SELECT * FROM table_for_rename_replicated WHERE key = 1 FORMAT TSVWithNames;" + +$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS table_for_rename_replicated;" diff --git a/tests/queries/0_stateless/01213_alter_rename_column_zookeeper.sql b/tests/queries/0_stateless/01213_alter_rename_column_zookeeper.sql deleted file mode 100644 index daf25f7ba4b..00000000000 --- a/tests/queries/0_stateless/01213_alter_rename_column_zookeeper.sql +++ /dev/null @@ -1,37 +0,0 @@ -DROP TABLE IF EXISTS table_for_rename_replicated; - - -CREATE TABLE table_for_rename_replicated -( - date Date, - key UInt64, - value1 String, - value2 String, - value3 String -) -ENGINE = ReplicatedMergeTree('/clickhouse/tables/table_for_rename_replicated', '1') -PARTITION BY date -ORDER BY key; - - -INSERT INTO table_for_rename_replicated SELECT toDate('2019-10-01') + number % 3, number, toString(number), toString(number), toString(number) from numbers(9); - -SELECT value1 FROM table_for_rename_replicated WHERE key = 1; - -SYSTEM STOP MERGES; - -SHOW CREATE TABLE table_for_rename_replicated; - -ALTER TABLE table_for_rename_replicated RENAME COLUMN value1 to renamed_value1 SETTINGS replication_alter_partitions_sync = 0; - -SELECT sleep(2) FORMAT Null; - -SHOW CREATE TABLE table_for_rename_replicated; - -SELECT renamed_value1 FROM table_for_rename_replicated WHERE key = 1; - -SELECT * FROM table_for_rename_replicated WHERE key = 1 FORMAT TSVWithNames; - -SYSTEM START MERGES; - -DROP TABLE IF EXISTS table_for_rename_replicated;