aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Processors/Formats/Impl/JSONColumnsBlockOutputFormatBase.h
blob: 235a6d4da96d2b964eaac72e3d378b7fbf46a31a (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
#pragma once

#include <Core/Block.h>
#include <Processors/Formats/OutputFormatWithUTF8ValidationAdaptor.h>
#include <Formats/FormatSettings.h>
#include <IO/WriteBuffer.h>


namespace DB
{

class WriteBuffer;

/// Base class for Columnar JSON output formats.
/// It buffers all data and outputs it as a single block in writeSuffix() method.
class JSONColumnsBlockOutputFormatBase : public OutputFormatWithUTF8ValidationAdaptor
{
public:
    JSONColumnsBlockOutputFormatBase(WriteBuffer & out_, const Block & header_, const FormatSettings & format_settings_, bool validate_utf8);

    String getName() const override { return "JSONColumnsBlockOutputFormatBase"; }

protected:
    void consume(Chunk chunk) override;
    void writeSuffix() override;

    void writeChunk(Chunk & chunk);
    void writeColumn(const IColumn & column, const ISerialization & serialization);

    virtual void writeChunkStart() = 0;
    virtual void writeChunkEnd() = 0;
    virtual void writeColumnStart(size_t /*column_index*/) = 0;
    void writeColumnEnd(bool is_last);

    const FormatSettings format_settings;
    const Serializations serializations;

    Chunk mono_chunk;

    size_t written_rows = 0;
};

}