Merge pull request #22863 from kitaisreal/data-type-low-cardinality-format-tsv-parsing-issue

DataTypeLowCardinality format tsv parsing issue
This commit is contained in:
alexey-milovidov 2021-04-09 09:50:50 +03:00 committed by GitHub
commit ee9b53a342
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View File

@ -7,6 +7,7 @@
#include <Formats/verbosePrintString.h>
#include <Formats/FormatFactory.h>
#include <DataTypes/DataTypeNothing.h>
#include <DataTypes/DataTypeLowCardinality.h>
#include <DataTypes/Serializations/SerializationNullable.h>
namespace DB
@ -338,8 +339,10 @@ void TabSeparatedRowInputFormat::tryDeserializeField(const DataTypePtr & type, I
const auto & index = column_mapping->column_indexes_for_input_fields[file_column];
if (index)
{
bool can_be_parsed_as_null = removeLowCardinality(type)->isNullable();
// check null value for type is not nullable. don't cross buffer bound for simplicity, so maybe missing some case
if (!type->isNullable() && !in.eof())
if (!can_be_parsed_as_null && !in.eof())
{
if (*in.position() == '\\' && in.available() >= 2)
{

View File

@ -0,0 +1,22 @@
#!/usr/bin/env bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS nullable_low_cardinality_tsv_test;";
$CLICKHOUSE_CLIENT --multiquery --query="CREATE TABLE nullable_low_cardinality_tsv_test
(
A Date,
S LowCardinality(Nullable(String)),
X Int32,
S1 LowCardinality(Nullable(String)),
S2 Array(String)
) ENGINE=TinyLog";
printf '2020-01-01\t\N\t32\t\N\n' | $CLICKHOUSE_CLIENT -q 'insert into nullable_low_cardinality_tsv_test format TSV' 2>&1 \
| grep -q "Code: 27"
echo $?;
$CLICKHOUSE_CLIENT --query="DROP TABLE nullable_low_cardinality_tsv_test";