```
/4/ :) SELECT arrayJoin([1, 2])  GROUP BY 1 WITH TOTALS FORMAT JSON

{
	"meta":
	[
		{
			"name": "arrayJoin([1, 2])",
			"type": "UInt8"
		}
	],

	"data":
	[
		{
			"arrayJoin([1, 2])": 1
		},
		{
			"arrayJoin([1, 2])": 2
		}← Progress: 0.00 rows, 0.00 B (0.00 rows/s., 0.00 B/s.) Logical error: 'Got 2 in totals chunk, expected 1'.
clickhouse-client: /home/akuzm/ch4/ch/src/Common/Exception.cpp:45: DB::Exception::Exception(const std::string &, int): Assertion `false' failed.
Aborted (core dumped)
```


ParsedTemplateFormatString format_, ParsedTemplateFormatString row_format_,
                                                     std::string row_between_delimiter_)
    : IOutputFormat(header_, out_), settings(settings_), format(std::move(format_))
    , row_format(std::move(row_format_)), row_between_delimiter(std::move(row_between_delimiter_))
{
    const auto & sample = getPort(PortKind::Main).getHeader();
    size_t columns = sample.columns();
    types.resize(columns);
    for (size_t i = 0; i < columns; ++i)
        types[i] = sample.safeGetByPosition(i).type;
    
    size_t data_idx = format.format_idx_to_column_idx.size() + 1;
    for (size_t i = 0; i < format.format_idx_to_column_idx.size(); ++i)
    {
        if (!format.format_idx_to_column_idx[i])
            format.throwInvalidFormat("Output part name cannot be empty.", i);
        switch (*format.format_idx_to_column_idx[i])
        {
            case static_cast<size_t>(ResultsetPart::Data):
                data_idx = i;
                [[fallthrough]];
            case static_cast<size_t>(ResultsetPart::Totals):
            case static_cast<size_t>(ResultsetPart::ExtremesMin):
            case static_cast<size_t>(ResultsetPart::ExtremesMax):
                if (format.formats[i] != ColumnFormat::None)
                    format.throwInvalidFormat("Serialization type for data, totals, min and max must be empty or None", i);
                break;