fix tryDeserializeTextCSV

This commit is contained in:
shuai-xu 2024-03-15 18:10:02 +08:00
parent 9d5cabb26d
commit 5ca0699859
4 changed files with 10 additions and 33 deletions

View File

@ -542,34 +542,11 @@ void SerializationTuple::deserializeTextCSV(IColumn & column, ReadBuffer & istr,
bool SerializationTuple::tryDeserializeTextCSV(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const
{
return addElementSafe<bool>(elems.size(), column, [&]
{
const size_t size = elems.size();
for (size_t i = 0; i < size; ++i)
{
if (i != 0)
{
skipWhitespaceIfAny(istr);
if (!checkChar(settings.csv.tuple_delimiter, istr))
return false;
skipWhitespaceIfAny(istr);
}
auto & element_column = extractElementColumn(column, i);
if (settings.null_as_default && !isColumnNullableOrLowCardinalityNullable(element_column))
{
if (!SerializationNullable::tryDeserializeNullAsDefaultOrNestedTextCSV(element_column, istr, settings, elems[i]))
return false;
}
else
{
if (!elems[i]->tryDeserializeTextCSV(element_column, istr, settings))
return false;
}
}
return true;
});
String s;
if (!tryReadCSV(s, istr, settings.csv))
return false;
ReadBufferFromString rb(s);
return tryDeserializeText(column, rb, settings, true);
}
void SerializationTuple::enumerateStreams(

View File

@ -1,11 +1,11 @@
"Hello, ""World""",123,"[1,2,3]",456,"['abc','def']","Newline
"Hello, ""World""",123,"[1,2,3]","(456,['abc','def'])","Newline
here"
"x","y","z","a","b"
"Hello, ""World""",123,"[1,2,3]",456,"['abc','def']","Newline
"Hello, ""World""",123,"[1,2,3]","(456,['abc','def'])","Newline
here"
"x","y","z","a","b"
"String","UInt8","Array(UInt8)","Tuple(UInt16, Array(String))","String"
"Hello, ""World""",123,"[1,2,3]",456,"['abc','def']","Newline
"Hello, ""World""",123,"[1,2,3]","(456,['abc','def']","Newline
here"
0,"0","[]","2000-01-01","2000-01-01 00:00:00"
1,"1","[0]","2000-01-02","2000-01-01 00:00:01"

View File

@ -11,8 +11,8 @@ $CLICKHOUSE_CLIENT --query="CREATE TABLE default_by_other_column (a Float32 DEFA
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
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";