#!/usr/bin/env bash set -e CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) # shellcheck source=../shell_config.sh . "$CURDIR"/../shell_config.sh $CLICKHOUSE_CLIENT --multiquery </dev/null & done wait is_done=$($CLICKHOUSE_CLIENT -q "SELECT countIf(case = 1) > 0 AND countIf(case = 2) > 0 FROM mv;") if [ "$is_done" -eq "1" ]; then break fi done } function alter_thread() { trap 'exit' INT # Generate random ALTERs, but make sure that at least one of them is for each source table. for i in {0..5}; do ALTER[$i]="ALTER TABLE mv MODIFY QUERY SELECT v == 1 as test, v as case FROM src_a;" done # Insert 3 ALTERs to src_b, one in the first half of the array and two in arbitrary positions. ALTER[$RANDOM % 3]="ALTER TABLE mv MODIFY QUERY SELECT v == 2 as test, v as case FROM src_b;" ALTER[$RANDOM % 6]="ALTER TABLE mv MODIFY QUERY SELECT v == 2 as test, v as case FROM src_b;" ALTER[$RANDOM % 6]="ALTER TABLE mv MODIFY QUERY SELECT v == 2 as test, v as case FROM src_b;" i=0 while true; do $CLICKHOUSE_CLIENT --allow_experimental_alter_materialized_view_structure=1 -q "${ALTER[$i % 6]}" ((i=i+1)) sleep "0.0$RANDOM" is_done=$($CLICKHOUSE_CLIENT -q "SELECT countIf(case = 1) > 0 AND countIf(case = 2) > 0 FROM mv;") if [ "$is_done" -eq "1" ]; then break fi done } export -f insert_thread; export -f alter_thread; # finishes much faster with all builds, except debug with coverage timeout 120 bash -c insert_thread & timeout 120 bash -c alter_thread & wait $CLICKHOUSE_CLIENT -q "SELECT countIf(case = 1) > 0 AND countIf(case = 2) > 0 FROM mv LIMIT 1;" $CLICKHOUSE_CLIENT -q "SELECT 'inconsistencies', count() FROM mv WHERE test == 0;" $CLICKHOUSE_CLIENT -q "DROP VIEW mv" $CLICKHOUSE_CLIENT -q "DROP TABLE src_a" $CLICKHOUSE_CLIENT -q "DROP TABLE src_b"