2019-04-22 13:31:17 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-08-01 01:14:25 +00:00
|
|
|
# shellcheck disable=SC2016
|
2019-04-22 13:31:17 +00:00
|
|
|
|
2019-04-22 13:42:52 +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
|
2019-04-22 13:31:17 +00:00
|
|
|
|
2020-12-04 02:15:44 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS tsv"
|
|
|
|
$CLICKHOUSE_CLIENT --query="CREATE TABLE tsv (d Date, u UInt8, str String) ENGINE = TinyLog"
|
2019-04-22 13:31:17 +00:00
|
|
|
|
2020-12-04 02:15:44 +00:00
|
|
|
INSERT_QUERY='$CLICKHOUSE_CLIENT --query="INSERT INTO tsv FORMAT TSVWithNames"'
|
2019-04-22 13:31:17 +00:00
|
|
|
USE_HEADER='--input_format_with_names_use_header=1'
|
|
|
|
SKIP_UNKNOWN='--input_format_skip_unknown_fields=1'
|
|
|
|
|
2019-04-22 13:42:52 +00:00
|
|
|
# Simple check for parsing
|
2020-08-01 00:56:32 +00:00
|
|
|
echo -ne 'd\tu\tstr\n2019-04-18\t42\tLine1\n2019-04-18\t42\tLine2' | eval "$INSERT_QUERY"
|
|
|
|
echo -ne 'd\tu\tstr\n2019-04-18\t42\tLine3\n2019-04-18\t42\tLine4' | eval "$INSERT_QUERY" $USE_HEADER
|
|
|
|
echo -ne 'd\tu\tstr\n2019-04-18\t42\tLine5\n2019-04-18\t42\tLine6' | eval "$INSERT_QUERY" $USE_HEADER $SKIP_UNKNOWN
|
2019-04-22 13:31:17 +00:00
|
|
|
|
2019-04-22 13:42:52 +00:00
|
|
|
# Random order of fields
|
2020-08-01 00:56:32 +00:00
|
|
|
echo -ne 'u\td\tstr\n42\t2019-04-18\tLine7\n' | eval "$INSERT_QUERY" $USE_HEADER
|
|
|
|
echo -ne 'u\tstr\td\n42\tLine8\t2019-04-18\n' | eval "$INSERT_QUERY" $USE_HEADER
|
|
|
|
echo -ne 'str\tu\td\nLine9\t42\t2019-04-18\n' | eval "$INSERT_QUERY" $USE_HEADER
|
2019-04-22 13:31:17 +00:00
|
|
|
|
2019-04-22 13:42:52 +00:00
|
|
|
# Excessive fields
|
2019-04-22 13:31:17 +00:00
|
|
|
echo -ne 'd\tu\tstr\tmore\tunknown\tfields\n2019-04-18\t1\tLine10\t\t\t\n2019-04-18\t2\tLine11\t\t\t\n' \
|
2020-08-01 00:56:32 +00:00
|
|
|
| eval "$INSERT_QUERY" $USE_HEADER $SKIP_UNKNOWN
|
2019-04-22 13:31:17 +00:00
|
|
|
echo -ne 'd\tunknown\tstr\tmore\tu\tfields\n2019-04-18\tblahblah\tLine12\t\t1\t\n2019-04-18\t\tLine13\tblahblah\t2\t\n' \
|
2020-08-01 00:56:32 +00:00
|
|
|
| eval "$INSERT_QUERY" $USE_HEADER $SKIP_UNKNOWN
|
2019-04-22 13:31:17 +00:00
|
|
|
|
2019-04-22 13:42:52 +00:00
|
|
|
# Missing fields (defaults)
|
2020-08-01 00:56:32 +00:00
|
|
|
echo -ne 'd\tu\n2019-04-18\t1\n2019-04-18\t2\n' | eval "$INSERT_QUERY" $USE_HEADER
|
|
|
|
echo -ne 'str\tu\nLine16\t1\nLine17\t2\n' | eval "$INSERT_QUERY" $USE_HEADER
|
|
|
|
echo -ne 'd\tstr\n2019-04-18\tLine18\n2019-04-18\tLine19\n'| eval "$INSERT_QUERY" $USE_HEADER
|
|
|
|
echo -ne 'unknown\n\n\n' | eval "$INSERT_QUERY" $USE_HEADER $SKIP_UNKNOWN
|
2019-04-22 13:31:17 +00:00
|
|
|
|
2020-12-04 02:15:44 +00:00
|
|
|
$CLICKHOUSE_CLIENT --query="SELECT * FROM tsv"
|
|
|
|
$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS tsv"
|