|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Tags: no-shared-merge-tree, no-object-storage |
| 3 | + |
| 4 | +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
| 5 | +# shellcheck source=../shell_config.sh |
| 6 | +. "$CURDIR"/../shell_config.sh |
| 7 | + |
| 8 | +${CLICKHOUSE_CLIENT} --query "DROP TABLE IF EXISTS test_rename_substreams" |
| 9 | + |
| 10 | +${CLICKHOUSE_CLIENT} --query " |
| 11 | + CREATE TABLE test_rename_substreams |
| 12 | + ( |
| 13 | + id UInt32, |
| 14 | + arr Array(UInt32) |
| 15 | + ) |
| 16 | + ENGINE = MergeTree |
| 17 | + ORDER BY id |
| 18 | + SETTINGS min_rows_for_wide_part = 1, min_bytes_for_wide_part = 1, |
| 19 | + enable_block_number_column = 0, enable_block_offset_column = 0, |
| 20 | + replace_long_file_name_to_hash = 0, ratio_of_defaults_for_sparse_serialization = 1; |
| 21 | +" |
| 22 | + |
| 23 | +${CLICKHOUSE_CLIENT} --query "INSERT INTO test_rename_substreams SELECT number, [number, number + 1] FROM numbers(10)" |
| 24 | + |
| 25 | +# Get data path before rename to verify initial state |
| 26 | +DATA_PATH=$(${CLICKHOUSE_CLIENT} --query "SELECT path FROM system.parts WHERE database = currentDatabase() AND table = 'test_rename_substreams' AND active") |
| 27 | + |
| 28 | +echo "Before rename:" |
| 29 | +cat "${DATA_PATH}columns_substreams.txt" |
| 30 | + |
| 31 | +# Rename arr -> brr |
| 32 | +${CLICKHOUSE_CLIENT} --query "ALTER TABLE test_rename_substreams RENAME COLUMN arr TO brr" |
| 33 | + |
| 34 | +# Get the new part path (mutation creates a new part) |
| 35 | +DATA_PATH_NEW=$(${CLICKHOUSE_CLIENT} --query "SELECT path FROM system.parts WHERE database = currentDatabase() AND table = 'test_rename_substreams' AND active") |
| 36 | + |
| 37 | +echo "After rename arr -> brr:" |
| 38 | +cat "${DATA_PATH_NEW}columns_substreams.txt" |
| 39 | + |
| 40 | +# Also rename a Nested column to test the second code path (line 450) |
| 41 | +${CLICKHOUSE_CLIENT} --query "DROP TABLE IF EXISTS test_rename_nested_substreams" |
| 42 | + |
| 43 | +${CLICKHOUSE_CLIENT} --query " |
| 44 | + CREATE TABLE test_rename_nested_substreams |
| 45 | + ( |
| 46 | + id UInt32, |
| 47 | + nested Nested(a UInt32, b UInt32) |
| 48 | + ) |
| 49 | + ENGINE = MergeTree |
| 50 | + ORDER BY id |
| 51 | + SETTINGS min_rows_for_wide_part = 1, min_bytes_for_wide_part = 1, |
| 52 | + enable_block_number_column = 0, enable_block_offset_column = 0, |
| 53 | + replace_long_file_name_to_hash = 0, ratio_of_defaults_for_sparse_serialization = 1; |
| 54 | +" |
| 55 | + |
| 56 | +${CLICKHOUSE_CLIENT} --query "INSERT INTO test_rename_nested_substreams SELECT number, [number], [number + 1] FROM numbers(10)" |
| 57 | + |
| 58 | +DATA_PATH_NESTED=$(${CLICKHOUSE_CLIENT} --query "SELECT path FROM system.parts WHERE database = currentDatabase() AND table = 'test_rename_nested_substreams' AND active") |
| 59 | + |
| 60 | +echo "Nested before rename:" |
| 61 | +cat "${DATA_PATH_NESTED}columns_substreams.txt" |
| 62 | + |
| 63 | +# Rename nested.a -> nested.aa |
| 64 | +${CLICKHOUSE_CLIENT} --query "ALTER TABLE test_rename_nested_substreams RENAME COLUMN nested.a TO nested.aa" |
| 65 | + |
| 66 | +DATA_PATH_NESTED_NEW=$(${CLICKHOUSE_CLIENT} --query "SELECT path FROM system.parts WHERE database = currentDatabase() AND table = 'test_rename_nested_substreams' AND active") |
| 67 | + |
| 68 | +echo "Nested after rename nested.a -> nested.aa:" |
| 69 | +cat "${DATA_PATH_NESTED_NEW}columns_substreams.txt" |
| 70 | + |
| 71 | +${CLICKHOUSE_CLIENT} --query "DROP TABLE test_rename_substreams" |
| 72 | +${CLICKHOUSE_CLIENT} --query "DROP TABLE test_rename_nested_substreams" |
0 commit comments