2022-07-05 18:03:51 +00:00
#!/usr/bin/env bash
CURDIR = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
# shellcheck source=../shell_config.sh
. " $CURDIR " /../shell_config.sh
function perform( )
{
local test_id = $1
local query = $2
2022-07-14 20:14:46 +00:00
echo " performing test: ${ test_id } "
2022-07-17 18:09:18 +00:00
${ CLICKHOUSE_CLIENT } --query " ${ query } " | sort --numeric-sort
2022-07-05 18:03:51 +00:00
if [ " $? " -eq 0 ] ; then
2022-07-17 18:09:18 +00:00
cat " ${ CLICKHOUSE_TMP } /test_into_outfile_and_stdout_ ${ test_id } .out " | sort --numeric-sort
2022-07-05 18:03:51 +00:00
else
echo "query failed"
fi
2022-07-14 20:14:46 +00:00
rm -f " ${ CLICKHOUSE_TMP } /test_into_outfile_and_stdout_ ${ test_id } .out "
}
function performBadQuery( )
{
local test_id = $1
local query = $2
local error_message = $3
echo " performing test: ${ test_id } "
${ CLICKHOUSE_CLIENT } --query " ${ query } " 2>& 1 | grep -Fc " ${ error_message } "
2022-07-05 18:03:51 +00:00
}
function performFileExists( )
{
local test_id = $1
local query = $2
2022-07-14 20:14:46 +00:00
local error_message = $3
touch " ${ CLICKHOUSE_TMP } /test_into_outfile_and_stdout_ ${ test_id } .out "
2022-07-05 18:03:51 +00:00
2022-07-14 20:14:46 +00:00
echo " performing test: ${ test_id } "
${ CLICKHOUSE_CLIENT } --query " ${ query } " 2>& 1 | grep -Fc " ${ error_message } "
rm -f " ${ CLICKHOUSE_TMP } /test_into_outfile_and_stdout_ ${ test_id } .out "
}
2022-07-05 18:03:51 +00:00
2022-07-14 20:14:46 +00:00
function performCompression( )
{
local test_id = $1
local query = $2
echo " performing test: ${ test_id } "
${ CLICKHOUSE_CLIENT } --query " ${ query } "
2022-07-05 18:03:51 +00:00
if [ " $? " -eq 0 ] ; then
2022-07-14 20:14:46 +00:00
gunzip " ${ CLICKHOUSE_TMP } /test_into_outfile_and_stdout_ ${ test_id } .gz "
cat " ${ CLICKHOUSE_TMP } /test_into_outfile_and_stdout_ ${ test_id } "
2022-07-05 18:03:51 +00:00
else
echo "query failed"
fi
2022-07-14 20:14:46 +00:00
rm -f " ${ CLICKHOUSE_TMP } /test_into_outfile_and_stdout_ ${ test_id } "
2022-07-05 18:03:51 +00:00
}
2022-07-14 20:14:46 +00:00
2022-07-05 18:03:51 +00:00
perform "select" " SELECT 1, 2, 3 INTO OUTFILE ' ${ CLICKHOUSE_TMP } /test_into_outfile_and_stdout_select.out' AND STDOUT "
2022-07-14 20:14:46 +00:00
performBadQuery "bad_query_incorrect_usage" " SELECT 1, 2, 3 INTO OUTFILE AND STDOUT' ${ CLICKHOUSE_TMP } /test_into_outfile_and_stdout_bad_query_incorrect_usage.out' " "SYNTAX_ERROR"
performBadQuery "bad_query_no_into_outfile" "SELECT 1, 2, 3 AND STDOUT'" "SYNTAX_ERROR"
2023-06-21 01:25:38 +00:00
performFileExists "bad_query_file_exists" " SELECT 1, 2, 3 INTO OUTFILE ' ${ CLICKHOUSE_TMP } /test_into_outfile_and_stdout_bad_query_file_exists.out' AND STDOUT " " File ${ CLICKHOUSE_TMP } /test_into_outfile_and_stdout_bad_query_file_exists.out exists, consider using APPEND or TRUNCATE. "
2022-07-14 20:14:46 +00:00
performCompression "compression" " SELECT * FROM (SELECT 'Hello, World! From clickhouse.') INTO OUTFILE ' ${ CLICKHOUSE_TMP } /test_into_outfile_and_stdout_compression.gz' AND STDOUT COMPRESSION 'GZ' FORMAT TabSeparated "
2022-07-05 18:03:51 +00:00
2022-07-14 20:14:46 +00:00
performBadQuery "bad_query_misplaced_compression" "SELECT 1, 2, 3 INTO OUTFILE 'test.gz' COMPRESSION 'GZ' AND STDOUT'" "SYNTAX_ERROR"
2022-07-05 18:03:51 +00:00
2022-07-17 18:09:18 +00:00
performBadQuery "bad_query_misplaced_format" "SELECT 1, 2, 3 INTO OUTFILE 'test.gz' FORMAT TabSeparated AND STDOUT'" "SYNTAX_ERROR"
perform "union_all" " SELECT 3, 4 UNION ALL SELECT 1, 2 INTO OUTFILE ' ${ CLICKHOUSE_TMP } /test_into_outfile_and_stdout_union_all.out' AND STDOUT "