ClickHouse/tests/queries/0_stateless/02023_storage_filelog.sh

79 lines
3.3 KiB
Bash
Raw Normal View History

2021-09-13 11:09:31 +00:00
#!/usr/bin/env bash
2021-09-13 11:09:31 +00:00
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-10-18 07:27:37 +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-13 11:09:31 +00:00
2021-10-30 09:54:17 +00:00
mkdir -p ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/
2021-09-26 07:22:45 +00:00
2021-10-30 09:54:17 +00:00
rm -rf ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME:?}/*
2021-09-26 07:22:45 +00:00
for i in {1..20}
do
2021-10-30 09:54:17 +00:00
echo $i, $i >> ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/a.txt
2021-09-26 07:22:45 +00:00
done
2021-09-13 11:09:31 +00:00
${CLICKHOUSE_CLIENT} --query "drop table if exists file_log;"
2021-10-30 09:54:17 +00:00
${CLICKHOUSE_CLIENT} --query "create table file_log(k UInt8, v UInt8) engine=FileLog('${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/', 'CSV');"
2021-09-13 11:09:31 +00:00
${CLICKHOUSE_CLIENT} --query "select * from file_log order by k;"
2021-10-30 09:54:17 +00:00
cp ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/a.txt ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/b.txt
2021-09-13 11:09:31 +00:00
${CLICKHOUSE_CLIENT} --query "select * from file_log order by k;"
2021-09-26 07:22:45 +00:00
for i in {100..120}
do
2021-10-30 09:54:17 +00:00
echo $i, $i >> ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/a.txt
2021-09-26 07:22:45 +00:00
done
2021-09-13 11:09:31 +00:00
2021-09-21 16:11:35 +00:00
# touch does not change file content, no event
2021-10-30 09:54:17 +00:00
touch ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/a.txt
2021-09-21 16:11:35 +00:00
2021-10-30 09:54:17 +00:00
cp ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/a.txt ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/c.txt
cp ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/a.txt ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/d.txt
cp ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/a.txt ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/e.txt
mv ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/b.txt ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/j.txt
2021-09-13 11:09:31 +00:00
2021-10-30 09:54:17 +00:00
rm ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/d.txt
2021-09-13 14:50:27 +00:00
2021-09-26 07:22:45 +00:00
${CLICKHOUSE_CLIENT} --query "select * from file_log order by k;"
2021-09-13 11:09:31 +00:00
2021-10-18 06:38:47 +00:00
${CLICKHOUSE_CLIENT} --query "detach table file_log;"
2021-10-30 09:54:17 +00:00
cp ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/e.txt ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/f.txt
mv ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/e.txt ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/g.txt
mv ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/c.txt ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/h.txt
2021-10-18 06:38:47 +00:00
for i in {150..200}
do
2021-10-30 09:54:17 +00:00
echo $i, $i >> ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/h.txt
2021-10-18 06:38:47 +00:00
done
for i in {200..250}
do
2021-10-30 09:54:17 +00:00
echo $i, $i >> ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/i.txt
2021-10-18 06:38:47 +00:00
done
${CLICKHOUSE_CLIENT} --query "attach table file_log;"
${CLICKHOUSE_CLIENT} --query "select * from file_log order by k;"
2021-09-26 07:22:45 +00:00
${CLICKHOUSE_CLIENT} --query "detach table file_log;"
${CLICKHOUSE_CLIENT} --query "attach table file_log;"
2021-09-13 11:09:31 +00:00
2021-09-26 07:22:45 +00:00
# should no records return
${CLICKHOUSE_CLIENT} --query "select * from file_log order by k;"
2021-10-30 09:54:17 +00:00
truncate ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME}/a.txt --size 0
2021-09-13 14:50:27 +00:00
2021-09-26 07:22:45 +00:00
# exception happend
2021-10-03 09:31:53 +00:00
${CLICKHOUSE_CLIENT} --query "select * from file_log order by k;" 2>&1 | grep -q "Code: 33" && echo 'OK' || echo 'FAIL'
2021-09-13 11:09:31 +00:00
2021-09-13 15:59:27 +00:00
${CLICKHOUSE_CLIENT} --query "drop table file_log;"
2021-10-30 09:54:17 +00:00
rm -rf ${user_files_path}/${CLICKHOUSE_TEST_UNIQUE_NAME:?}