From e590a341e56a967a191dbb6a0b2bfd222a207b43 Mon Sep 17 00:00:00 2001 From: alesapin Date: Fri, 13 Nov 2020 11:45:51 +0300 Subject: [PATCH] Add test --- ...alter_low_cardinality_and_select.reference | 6 +++ .../01576_alter_low_cardinality_and_select.sh | 41 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/queries/0_stateless/01576_alter_low_cardinality_and_select.reference create mode 100755 tests/queries/0_stateless/01576_alter_low_cardinality_and_select.sh diff --git a/tests/queries/0_stateless/01576_alter_low_cardinality_and_select.reference b/tests/queries/0_stateless/01576_alter_low_cardinality_and_select.reference new file mode 100644 index 00000000000..532cba023b6 --- /dev/null +++ b/tests/queries/0_stateless/01576_alter_low_cardinality_and_select.reference @@ -0,0 +1,6 @@ +733 733 +CREATE TABLE default.alter_table\n(\n `key` UInt64,\n `value` LowCardinality(String)\n)\nENGINE = MergeTree\nORDER BY key\nSETTINGS index_granularity = 8192 +all_1_1_0 +all_2_2_0 +all_3_3_0 +701 701 diff --git a/tests/queries/0_stateless/01576_alter_low_cardinality_and_select.sh b/tests/queries/0_stateless/01576_alter_low_cardinality_and_select.sh new file mode 100755 index 00000000000..1055c23ccad --- /dev/null +++ b/tests/queries/0_stateless/01576_alter_low_cardinality_and_select.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +. "$CURDIR"/../shell_config.sh + + +${CLICKHOUSE_CLIENT} --query "DROP TABLE IF EXISTS alter_table" + +${CLICKHOUSE_CLIENT} --query "CREATE TABLE alter_table (key UInt64, value String) ENGINE MergeTree ORDER BY key" + +# we don't need mutations and merges +${CLICKHOUSE_CLIENT} --query "SYSTEM STOP MERGES alter_table" + +${CLICKHOUSE_CLIENT} --query "INSERT INTO alter_table SELECT number, toString(number) FROM numbers(10000)" +${CLICKHOUSE_CLIENT} --query "INSERT INTO alter_table SELECT number, toString(number) FROM numbers(10000, 10000)" +${CLICKHOUSE_CLIENT} --query "INSERT INTO alter_table SELECT number, toString(number) FROM numbers(20000, 10000)" + +${CLICKHOUSE_CLIENT} --query "SELECT * FROM alter_table WHERE value == '733'" + +${CLICKHOUSE_CLIENT} --query "ALTER TABLE alter_table MODIFY COLUMN value LowCardinality(String)" & + +type_query="SELECT type FROM system.columns WHERE name = 'value' and table='alter_table' and database='${CLICKHOUSE_DATABASE}'" +value_type="" + +# waiting until schema will change (but not data) +while [[ "$value_type" != "LowCardinality(String)" ]] +do + sleep 0.1 + value_type=$($CLICKHOUSE_CLIENT --query "$type_query") +done + +# checking type is LowCardinalty +${CLICKHOUSE_CLIENT} --query "SHOW CREATE TABLE alter_table" + +# checking no mutations happened +${CLICKHOUSE_CLIENT} --query "SELECT name FROM system.parts where table='alter_table' and active and database='${CLICKHOUSE_DATABASE}' ORDER BY name" + +# checking that conversions applied "on fly" works +${CLICKHOUSE_CLIENT} --query "SELECT * FROM alter_table PREWHERE key > 700 WHERE value = '701'" + +${CLICKHOUSE_CLIENT} --query "DROP TABLE IF EXISTS alter_table"