ClickHouse/tests/queries/0_stateless/02297_regex_parsing_file_names.sh
Mikhail Koviazin db43fb1004
tests/queries: use CLICKHOUSE_CLIENT_BINARY
Previously tests assumed there is `clickhouse-client` available in test machine
`$PATH`, which is not always true and will cause a test failure when ClickHouse
is not installed system-wide. This commit fixes that by utilizing
`CLICKHOUSE_CLIENT_BINARY` more which is substitued from `CLICKHOUSE_BINARY`
which is set as `-b` argument in `clickhouse-test`.
2023-12-14 12:14:57 +00:00

41 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Tags: no-parallel
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')"
CLICKHOUSE_USER_FILES_PATH=$($CLICKHOUSE_CLIENT_BINARY --query "select _path, _file from file('nonexist.txt', 'CSV', 'val1 char')" 2>&1 | grep Exception | awk '{gsub("/nonexist.txt","",$9); print $9}')
mkdir -p ${CLICKHOUSE_USER_FILES_PATH}/
rm -rf ${CLICKHOUSE_USER_FILES_PATH}/file_{0..10}.csv
echo '0' > ${CLICKHOUSE_USER_FILES_PATH}/file_0.csv
echo '0' > ${CLICKHOUSE_USER_FILES_PATH}/file_1.csv
echo '0' > ${CLICKHOUSE_USER_FILES_PATH}/file_2.csv
echo '0' > ${CLICKHOUSE_USER_FILES_PATH}/file_3.csv
echo '0' > ${CLICKHOUSE_USER_FILES_PATH}/file_4.csv
echo '0' > ${CLICKHOUSE_USER_FILES_PATH}/file_5.csv
echo '0' > ${CLICKHOUSE_USER_FILES_PATH}/file_6.csv
echo '0' > ${CLICKHOUSE_USER_FILES_PATH}/file_7.csv
echo '0' > ${CLICKHOUSE_USER_FILES_PATH}/file_8.csv
echo '0' > ${CLICKHOUSE_USER_FILES_PATH}/file_9.csv
echo '0' > ${CLICKHOUSE_USER_FILES_PATH}/file_10.csv
# echo '' > ${CLICKHOUSE_USER_FILES_PATH}/file_10.csv
${CLICKHOUSE_CLIENT} -q "DROP TABLE IF EXISTS t_regex;"
${CLICKHOUSE_CLIENT} -q "CREATE TABLE t_regex (id UInt64) ENGINE = MergeTree() order by id;"
${CLICKHOUSE_CLIENT} -q "INSERT INTO t_regex SELECT * FROM file('file_{0..10}.csv','CSV');"
${CLICKHOUSE_CLIENT} -q "SELECT count() from t_regex;"
rm -rf ${CLICKHOUSE_USER_FILES_PATH}/file_{0..10}.csv;
${CLICKHOUSE_CLIENT} -q "DROP TABLE IF EXISTS t_regex;"