mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Improve format JSONColumns when result is empty
This commit is contained in:
parent
496cacf25e
commit
f89a6cf68d
@ -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