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

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


namespace DB
{

/* Outputs data as a single JSON Object with rows as fields:
 * {
 *     "row_1": {"num": 42, "str": "hello", "arr": [0,1]},
 *     "row_2": {"num": 43, "str": "hello", "arr": [0,1,2]},
 *     "row_3": {"num": 44, "str": "hello", "arr": [0,1,2,3]},
 * }
 */

class JSONObjectEachRowRowOutputFormat : public JSONEachRowRowOutputFormat
{
public:
    JSONObjectEachRowRowOutputFormat(
        WriteBuffer & out_,
        const Block & header_,
        const FormatSettings & settings_);

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

private:
    void write(const Columns & columns, size_t row) override;
    void writeField(const IColumn & column, const ISerialization & serialization, size_t row) override;
    void writeFieldDelimiter() override;
    void writeRowStartDelimiter() override;
    void writeRowEndDelimiter() override;
    void writeRowBetweenDelimiter() override;

    void writePrefix() override;
    void writeSuffix() override;

    std::optional<size_t> field_index_for_object_name;
    String object_name;
    size_t rows = 0;
};

}