mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
Merge pull request #46053 from ucasfl/json-columns
Closes https://github.com/ClickHouse/ClickHouse/issues/46024
This commit is contained in:
commit
5686703e79
@ -8,7 +8,7 @@ namespace DB
|
||||
{
|
||||
|
||||
JSONColumnsBlockOutputFormat::JSONColumnsBlockOutputFormat(WriteBuffer & out_, const Block & header_, const FormatSettings & format_settings_, bool validate_utf8, size_t indent_)
|
||||
: JSONColumnsBlockOutputFormatBase(out_, header_, format_settings_, validate_utf8), indent(indent_)
|
||||
: JSONColumnsBlockOutputFormatBase(out_, header_, format_settings_, validate_utf8), indent(indent_), header(header_)
|
||||
{
|
||||
names = JSONUtils::makeNamesValidJSONStrings(header_.getNames(), format_settings, validate_utf8);
|
||||
}
|
||||
@ -25,6 +25,18 @@ void JSONColumnsBlockOutputFormat::writeColumnStart(size_t column_index)
|
||||
|
||||
void JSONColumnsBlockOutputFormat::writeChunkEnd()
|
||||
{
|
||||
/// Write empty chunk
|
||||
if (!written_rows)
|
||||
{
|
||||
const auto & columns = header.getColumns();
|
||||
for (size_t i = 0; i != columns.size(); ++i)
|
||||
{
|
||||
writeColumnStart(i);
|
||||
writeColumn(*columns[i], *serializations[i]);
|
||||
writeColumnEnd(i == columns.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
JSONUtils::writeObjectEnd(*ostr, indent);
|
||||
writeChar('\n', *ostr);
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ protected:
|
||||
|
||||
Names names;
|
||||
size_t indent;
|
||||
|
||||
Block header;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ void JSONColumnsBlockOutputFormatBase::writeChunk(Chunk & chunk)
|
||||
writeColumn(*columns[i], *serializations[i]);
|
||||
writeColumnEnd(i == columns.size() - 1);
|
||||
}
|
||||
written_rows += chunk.getNumRows();
|
||||
writeChunkEnd();
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,8 @@ protected:
|
||||
const Serializations serializations;
|
||||
|
||||
Chunk mono_chunk;
|
||||
|
||||
size_t written_rows = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"n": [],
|
||||
"s": []
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
DROP TABLE IF EXISTS json_columns;
|
||||
|
||||
CREATE TABLE json_columns (n UInt32, s String) ENGINE = MergeTree order by n;
|
||||
|
||||
SELECT * FROM json_columns FORMAT JSONColumns;
|
Loading…
Reference in New Issue
Block a user