Merge pull request #22527 from ClickHouse/fix-missing-nl-parse-tsv

Fix deserialization of empty string without newline at end of TSV format
This commit is contained in:
alexey-milovidov 2021-04-03 12:51:10 +03:00 committed by GitHub
commit 143f4b59a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 5 deletions

View File

@ -224,12 +224,9 @@ ReturnType SerializationNullable::deserializeTextEscapedImpl(IColumn & column, R
{
/// Little tricky, because we cannot discriminate null from first character.
if (istr.eof())
throw ParsingException("Unexpected end of stream, while parsing value of Nullable type", ErrorCodes::CANNOT_READ_ALL_DATA);
/// This is not null, surely.
if (*istr.position() != '\\')
if (istr.eof() || *istr.position() != '\\') /// Some data types can deserialize absence of data (e.g. empty string), so eof is ok.
{
/// This is not null, surely.
return safeDeserialize<ReturnType>(column, *nested,
[] { return false; },
[&nested, &istr, &settings] (IColumn & nested_column) { nested->deserializeTextEscaped(nested_column, istr, settings); });

View File

@ -0,0 +1,6 @@
1
1
1
1
1
1

View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
printf '1\t' | $CLICKHOUSE_LOCAL --query="SELECT * FROM table" --structure='a String, b String'
printf '1\t' | $CLICKHOUSE_LOCAL --input_format_null_as_default 0 --query="SELECT * FROM table" --structure='a String, b String'
printf '1\t' | $CLICKHOUSE_LOCAL --input_format_null_as_default 1 --query="SELECT * FROM table" --structure='a String, b String'
printf '1\t' | $CLICKHOUSE_LOCAL --query="SELECT * FROM table" --structure='a String, b Nullable(String)'
printf '1\t' | $CLICKHOUSE_LOCAL --input_format_null_as_default 0 --query="SELECT * FROM table" --structure='a String, b Nullable(String)'
printf '1\t' | $CLICKHOUSE_LOCAL --input_format_null_as_default 1 --query="SELECT * FROM table" --structure='a Nullable(String), b Nullable(String)'