ClickHouse/tests/queries/0_stateless/01658_read_file_to_stringcolumn.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

100 lines
4.3 KiB
Bash
Raw Normal View History

2021-01-16 18:55:07 +00:00
#!/usr/bin/env bash
2021-09-12 12:35:27 +00:00
# Tags: no-parallel
2021-01-16 18:55:07 +00:00
set -eu
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
# Data preparation.
2021-12-13 05:52:10 +00:00
2021-01-28 11:13:32 +00:00
# Now we can get the user_files_path by use the table file function for trick. also we can get it by query as:
2021-01-29 02:14:10 +00:00
# "insert into function file('exist.txt', 'CSV', 'val1 char') values ('aaaa'); select _path from file('exist.txt', 'CSV', 'val1 char')"
2021-12-13 05:52:10 +00:00
CLICKHOUSE_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-02-12 17:25:40 +00:00
2021-12-13 05:52:10 +00:00
mkdir -p ${CLICKHOUSE_USER_FILES_PATH}/
echo -n aaaaaaaaa > ${CLICKHOUSE_USER_FILES_PATH}/a.txt
echo -n bbbbbbbbb > ${CLICKHOUSE_USER_FILES_PATH}/b.txt
echo -n ccccccccc > ${CLICKHOUSE_USER_FILES_PATH}/c.txt
2021-01-16 18:55:07 +00:00
echo -n ccccccccc > /tmp/c.txt
2021-12-13 05:52:10 +00:00
mkdir -p ${CLICKHOUSE_USER_FILES_PATH}/dir
2021-01-16 18:55:07 +00:00
2021-01-16 18:55:07 +00:00
### 1st TEST in CLIENT mode.
${CLICKHOUSE_CLIENT} --query "drop table if exists data;"
${CLICKHOUSE_CLIENT} --query "create table data (A String, B String) engine=MergeTree() order by A;"
# Valid cases:
2021-12-13 05:52:10 +00:00
${CLICKHOUSE_CLIENT} --query "select file('a.txt'), file('b.txt');";echo ":"$?
${CLICKHOUSE_CLIENT} --query "insert into data select file('a.txt'), file('b.txt');";echo ":"$?
${CLICKHOUSE_CLIENT} --query "insert into data select file('a.txt'), file('b.txt');";echo ":"$?
${CLICKHOUSE_CLIENT} --query "select file('c.txt'), * from data";echo ":"$?
2021-02-16 12:37:49 +00:00
${CLICKHOUSE_CLIENT} --multiquery --query "
2021-12-13 05:35:40 +00:00
create table filenames(name String) engine=MergeTree() order by tuple();
insert into filenames values ('a.txt'), ('b.txt'), ('c.txt');
select file(name) from filenames format TSV;
drop table if exists filenames;
2021-02-16 12:37:49 +00:00
"
2021-01-16 18:55:07 +00:00
# Invalid cases: (Here using sub-shell to catch exception avoiding the test quit)
# Test non-exists file
2021-12-13 05:52:10 +00:00
echo "${CLICKHOUSE_CLIENT} --query "'"select file('"'nonexist.txt'), file('b.txt')"'";echo :$?' | bash 2>/dev/null
2021-01-16 18:55:07 +00:00
# Test isDir
2021-12-13 05:52:10 +00:00
echo "${CLICKHOUSE_CLIENT} --query "'"select file('"'dir'), file('b.txt')"'";echo :$?' | bash 2>/dev/null
2021-01-16 18:55:07 +00:00
# Test path out of the user_files directory. It's not allowed in client mode
2021-12-13 05:52:10 +00:00
echo "${CLICKHOUSE_CLIENT} --query "'"select file('"'/tmp/c.txt'), file('b.txt')"'";echo :$?' | bash 2>/dev/null
2021-01-16 18:55:07 +00:00
# Test relative path consists of ".." whose absolute path is out of the user_files directory.
2021-12-13 05:52:10 +00:00
echo "${CLICKHOUSE_CLIENT} --query "'"select file('"'../../../../../../../../../../../../../../../../../../../tmp/c.txt'), file('b.txt')"'";echo :$?' | bash 2>/dev/null
echo "${CLICKHOUSE_CLIENT} --query "'"select file('"'../../../../a.txt'), file('b.txt')"'";echo :$?' | bash 2>/dev/null
2021-01-16 18:55:07 +00:00
### 2nd TEST in LOCAL mode.
echo -n aaaaaaaaa > a.txt
echo -n bbbbbbbbb > b.txt
echo -n ccccccccc > c.txt
2021-01-22 07:29:39 +00:00
mkdir -p dir
2021-01-16 18:55:07 +00:00
#Test for large files, with length : 699415
c_count=$(wc -c ${CURDIR}/01518_nullable_aggregate_states2.reference | awk '{print $1}')
echo $c_count
# Valid cases:
# The default dir is the CWD path in LOCAL mode
${CLICKHOUSE_LOCAL} --query "
2021-12-13 05:35:40 +00:00
drop table if exists data;
create table data (A String, B String) engine=MergeTree() order by A;
select file('a.txt'), file('b.txt');
insert into data select file('a.txt'), file('b.txt');
insert into data select file('a.txt'), file('b.txt');
select file('c.txt'), * from data;
select file('/tmp/c.txt'), * from data;
select $c_count, $c_count -length(file('${CURDIR}/01518_nullable_aggregate_states2.reference'))
2021-01-16 18:55:07 +00:00
"
echo ":"$?
# Invalid cases: (Here using sub-shell to catch exception avoiding the test quit)
# Test non-exists file
2021-12-13 05:52:10 +00:00
echo "${CLICKHOUSE_LOCAL} --query "'"select file('"'nonexist.txt'), file('b.txt')"'";echo :$?' | bash 2>/dev/null
2021-01-16 18:55:07 +00:00
# Test isDir
2021-12-13 05:52:10 +00:00
echo "${CLICKHOUSE_LOCAL} --query "'"select file('"'dir'), file('b.txt')"'";echo :$?' | bash 2>/dev/null
# Test that the function is not injective
echo -n Hello > ${CLICKHOUSE_USER_FILES_PATH}/a
echo -n Hello > ${CLICKHOUSE_USER_FILES_PATH}/b
echo -n World > ${CLICKHOUSE_USER_FILES_PATH}/c
${CLICKHOUSE_CLIENT} --query "SELECT file(arrayJoin(['a', 'b', 'c'])) AS s, count() GROUP BY s ORDER BY s"
${CLICKHOUSE_CLIENT} --query "SELECT s, count() FROM file('?', TSV, 's String') GROUP BY s ORDER BY s"
2021-01-16 18:55:07 +00:00
# Restore
2021-12-13 05:52:10 +00:00
rm ${CLICKHOUSE_USER_FILES_PATH}/{a,b,c}.txt
rm ${CLICKHOUSE_USER_FILES_PATH}/{a,b,c}
rm /tmp/c.txt
rm -rf ${CLICKHOUSE_USER_FILES_PATH}/dir