2018-05-24 01:02:16 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-08-20 11:17:57 +00:00
|
|
|
#include <Formats/FormatFactory.h>
|
2018-05-24 01:02:16 +00:00
|
|
|
#include <Processors/Formats/IOutputFormat.h>
|
|
|
|
|
2019-08-20 11:17:57 +00:00
|
|
|
#include <string>
|
|
|
|
|
2018-05-24 01:02:16 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class WriteBuffer;
|
|
|
|
|
|
|
|
/** Output format that writes data row by row.
|
|
|
|
*/
|
|
|
|
class IRowOutputFormat : public IOutputFormat
|
|
|
|
{
|
2021-10-20 20:47:50 +00:00
|
|
|
public:
|
2022-10-28 16:41:10 +00:00
|
|
|
/// Used to work with IRowOutputFormat explicitly.
|
|
|
|
void writeRow(const Columns & columns, size_t row_num)
|
|
|
|
{
|
|
|
|
first_row = false;
|
|
|
|
write(columns, row_num);
|
|
|
|
}
|
2021-10-20 20:47:50 +00:00
|
|
|
|
2022-10-28 16:41:10 +00:00
|
|
|
virtual void writeRowBetweenDelimiter() {} /// delimiter between rows
|
2022-09-09 17:42:33 +00:00
|
|
|
|
2018-05-24 01:02:16 +00:00
|
|
|
protected:
|
2022-10-28 16:41:10 +00:00
|
|
|
IRowOutputFormat(const Block & header, WriteBuffer & out_);
|
2019-02-18 16:36:07 +00:00
|
|
|
void consume(Chunk chunk) override;
|
|
|
|
void consumeTotals(Chunk chunk) override;
|
|
|
|
void consumeExtremes(Chunk chunk) override;
|
2018-05-24 01:02:16 +00:00
|
|
|
|
2022-09-12 17:21:40 +00:00
|
|
|
virtual bool supportTotals() const { return false; }
|
|
|
|
virtual bool supportExtremes() const { return false; }
|
|
|
|
|
2022-10-28 16:41:10 +00:00
|
|
|
/** 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);
|
2018-05-24 01:02:16 +00:00
|
|
|
|
|
|
|
/** 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;
|
2018-05-24 01:02:16 +00:00
|
|
|
|
|
|
|
/** 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
|
2021-11-17 20:51:46 +00:00
|
|
|
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() {}
|
2021-11-17 20:51:46 +00:00
|
|
|
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;
|
2018-05-24 01:02:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|