2017-11-01 11:46:58 +00:00
#!/usr/bin/env bash
2017-12-15 19:34:19 +00:00
2017-05-11 14:05:08 +00:00
set -e
2017-12-15 19:34:19 +00:00
CURDIR = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
. $CURDIR /../shell_config.sh
2017-05-11 14:05:08 +00:00
# Not found column date in block. There are only columns: x.
# Test 1. Complex test checking columns.txt
2017-12-15 19:34:19 +00:00
chl = " $CLICKHOUSE_CLIENT -q "
ch_dir = ` ${ CLICKHOUSE_EXTRACT_CONFIG } -k path`
2017-05-11 14:05:08 +00:00
2017-05-12 13:44:11 +00:00
$chl "DROP TABLE IF EXISTS test.partition_428"
2019-06-19 16:16:13 +00:00
$chl "CREATE TABLE test.partition_428 (p Date, k Int8, v1 Int8 MATERIALIZED k + 1) ENGINE = MergeTree PARTITION BY p ORDER BY k SETTINGS index_granularity=1, index_granularity_bytes=0"
2017-05-11 14:05:08 +00:00
$chl "INSERT INTO test.partition_428 (p, k) VALUES(toDate(31), 1)"
$chl "INSERT INTO test.partition_428 (p, k) VALUES(toDate(1), 2)"
for part in ` $chl "SELECT name FROM system.parts WHERE database='test' AND table='partition_428'" ` ; do
2018-10-30 14:05:44 +00:00
# 2 header lines + 3 columns
( sudo -n cat $ch_dir /data/test/partition_428/$part /columns.txt 2>/dev/null || \
cat $ch_dir /data/test/partition_428/$part /columns.txt) | wc -l
2017-05-11 14:05:08 +00:00
done
2018-10-30 15:04:13 +00:00
$chl "ALTER TABLE test.partition_428 FREEZE"
2018-11-01 10:35:50 +00:00
# Do `cd` for consistent output for reference
2019-05-31 04:03:46 +00:00
# Do not check increment.txt - it can be changed by other tests with FREEZE
cd $ch_dir && find shadow -type f -exec md5sum { } \; | grep "partition_428" | sed 's!shadow/[0-9]*/data/[a-z0-9_-]*/!shadow/1/data/test/!g' | sort | uniq
2018-10-30 15:04:13 +00:00
2017-05-11 14:05:08 +00:00
$chl "ALTER TABLE test.partition_428 DETACH PARTITION 197001"
$chl "ALTER TABLE test.partition_428 ATTACH PARTITION 197001"
for part in ` $chl "SELECT name FROM system.parts WHERE database='test' AND table='partition_428'" ` ; do
2018-10-30 14:05:44 +00:00
# 2 header lines + 3 columns
( sudo -n cat $ch_dir /data/test/partition_428/$part /columns.txt 2>/dev/null || \
cat $ch_dir /data/test/partition_428/$part /columns.txt) | wc -l
2017-05-11 14:05:08 +00:00
done
$chl "ALTER TABLE test.partition_428 MODIFY COLUMN v1 Int8"
2018-10-30 18:57:20 +00:00
2018-11-01 10:35:50 +00:00
# Check the backup hasn't changed
2019-05-31 04:03:46 +00:00
cd $ch_dir && find shadow -type f -exec md5sum { } \; | grep "partition_428" | sed 's!shadow/[0-9]*/data/[a-z0-9_-]*/!shadow/1/data/test/!g' | sort | uniq
2018-10-30 18:57:20 +00:00
2017-05-11 14:05:08 +00:00
$chl "OPTIMIZE TABLE test.partition_428"
$chl "SELECT toUInt16(p), k, v1 FROM test.partition_428 ORDER BY k FORMAT CSV"
$chl "DROP TABLE test.partition_428"
# Test 2. Simple test
$chl "drop table if exists test.partition_428"
2019-06-19 16:16:13 +00:00
$chl "create table test.partition_428 (date MATERIALIZED toDate(0), x UInt64, sample_key MATERIALIZED intHash64(x)) ENGINE=MergeTree PARTITION BY date SAMPLE BY sample_key ORDER BY (date,x,sample_key) SETTINGS index_granularity=8192, index_granularity_bytes=0"
2017-05-11 14:05:08 +00:00
$chl "insert into test.partition_428 ( x ) VALUES ( now() )"
$chl "insert into test.partition_428 ( x ) VALUES ( now()+1 )"
$chl "alter table test.partition_428 detach partition 197001"
$chl "alter table test.partition_428 attach partition 197001"
$chl "optimize table test.partition_428"
$chl "drop table test.partition_428"