ClickHouse/src/Processors/Formats/IRowOutputFormat.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

100 lines
2.2 KiB
C++
Raw Normal View History

#include <string>
#include <Processors/Formats/IRowOutputFormat.h>
2019-02-19 18:41:18 +00:00
#include <IO/WriteHelpers.h>
namespace DB
{
2020-02-25 18:10:48 +00:00
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
IRowOutputFormat::IRowOutputFormat(const Block & header, WriteBuffer & out_)
2021-03-09 14:46:52 +00:00
: IOutputFormat(header, out_)
2022-05-06 16:48:48 +00:00
, num_columns(header.columns())
2021-03-09 14:46:52 +00:00
, types(header.getDataTypes())
2022-05-06 16:48:48 +00:00
, serializations(header.getSerializations())
2021-03-09 14:46:52 +00:00
{
}
2019-02-19 18:41:18 +00:00
void IRowOutputFormat::consume(DB::Chunk chunk)
{
auto num_rows = chunk.getNumRows();
2020-04-22 06:34:20 +00:00
const auto & columns = chunk.getColumns();
2019-02-19 18:41:18 +00:00
2020-02-03 10:02:52 +00:00
for (size_t row = 0; row < num_rows; ++row)
2019-02-19 18:41:18 +00:00
{
2022-09-12 11:27:11 +00:00
if (haveWrittenData())
2019-02-19 18:41:18 +00:00
writeRowBetweenDelimiter();
write(columns, row);
2020-10-12 13:05:40 +00:00
first_row = false;
2019-02-19 18:41:18 +00:00
}
}
void IRowOutputFormat::consumeTotals(DB::Chunk chunk)
{
if (!supportTotals())
return;
2019-02-19 18:41:18 +00:00
auto num_rows = chunk.getNumRows();
if (num_rows != 1)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Got {} in totals chunk, expected 1", num_rows);
2019-02-19 18:41:18 +00:00
2020-04-22 06:34:20 +00:00
const auto & columns = chunk.getColumns();
2019-02-19 18:41:18 +00:00
writeBeforeTotals();
writeTotals(columns, 0);
writeAfterTotals();
}
void IRowOutputFormat::consumeExtremes(DB::Chunk chunk)
{
if (!supportExtremes())
return;
2019-02-19 18:41:18 +00:00
auto num_rows = chunk.getNumRows();
2020-04-22 06:34:20 +00:00
const auto & columns = chunk.getColumns();
2019-02-19 18:41:18 +00:00
if (num_rows != 2)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Got {} in extremes chunk, expected 2", num_rows);
2019-02-19 18:41:18 +00:00
writeBeforeExtremes();
writeMinExtreme(columns, 0);
writeRowBetweenDelimiter();
writeMaxExtreme(columns, 1);
writeAfterExtremes();
}
void IRowOutputFormat::write(const Columns & columns, size_t row_num)
{
writeRowStartDelimiter();
for (size_t i = 0; i < num_columns; ++i)
{
if (i != 0)
writeFieldDelimiter();
2021-03-09 14:46:52 +00:00
writeField(*columns[i], *serializations[i], row_num);
}
writeRowEndDelimiter();
}
2019-02-19 18:41:18 +00:00
void IRowOutputFormat::writeMinExtreme(const DB::Columns & columns, size_t row_num)
{
write(columns, row_num);
}
2023-02-19 22:15:09 +00:00
void IRowOutputFormat::writeMaxExtreme(const DB::Columns & columns, size_t row_num)
2019-02-19 18:41:18 +00:00
{
write(columns, row_num);
}
void IRowOutputFormat::writeTotals(const DB::Columns & columns, size_t row_num)
{
write(columns, row_num);
}
}