Failing case corrected and test added

This commit is contained in:
Alfonso Martinez 2022-10-25 17:40:54 +02:00
parent efd47c9eff
commit 8ef07bac89
3 changed files with 26 additions and 7 deletions

View File

@ -1303,13 +1303,27 @@ public:
static bool insertResultToColumn(IColumn & dest, const Element & element, std::string_view)
{
ColumnString & col_str = assert_cast<ColumnString &>(dest);
auto & chars = col_str.getChars();
WriteBufferFromVector<ColumnString::Chars> buf(chars, AppendModeTag());
traverse(element, buf);
buf.finalize();
chars.push_back(0);
col_str.getOffsets().push_back(chars.size());
if (dest.getDataType() == TypeIndex::LowCardinality)
{
ColumnString::Chars chars;
WriteBufferFromVector<ColumnString::Chars> buf(chars, AppendModeTag());
chars.push_back(0);
traverse(element, buf);
buf.finalize();
std::string str = reinterpret_cast<const char *>(chars.data());
chars.push_back(0);
assert_cast<ColumnLowCardinality &>(dest).insertData(str.data(), str.size());
}
else
{
ColumnString & col_str = assert_cast<ColumnString &>(dest);
auto & chars = col_str.getChars();
WriteBufferFromVector<ColumnString::Chars> buf(chars, AppendModeTag());
traverse(element, buf);
buf.finalize();
chars.push_back(0);
col_str.getOffsets().push_back(chars.size());
}
return true;
}

View File

@ -0,0 +1,2 @@
('{"b":{"c":1,"d":"str"}}','','','')
('{"b":{"c":1,"d":"str"}}','','','')

View File

@ -0,0 +1,3 @@
-- Tags: no-fasttest
SELECT JSONExtract('{"a" : {"b" : {"c" : 1, "d" : "str"}}}', 'Tuple( a LowCardinality(String), b LowCardinality(String), c LowCardinality(String), d LowCardinality(String))');
SELECT JSONExtract('{"a" : {"b" : {"c" : 1, "d" : "str"}}}', 'Tuple( a String, b LowCardinality(String), c LowCardinality(String), d LowCardinality(String))');