2019-10-07 16:08:07 +00:00
#!/usr/bin/env bash
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
2019-10-07 16:08:07 +00:00
$CLICKHOUSE_CLIENT --query= "DROP TABLE IF EXISTS null_as_default" ;
2022-03-04 07:04:43 +00:00
$CLICKHOUSE_CLIENT --query= "DROP TABLE IF EXISTS default_by_other_column" ;
2019-10-07 16:08:07 +00:00
$CLICKHOUSE_CLIENT --query= "CREATE TABLE null_as_default (i Int8, s String DEFAULT 'Hello', n UInt64 DEFAULT 42, d Date DEFAULT '2019-06-19', a Array(UInt8) DEFAULT [1, 2, 3], t Tuple(String, Float64) DEFAULT ('default', i / 4)) ENGINE = Memory" ;
2022-03-04 07:04:43 +00:00
$CLICKHOUSE_CLIENT --query= "CREATE TABLE default_by_other_column (a Float32 DEFAULT 100, b Float64 DEFAULT a, c Tuple(String, Float64) DEFAULT ('default', b / 4)) ENGINE = Memory" ;
2019-10-07 16:08:07 +00:00
echo 'CSV'
echo ' \N , 1, \N , "2019-07-22" , "[10, 20, 30]" , \N
1, world, 3, "2019-07-23" , \N , tuple, 3.14
2, \N , 123, \N , "[]" , test, 2.71828
3, \N , \N , \N , \N , \N ' | $CLICKHOUSE_CLIENT --input_format_null_as_default= 1 --query= "INSERT INTO null_as_default FORMAT CSV" ;
$CLICKHOUSE_CLIENT --query= "SELECT * FROM null_as_default ORDER BY i" ;
$CLICKHOUSE_CLIENT --query= "TRUNCATE TABLE null_as_default" ;
echo 'TSV'
echo -e ' \N \t 1\t \N \t 2019-07-22\t [ 10, 20, 30] \t \N
1\t world\t 3\t 2019-07-23\t \N \t ( '\' 'tuple' \' ' , 3.14)
2\t \N \t 123\t \N \t [ ] \t ( '\' 'test' \' ' , 2.71828)
3\t \N \t \N \t \N \t \N \t \N ' | $CLICKHOUSE_CLIENT --input_format_null_as_default= 1 --query= "INSERT INTO null_as_default FORMAT TSV" ;
$CLICKHOUSE_CLIENT --query= "SELECT * FROM null_as_default ORDER BY i" ;
$CLICKHOUSE_CLIENT --query= "TRUNCATE TABLE null_as_default" ;
echo 'TSKV'
echo -e ' i = \N \t s= 1\t n= \N \t d= 2019-07-22\t a= [ 10, 20, 30] \t t= \N
i = 1\t s= world\t n= 3\t d= 2019-07-23\t a= \N \t t= ( '\' 'tuple' \' ' , 3.14)
i = 2\t s= \N \t n= 123\t d= \N \t a= [ ] \t t= ( '\' 'test' \' ' , 2.71828)
i = 3\t s= \N \t n= \N \t d= \N \t a= \N \t t= \N ' | $CLICKHOUSE_CLIENT --input_format_null_as_default= 1 --query= "INSERT INTO null_as_default FORMAT TSKV" ;
$CLICKHOUSE_CLIENT --query= "SELECT * FROM null_as_default ORDER BY i" ;
$CLICKHOUSE_CLIENT --query= "TRUNCATE TABLE null_as_default" ;
echo 'JSONEachRow'
echo ' { "i" : null, "s" : "1" , "n" : null, "d" : "2019-07-22" , "a" : [ 10, 20, 30] , "t" : null}
{ "i" : 1, "s" : "world" , "n" : 3, "d" : "2019-07-23" , "a" : null, "t" : [ "tuple" , 3.14] }
{ "i" : 2, "s" : null, "n" : 123, "d" : null, "a" : [ ] , "t" : [ "test" , 2.71828] }
{ "i" : 3, "s" : null, "n" : null, "d" : null, "a" : null, "t" : null} ' | $CLICKHOUSE_CLIENT --input_format_null_as_default= 1 --query= "INSERT INTO null_as_default FORMAT JSONEachRow" ;
$CLICKHOUSE_CLIENT --query= "SELECT * FROM null_as_default ORDER BY i" ;
$CLICKHOUSE_CLIENT --query= "TRUNCATE TABLE null_as_default" ;
2020-09-09 06:20:14 +00:00
echo 'JSONStringsEachRow'
echo ' { "i" : "null" , "s" : "1" , "n" : "ᴺᵁᴸᴸ" , "d" : "2019-07-22" , "a" : "[10, 20, 30]" , "t" : "NULL" }
{ "i" : "1" , "s" : "world" , "n" : "3" , "d" : "2019-07-23" , "a" : "null" , "t" : "('\''tuple'\'', 3.14)" }
{ "i" : "2" , "s" : "null" , "n" : "123" , "d" : "null" , "a" : "[]" , "t" : "('\''test'\'', 2.71828)" }
{ "i" : "3" , "s" : "null" , "n" : "null" , "d" : "null" , "a" : "null" , "t" : "null" } ' | $CLICKHOUSE_CLIENT --input_format_null_as_default= 1 --query= "INSERT INTO null_as_default FORMAT JSONStringsEachRow" ;
$CLICKHOUSE_CLIENT --query= "SELECT * FROM null_as_default ORDER BY i" ;
$CLICKHOUSE_CLIENT --query= "TRUNCATE TABLE null_as_default" ;
2019-10-07 16:08:07 +00:00
echo 'Template (Quoted)'
echo 'NULL, ' \' '1' \' ', null, ' \' '2019-07-22' \' ' , [ 10, 20, 30] , NuLl
1, '\' 'world' \' ', 3, ' \' '2019-07-23' \' ', NULL, (' \' 'tuple' \' ' , 3.14)
2, null, 123, null, [ ] , ( '\' 'test' \' ' , 2.71828)
3, null, null, null, null, null' | $CLICKHOUSE_CLIENT --input_format_null_as_default=1 --format_custom_escaping_rule=Quoted --format_custom_field_delimiter=' , ' --query= "INSERT INTO null_as_default FORMAT CustomSeparated" ;
$CLICKHOUSE_CLIENT --query= "SELECT * FROM null_as_default ORDER BY i" ;
2019-10-16 19:52:00 +00:00
$CLICKHOUSE_CLIENT --query= "TRUNCATE TABLE null_as_default" ;
echo 'Values'
echo '(NULL, ' \' '1' \' ', (null), ' \' '2019-07-22' \' ' , ( [ 10, 20, 30] ) , ( NuLl) ) ,
2021-09-11 12:37:25 +00:00
( 1, '\' 'world' \' ', (3), ' \' '2019-07-23' \' ', (NULL), (' \' 'tuple' \' ' , 3.14) ) ,
( 2, null, ( 123) , null, ( [ ] ) , ( '\' 'test' \' ' , 2.71828) ) ,
2019-12-16 10:24:02 +00:00
( 3, null, ( null) , null, ( null) , ( null) ) ' | $CLICKHOUSE_CLIENT --input_format_null_as_default= 1 --query= "INSERT INTO null_as_default VALUES" ;
2019-10-16 19:52:00 +00:00
$CLICKHOUSE_CLIENT --query= "SELECT * FROM null_as_default ORDER BY i" ;
2019-10-07 16:08:07 +00:00
$CLICKHOUSE_CLIENT --query= "DROP TABLE null_as_default" ;
2022-03-04 07:04:43 +00:00
echo 'default_by_other_column'
$CLICKHOUSE_CLIENT --input_format_null_as_default= 1 --query= "INSERT INTO default_by_other_column(c) VALUES(null)" ;
$CLICKHOUSE_CLIENT --input_format_null_as_default= 1 --query= "INSERT INTO default_by_other_column(b, c) VALUES(null, null)" ;
$CLICKHOUSE_CLIENT --input_format_null_as_default= 1 --query= "INSERT INTO default_by_other_column(a, b, c) VALUES(null, null, null)" ;
$CLICKHOUSE_CLIENT --input_format_null_as_default= 1 --query= "INSERT INTO default_by_other_column(a) VALUES(10)" ;
$CLICKHOUSE_CLIENT --input_format_null_as_default= 1 --query= "INSERT INTO default_by_other_column(a, b, c) VALUES(1, 2, ('tuple', 3))" ;
$CLICKHOUSE_CLIENT --query= "SELECT * FROM default_by_other_column ORDER BY a" ;
$CLICKHOUSE_CLIENT --query= "DROP TABLE default_by_other_column" ;