2020-02-07 13:54:17 +00:00
#!/usr/bin/env bash
CURDIR = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
2020-12-28 11:46:53 +00:00
# shellcheck source=../shell_config.sh
2020-08-01 00:51:12 +00:00
. " $CURDIR " /../shell_config.sh
2020-02-07 13:54:17 +00:00
$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS movement"
2023-08-12 17:31:18 +00:00
$CLICKHOUSE_CLIENT -n --query "CREATE TABLE movement (date DateTime('Asia/Istanbul')) Engine = MergeTree ORDER BY (toStartOfHour(date)) SETTINGS index_granularity = 8192, index_granularity_bytes = '10Mi';"
2020-02-07 13:54:17 +00:00
2022-03-11 23:45:26 +00:00
$CLICKHOUSE_CLIENT --query "insert into movement select toDateTime('2020-01-22 00:00:00', 'Asia/Istanbul') + number%(23*3600) from numbers(1000000);"
2020-02-07 13:54:17 +00:00
$CLICKHOUSE_CLIENT --query "OPTIMIZE TABLE movement FINAL"
$CLICKHOUSE_CLIENT -n --query "
SELECT
count( ) ,
toStartOfHour( date) AS Hour
FROM movement
2022-03-11 23:45:26 +00:00
WHERE ( date >= toDateTime( '2020-01-22T10:00:00' , 'Asia/Istanbul' ) ) AND ( date <= toDateTime( '2020-01-22T23:00:00' , 'Asia/Istanbul' ) )
2020-02-07 13:54:17 +00:00
GROUP BY Hour
ORDER BY Hour DESC
" | grep " 16:00:00" | cut -f1
2022-03-11 23:45:26 +00:00
$CLICKHOUSE_CLIENT --query "alter table movement delete where date >= toDateTime('2020-01-22T16:00:00', 'Asia/Istanbul') and date < toDateTime('2020-01-22T17:00:00', 'Asia/Istanbul') SETTINGS mutations_sync = 2"
2020-02-07 13:54:17 +00:00
$CLICKHOUSE_CLIENT -n --query "
SELECT
count( ) ,
toStartOfHour( date) AS Hour
FROM movement
2022-03-11 23:45:26 +00:00
WHERE ( date >= toDateTime( '2020-01-22T10:00:00' , 'Asia/Istanbul' ) ) AND ( date <= toDateTime( '2020-01-22T23:00:00' , 'Asia/Istanbul' ) )
2020-02-07 13:54:17 +00:00
GROUP BY Hour
ORDER BY Hour DESC
" | grep " 16:00:00" | wc -l
$CLICKHOUSE_CLIENT -n --query "
SELECT
count( ) ,
toStartOfHour( date) AS Hour
FROM movement
2022-03-11 23:45:26 +00:00
WHERE ( date >= toDateTime( '2020-01-22T10:00:00' , 'Asia/Istanbul' ) ) AND ( date <= toDateTime( '2020-01-22T23:00:00' , 'Asia/Istanbul' ) )
2020-02-07 13:54:17 +00:00
GROUP BY Hour
ORDER BY Hour DESC
" | grep " 22:00:00" | cut -f1
$CLICKHOUSE_CLIENT -n --query "
SELECT
count( ) ,
toStartOfHour( date) AS Hour
FROM movement
GROUP BY Hour
ORDER BY Hour DESC
" | grep " 22:00:00" | cut -f1
$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS movement"