2023-08-03 12:42:50 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Tags: no-fasttest
|
|
|
|
|
|
|
|
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
|
|
# shellcheck source=../shell_config.sh
|
|
|
|
. "$CUR_DIR"/../shell_config.sh
|
|
|
|
|
|
|
|
function read_archive_file() {
|
|
|
|
$CLICKHOUSE_LOCAL --query "SELECT * FROM file('${user_files_path}/$1') ORDER BY 1, 2"
|
2023-08-04 10:33:25 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query "SELECT * FROM file('${user_files_path}/$1') ORDER BY 1, 2"
|
2023-08-28 13:10:13 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query "DESC file('${user_files_path}/$1')"
|
2023-08-03 12:42:50 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query "CREATE TABLE 02661_archive_table Engine=File('CSV', '${user_files_path}/$1')"
|
|
|
|
$CLICKHOUSE_CLIENT --query "SELECT * FROM 02661_archive_table ORDER BY 1, 2"
|
|
|
|
$CLICKHOUSE_CLIENT --query "DROP TABLE 02661_archive_table"
|
2023-08-04 10:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_archive_test() {
|
|
|
|
$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS 02661_archive_table"
|
|
|
|
|
2023-08-28 13:10:13 +00:00
|
|
|
extension_without_dot=$(echo $1 | sed -e 's/\.//g')
|
|
|
|
FILE_PREFIX="02661_read_from_archive_${CLICKHOUSE_DATABASE}_$extension_without_dot"
|
2023-08-09 10:04:29 +00:00
|
|
|
|
2023-08-28 13:10:13 +00:00
|
|
|
user_files_path=$(clickhouse-client --query "select _path, _file from file('nonexist.txt', 'CSV', 'val1 char')" 2>&1 | grep -o "/[^[:space:]]*nonexist.txt" | awk '{gsub("/nonexist.txt","",$1); print $1}')
|
2023-08-04 10:33:25 +00:00
|
|
|
|
2023-08-28 13:10:13 +00:00
|
|
|
touch ${FILE_PREFIX}_data0.csv
|
2023-08-09 10:04:29 +00:00
|
|
|
echo -e "1,2\n3,4" > ${FILE_PREFIX}_data1.csv
|
|
|
|
echo -e "5,6\n7,8" > ${FILE_PREFIX}_data2.csv
|
|
|
|
echo -e "9,10\n11,12" > ${FILE_PREFIX}_data3.csv
|
2023-08-04 10:33:25 +00:00
|
|
|
|
2023-08-28 13:10:13 +00:00
|
|
|
eval "$2 ${user_files_path}/${FILE_PREFIX}_archive1.$1 ${FILE_PREFIX}_data0.csv ${FILE_PREFIX}_data1.csv ${FILE_PREFIX}_data2.csv > /dev/null"
|
2023-08-09 10:04:29 +00:00
|
|
|
eval "$2 ${user_files_path}/${FILE_PREFIX}_archive2.$1 ${FILE_PREFIX}_data1.csv ${FILE_PREFIX}_data3.csv > /dev/null"
|
|
|
|
eval "$2 ${user_files_path}/${FILE_PREFIX}_archive3.$1 ${FILE_PREFIX}_data2.csv ${FILE_PREFIX}_data3.csv > /dev/null"
|
2023-08-04 10:33:25 +00:00
|
|
|
|
|
|
|
echo "archive1 data1.csv"
|
2023-08-09 10:04:29 +00:00
|
|
|
read_archive_file "${FILE_PREFIX}_archive1.$1 :: ${FILE_PREFIX}_data1.csv"
|
2023-08-04 10:33:25 +00:00
|
|
|
echo "archive{1..2} data1.csv"
|
2023-08-09 10:04:29 +00:00
|
|
|
read_archive_file "${FILE_PREFIX}_archive{1..2}.$1 :: ${FILE_PREFIX}_data1.csv"
|
2023-08-04 10:33:25 +00:00
|
|
|
echo "archive{1,2} data{1,3}.csv"
|
2023-08-09 10:04:29 +00:00
|
|
|
read_archive_file "${FILE_PREFIX}_archive{1,2}.$1 :: ${FILE_PREFIX}_data{1,3}.csv"
|
2023-08-04 10:33:25 +00:00
|
|
|
echo "archive3 data*.csv"
|
2023-08-09 10:04:29 +00:00
|
|
|
read_archive_file "${FILE_PREFIX}_archive3.$1 :: ${FILE_PREFIX}_data*.csv"
|
2023-08-04 10:33:25 +00:00
|
|
|
echo "archive* *.csv"
|
2023-08-09 10:04:29 +00:00
|
|
|
read_archive_file "${FILE_PREFIX}_archive*.$1 :: *.csv"
|
2023-08-04 10:33:25 +00:00
|
|
|
echo "archive* {2..3}.csv"
|
2023-08-09 10:04:29 +00:00
|
|
|
read_archive_file "${FILE_PREFIX}_archive*.$1 :: ${FILE_PREFIX}_data{2..3}.csv"
|
2023-08-04 10:33:25 +00:00
|
|
|
|
2023-08-28 13:10:13 +00:00
|
|
|
$CLICKHOUSE_LOCAL --query "SELECT * FROM file('${user_files_path}/${FILE_PREFIX}_archive1.$1::nonexistent.csv')" 2>&1 | grep -q "CANNOT_EXTRACT_TABLE_STRUCTURE" && echo "OK" || echo "FAIL"
|
|
|
|
$CLICKHOUSE_LOCAL --query "SELECT * FROM file('${user_files_path}/${FILE_PREFIX}_archive3.$1::{2..3}.csv')" 2>&1 | grep -q "CANNOT_EXTRACT_TABLE_STRUCTURE" && echo "OK" || echo "FAIL"
|
2023-08-04 10:33:25 +00:00
|
|
|
|
2023-08-09 10:04:29 +00:00
|
|
|
rm ${user_files_path}/${FILE_PREFIX}_archive{1..3}.$1
|
2023-08-04 10:33:25 +00:00
|
|
|
|
2023-08-28 13:10:13 +00:00
|
|
|
rm ${FILE_PREFIX}_data{0..3}.csv
|
2023-08-18 09:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# vi: ft=bash
|