ClickHouse/src/Processors/Formats/IRowOutputFormat.h

71 lines
2.3 KiB
C++
Raw Normal View History

#pragma once
#include <Formats/FormatFactory.h>
#include <Processors/Formats/IOutputFormat.h>
#include <string>
namespace DB
{
class WriteBuffer;
/** Output format that writes data row by row.
*/
class IRowOutputFormat : public IOutputFormat
{
public:
/// Used to work with IRowOutputFormat explicitly.
void writeRow(const Columns & columns, size_t row_num)
{
first_row = false;
write(columns, row_num);
}
virtual void writeRowBetweenDelimiter() {} /// delimiter between rows
protected:
IRowOutputFormat(const Block & header, WriteBuffer & out_);
void consume(Chunk chunk) override;
void consumeTotals(Chunk chunk) override;
void consumeExtremes(Chunk chunk) override;
virtual bool supportTotals() const { return false; }
virtual bool supportExtremes() const { return false; }
/** Write a row.
* Default implementation calls methods to write single values and delimiters
* (except delimiter between rows (writeRowBetweenDelimiter())).
*/
virtual void write(const Columns & columns, size_t row_num);
2019-02-19 18:41:18 +00:00
virtual void writeMinExtreme(const Columns & columns, size_t row_num);
virtual void writeMaxExtreme(const Columns & columns, size_t row_num);
virtual void writeTotals(const Columns & columns, size_t row_num);
/** Write single value. */
2021-03-09 14:46:52 +00:00
virtual void writeField(const IColumn & column, const ISerialization & serialization, size_t row_num) = 0;
/** Write delimiter. */
2019-02-19 18:41:18 +00:00
virtual void writeFieldDelimiter() {} /// delimiter between values
virtual void writeRowStartDelimiter() {} /// delimiter before each row
virtual void writeRowEndDelimiter() {} /// delimiter after each row
2021-11-02 13:40:41 +00:00
virtual void writePrefix() override {} /// delimiter before resultset
virtual void writeSuffix() override {} /// delimiter after resultset
2019-02-19 18:41:18 +00:00
virtual void writeBeforeTotals() {}
virtual void writeAfterTotals() {}
virtual void writeBeforeExtremes() {}
virtual void writeAfterExtremes() {}
virtual void finalizeImpl() override {} /// Write something after resultset, totals end extremes.
2019-02-19 18:41:18 +00:00
2022-09-12 11:27:11 +00:00
bool haveWrittenData() { return !first_row || getRowsReadBefore() != 0; }
2022-02-06 04:14:01 +00:00
size_t num_columns;
2021-11-02 13:40:41 +00:00
DataTypes types;
Serializations serializations;
bool first_row = true;
};
}