2018-06-05 11:00:17 +00:00
#!/usr/bin/env bash
CURDIR = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
2020-08-01 00:51:12 +00:00
. " $CURDIR " /../shell_config.sh
2018-06-05 11:00:17 +00:00
${ CLICKHOUSE_CLIENT } --query= "SELECT '*** Single column partition key ***'"
2019-04-16 14:13:13 +00:00
${ CLICKHOUSE_CLIENT } --query= "DROP TABLE IF EXISTS single_col_partition_key"
${ CLICKHOUSE_CLIENT } --query= "CREATE TABLE single_col_partition_key(x UInt32) ENGINE MergeTree ORDER BY x PARTITION BY intDiv(x, 10)"
2018-06-05 11:00:17 +00:00
2019-04-16 14:13:13 +00:00
${ CLICKHOUSE_CLIENT } --query= "INSERT INTO single_col_partition_key VALUES (1), (2), (3), (4), (11), (12), (20)"
2018-06-05 11:00:17 +00:00
2019-04-16 14:13:13 +00:00
${ CLICKHOUSE_CLIENT } --query= "SELECT count() FROM single_col_partition_key WHERE x < 3 FORMAT XML" | grep -F rows_read | sed 's/^[ \t]*//g'
${ CLICKHOUSE_CLIENT } --query= "SELECT count() FROM single_col_partition_key WHERE x >= 11 FORMAT XML" | grep -F rows_read | sed 's/^[ \t]*//g'
${ CLICKHOUSE_CLIENT } --query= "SELECT count() FROM single_col_partition_key WHERE x = 20 FORMAT XML" | grep -F rows_read | sed 's/^[ \t]*//g'
2018-06-05 11:00:17 +00:00
2019-04-16 14:13:13 +00:00
${ CLICKHOUSE_CLIENT } --query= "DROP TABLE single_col_partition_key"
2018-06-05 11:00:17 +00:00
${ CLICKHOUSE_CLIENT } --query= "SELECT '*** Composite partition key ***'"
2019-04-16 14:13:13 +00:00
${ CLICKHOUSE_CLIENT } --query= "DROP TABLE IF EXISTS composite_partition_key"
${ CLICKHOUSE_CLIENT } --query= "CREATE TABLE composite_partition_key(a UInt32, b UInt32, c UInt32) ENGINE MergeTree ORDER BY c PARTITION BY (intDiv(a, 100), intDiv(b, 10), c)"
2018-06-05 11:00:17 +00:00
2019-04-16 14:13:13 +00:00
${ CLICKHOUSE_CLIENT } --query= " INSERT INTO composite_partition_key VALUES \
2018-06-05 11:00:17 +00:00
( 1, 1, 1) , ( 2, 2, 1) , ( 3, 3, 1) "
2019-04-16 14:13:13 +00:00
${ CLICKHOUSE_CLIENT } --query= " INSERT INTO composite_partition_key VALUES \
2018-06-05 11:00:17 +00:00
( 100, 10, 2) , ( 101, 11, 2) , ( 102, 12, 2) "
2019-04-16 14:13:13 +00:00
${ CLICKHOUSE_CLIENT } --query= " INSERT INTO composite_partition_key VALUES \
2018-06-05 11:00:17 +00:00
( 200, 10, 2) , ( 201, 11, 2) , ( 202, 12, 2) "
2019-04-16 14:13:13 +00:00
${ CLICKHOUSE_CLIENT } --query= " INSERT INTO composite_partition_key VALUES \
2018-06-05 11:00:17 +00:00
( 301, 20, 3) , ( 302, 21, 3) , ( 303, 22, 3) "
2019-04-16 14:13:13 +00:00
${ CLICKHOUSE_CLIENT } --query= "SELECT count() FROM composite_partition_key WHERE a > 400 FORMAT XML" | grep -F rows_read | sed 's/^[ \t]*//g'
${ CLICKHOUSE_CLIENT } --query= "SELECT count() FROM composite_partition_key WHERE b = 11 FORMAT XML" | grep -F rows_read | sed 's/^[ \t]*//g'
${ CLICKHOUSE_CLIENT } --query= "SELECT count() FROM composite_partition_key WHERE c = 4 FORMAT XML" | grep -F rows_read | sed 's/^[ \t]*//g'
2018-06-05 11:00:17 +00:00
2019-04-16 14:13:13 +00:00
${ CLICKHOUSE_CLIENT } --query= "SELECT count() FROM composite_partition_key WHERE a < 200 AND c = 2 FORMAT XML" | grep -F rows_read | sed 's/^[ \t]*//g'
${ CLICKHOUSE_CLIENT } --query= "SELECT count() FROM composite_partition_key WHERE a = 301 AND b < 20 FORMAT XML" | grep -F rows_read | sed 's/^[ \t]*//g'
${ CLICKHOUSE_CLIENT } --query= "SELECT count() FROM composite_partition_key WHERE b >= 12 AND c = 2 FORMAT XML" | grep -F rows_read | sed 's/^[ \t]*//g'
2018-06-05 11:00:17 +00:00
2019-04-16 14:13:13 +00:00
${ CLICKHOUSE_CLIENT } --query= "SELECT count() FROM composite_partition_key WHERE a = 301 AND b = 21 AND c = 3 FORMAT XML" | grep -F rows_read | sed 's/^[ \t]*//g'
2018-06-05 11:00:17 +00:00
2019-04-16 14:13:13 +00:00
${ CLICKHOUSE_CLIENT } --query= "DROP TABLE composite_partition_key"