2022-04-03 07:52:44 +00:00
#!/usr/bin/env bash
CUR_DIR = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
# shellcheck source=../shell_config.sh
. " $CUR_DIR " /../shell_config.sh
function run_format( )
{
local q = " $1 " && shift
2023-08-05 11:47:57 +00:00
echo " [multi] $q "
2022-04-04 08:09:22 +00:00
$CLICKHOUSE_FORMAT " $@ " <<< " $q "
2022-04-03 07:52:44 +00:00
}
function run_format_both( )
{
local q = " $1 " && shift
echo " [multi] $q "
2022-04-04 08:09:22 +00:00
$CLICKHOUSE_FORMAT " $@ " <<< " $q "
2022-04-03 07:52:44 +00:00
echo " [oneline] $q "
2022-04-04 08:09:22 +00:00
$CLICKHOUSE_FORMAT --oneline " $@ " <<< " $q "
2022-04-03 07:52:44 +00:00
}
# NOTE: that those queries may work slow, due to stack trace obtaining
2023-08-05 11:47:57 +00:00
run_format 'insert into foo settings max_threads=1' | & grep --max-count 2 --only-matching -e "Syntax error (query): failed at position .* (end of query):" -e '^\[.*$'
2023-08-05 11:54:36 +00:00
2022-04-04 08:09:22 +00:00
# compatibility
2023-12-27 17:13:56 +00:00
run_format 'insert into foo format tsv settings max_threads=1' | & grep --max-count 2 --only-matching -e "NOT_IMPLEMENTED" -e '^\[.*$'
2022-04-04 08:09:22 +00:00
run_format_both 'insert into foo format tsv settings max_threads=1' --allow_settings_after_format_in_insert
2023-08-05 11:47:57 +00:00
run_format 'insert into foo settings max_threads=1 format tsv settings max_threads=1' --allow_settings_after_format_in_insert | & grep --max-count 2 --only-matching -e "You have SETTINGS before and after FORMAT" -e '^\[.*$'
2023-08-05 11:54:36 +00:00
2022-04-04 08:09:22 +00:00
# and via server (since this is a separate code path)
$CLICKHOUSE_CLIENT -q 'drop table if exists data_02263'
$CLICKHOUSE_CLIENT -q 'create table data_02263 (key Int) engine=Memory()'
2023-08-05 11:47:57 +00:00
$CLICKHOUSE_CLIENT -q 'insert into data_02263 format TSV settings max_threads=1 1' | & grep --max-count 1 -F --only-matching "Cannot parse input: expected '\n' before: 'settings max_threads=1 1'"
2022-04-04 08:09:22 +00:00
$CLICKHOUSE_CLIENT --allow_settings_after_format_in_insert= 1 -q 'insert into data_02263 format TSV settings max_threads=1 1'
$CLICKHOUSE_CLIENT -q 'select * from data_02263'
2023-08-05 11:47:57 +00:00
$CLICKHOUSE_CLIENT --allow_settings_after_format_in_insert= 1 -q 'insert into data_02263 settings max_threads=1 format tsv settings max_threads=1' | & grep --max-count 1 -F --only-matching "You have SETTINGS before and after FORMAT"
2022-04-04 08:09:22 +00:00
$CLICKHOUSE_CLIENT -q 'drop table data_02263'
2022-04-03 07:52:44 +00:00
run_format_both 'insert into foo values'
run_format_both 'insert into foo select 1'
run_format_both 'insert into foo watch bar'
run_format_both 'insert into foo format tsv'
run_format_both 'insert into foo settings max_threads=1 values'
run_format_both 'insert into foo settings max_threads=1 select 1'
run_format_both 'insert into foo settings max_threads=1 watch bar'
run_format_both 'insert into foo settings max_threads=1 format tsv'
run_format_both 'insert into foo select 1 settings max_threads=1'
run_format_both 'insert into foo settings max_threads=1 select 1 settings max_threads=1'