aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Processors/Formats/IRowOutputFormat.h
blob: 3a648f00eba547bdf9e36fcc43c2747b84e0a474 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#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);
    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. */
    virtual void writeField(const IColumn & column, const ISerialization & serialization, size_t row_num) = 0;

    /** Write delimiter. */
    virtual void writeFieldDelimiter() {}       /// delimiter between values
    virtual void writeRowStartDelimiter() {}    /// delimiter before each row
    virtual void writeRowEndDelimiter() {}      /// delimiter after each row
    virtual void writePrefix() override {}      /// delimiter before resultset
    virtual void writeSuffix() override {}      /// delimiter after resultset
    virtual void writeBeforeTotals() {}
    virtual void writeAfterTotals() {}
    virtual void writeBeforeExtremes() {}
    virtual void writeAfterExtremes() {}
    virtual void finalizeImpl() override {}  /// Write something after resultset, totals end extremes.

    bool haveWrittenData() { return !first_row || getRowsReadBefore() != 0; }

    size_t num_columns;
    DataTypes types;
    Serializations serializations;

    bool first_row = true;
};

}