2016-12-21 20:04:27 +00:00
#!/usr/bin/env bash
2016-02-07 09:53:48 +00:00
2017-12-15 19:34:19 +00:00
CURDIR = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd )
2020-12-28 11:46:53 +00:00
# shellcheck source=../shell_config.sh
2020-08-01 00:51:12 +00:00
. " $CURDIR " /../shell_config.sh
2017-12-15 19:34:19 +00:00
2023-06-15 11:23:08 +00:00
echo = = = Test input_format_csv_empty_as_default
2019-04-16 14:13:13 +00:00
$CLICKHOUSE_CLIENT --query= "DROP TABLE IF EXISTS csv" ;
2019-06-20 12:46:36 +00:00
$CLICKHOUSE_CLIENT --query= "CREATE TABLE csv (s String, n UInt64 DEFAULT 1, d Date DEFAULT '2019-06-19') ENGINE = Memory" ;
2016-02-07 09:53:48 +00:00
2019-06-20 12:46:36 +00:00
printf ' "Hello, world" , 123, "2016-01-01"
2016-02-07 10:23:02 +00:00
"Hello, " "world" "" , "456" , 2016-01-02,
2017-04-05 11:52:23 +00:00
Hello "world" , 789 ,2016-01-03
2016-02-07 09:53:48 +00:00
" Hello
2019-06-20 12:46:36 +00:00
world" , 100, 2016-01-04,
default,,
2021-10-14 10:32:49 +00:00
default-eof,,' | $CLICKHOUSE_CLIENT --input_format_defaults_for_omitted_fields= 1 --input_format_csv_empty_as_default= 1 --query= "INSERT INTO csv FORMAT CSV" ;
2016-02-07 09:53:48 +00:00
2022-02-02 16:49:44 +00:00
$CLICKHOUSE_CLIENT --query= "SELECT * FROM csv ORDER BY d, s" ;
2019-04-16 14:13:13 +00:00
$CLICKHOUSE_CLIENT --query= "DROP TABLE csv" ;
2017-08-15 10:20:05 +00:00
2023-06-15 11:23:08 +00:00
echo = = = Test datetime
2022-03-11 23:45:26 +00:00
$CLICKHOUSE_CLIENT --query= "CREATE TABLE csv (t DateTime('Asia/Istanbul'), s String) ENGINE = Memory" ;
2017-08-15 10:20:05 +00:00
echo ' "2016-01-01 01:02:03" ,"1"
2016-01-02 01:02:03, "2"
1502792101,"3"
2019-04-16 14:13:13 +00:00
99999,"4" ' | $CLICKHOUSE_CLIENT --query= "INSERT INTO csv FORMAT CSV" ;
2017-08-15 10:20:05 +00:00
2019-04-16 14:13:13 +00:00
$CLICKHOUSE_CLIENT --query= "SELECT * FROM csv ORDER BY s" ;
$CLICKHOUSE_CLIENT --query= "DROP TABLE csv" ;
2019-07-18 15:54:58 +00:00
2023-06-15 11:23:08 +00:00
echo = = = Test nullable datetime
2022-03-11 23:45:26 +00:00
$CLICKHOUSE_CLIENT --query= "CREATE TABLE csv (t Nullable(DateTime('Asia/Istanbul')), s Nullable(String)) ENGINE = Memory" ;
2019-07-18 15:54:58 +00:00
echo ' NULL, NULL
"2016-01-01 01:02:03" ,NUL
2021-11-02 09:15:21 +00:00
"2016-01-02 01:02:03" ,Nhello' | $CLICKHOUSE_CLIENT --format_csv_null_representation=' NULL' --input_format_csv_empty_as_default= 1 --query= "INSERT INTO csv FORMAT CSV" ;
2019-07-18 15:54:58 +00:00
2019-07-23 13:37:52 +00:00
$CLICKHOUSE_CLIENT --query= "SELECT * FROM csv ORDER BY s NULLS LAST" ;
$CLICKHOUSE_CLIENT --query= "DROP TABLE csv" ;
2023-06-14 10:35:36 +00:00
2023-07-06 07:32:46 +00:00
echo = = = Test ignore extra columns
2023-06-14 16:44:31 +00:00
$CLICKHOUSE_CLIENT --query= "CREATE TABLE csv (s String, n UInt64 DEFAULT 3, d String DEFAULT 'String4') ENGINE = Memory" ;
2023-07-06 13:09:49 +00:00
echo ' "Hello" , 1, "String1"
2023-06-21 14:01:05 +00:00
"Hello" , 2, "String2" ,
"Hello" , 3, "String3" , "2016-01-13"
"Hello" , 4, , "2016-01-14"
"Hello" , 5, "String5" , "2016-01-15" , "2016-01-16"
2023-07-05 11:42:02 +00:00
"Hello" , 6, "String6" , " line with a
2023-07-06 07:32:46 +00:00
break" ' | $CLICKHOUSE_CLIENT --input_format_defaults_for_omitted_fields=1 --input_format_csv_empty_as_default=1 --input_format_csv_allow_variable_number_of_columns=1 --query= " INSERT INTO csv FORMAT CSV" ;
2023-06-14 10:35:36 +00:00
$CLICKHOUSE_CLIENT --query= "SELECT * FROM csv ORDER BY s, n" ;
2023-06-15 11:23:08 +00:00
$CLICKHOUSE_CLIENT --query= "DROP TABLE csv" ;
2023-07-06 07:32:46 +00:00
echo = = = Test missing as default
2023-06-19 09:51:29 +00:00
$CLICKHOUSE_CLIENT --query= "CREATE TABLE csv (f1 String, f2 UInt64, f3 UInt256, f4 UInt64 Default 33, f5 Nullable(UInt64), f6 Nullable(UInt64) Default 55, f7 String DEFAULT 'Default') ENGINE = Memory" ;
2023-06-15 11:23:08 +00:00
2023-06-19 10:48:38 +00:00
echo '
,
2023-06-21 06:25:11 +00:00
"Hello"
"Hello" ,
"Hello" , 1, 3, 2
"Hello" ,1,4,2,3,4,"String"
"Hello" , 1, 4, 2, 3, 4, "String"
2023-07-06 07:32:46 +00:00
"Hello" , 1, 5, 2, 3, 4, "String" ,' | $CLICKHOUSE_CLIENT --input_format_defaults_for_omitted_fields= 1 --input_format_csv_allow_variable_number_of_columns= 1 --query= "INSERT INTO csv FORMAT CSV" ;
2023-06-19 09:51:29 +00:00
$CLICKHOUSE_CLIENT --query= "SELECT * FROM csv ORDER BY f1, f2, f3, f4, f5 NULLS FIRST, f6, f7" ;
2023-06-15 11:23:08 +00:00
$CLICKHOUSE_CLIENT --query= "DROP TABLE csv" ;