ClickHouse/tests/queries/0_stateless/02024_storage_filelog_mv.sh

66 lines
1.9 KiB
Bash
Raw Normal View History

2021-09-26 07:22:45 +00:00
#!/usr/bin/env bash
# Tags: long, no-parallel
set -eu
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
# Data preparation.
# Now we can get the user_files_path by use the table file function for trick. also we can get it by query as:
# "insert into function file('exist.txt', 'CSV', 'val1 char') values ('aaaa'); select _path from file('exist.txt', 'CSV', 'val1 char')"
2021-09-26 13:07:31 +00:00
user_files_path=$(clickhouse-client --query "select _path,_file from file('nonexist.txt', 'CSV', 'val1 char')" 2>&1 | grep Exception | awk '{gsub("/nonexist.txt","",$9); print $9}')
2021-09-26 07:22:45 +00:00
mkdir -p ${user_files_path}/logs/
rm -rf ${user_files_path}/logs/*
2021-10-18 07:08:37 +00:00
for i in {1..20}
do
echo $i, $i >> ${user_files_path}/logs/a.txt
done
2021-09-26 07:22:45 +00:00
${CLICKHOUSE_CLIENT} --query "drop table if exists file_log;"
2021-09-30 16:22:26 +00:00
${CLICKHOUSE_CLIENT} --query "create table file_log(k UInt8, v UInt8) engine=FileLog('${user_files_path}/logs/', 'CSV');"
2021-09-26 07:22:45 +00:00
${CLICKHOUSE_CLIENT} --query "drop table if exists mv;"
${CLICKHOUSE_CLIENT} --query "create Materialized View mv engine=MergeTree order by k as select * from file_log;"
2021-10-23 09:35:33 +00:00
function count()
{
COUNT=$(${CLICKHOUSE_CLIENT} --query "select count() from mv;")
echo $COUNT
}
while true; do
[[ $(count) == 20 ]] && break
sleep 1
2021-09-26 07:22:45 +00:00
done
${CLICKHOUSE_CLIENT} --query "select * from mv order by k;"
cp ${user_files_path}/logs/a.txt ${user_files_path}/logs/b.txt
# touch does not change file content, no event
touch ${user_files_path}/logs/a.txt
cp ${user_files_path}/logs/a.txt ${user_files_path}/logs/c.txt
cp ${user_files_path}/logs/a.txt ${user_files_path}/logs/d.txt
for i in {100..120}
do
echo $i, $i >> ${user_files_path}/logs/d.txt
done
2021-10-23 09:35:33 +00:00
while true; do
[[ $(count) == 101 ]] && break
sleep 1
2021-09-26 07:22:45 +00:00
done
${CLICKHOUSE_CLIENT} --query "select * from mv order by k;"
${CLICKHOUSE_CLIENT} --query "drop table mv;"
${CLICKHOUSE_CLIENT} --query "drop table file_log;"
rm -rf ${user_files_path}/logs