1#pragma once
2
3#include <Core/Block.h>
4#include <IO/WriteBuffer.h>
5#include <Processors/Formats/IRowOutputFormat.h>
6#include <Formats/FormatSettings.h>
7
8
9namespace DB
10{
11
12/** The stream for outputting data in JSON format, by object per line.
13 * Does not validate UTF-8.
14 */
15class JSONCompactEachRowRowOutputFormat : public IRowOutputFormat
16{
17public:
18 JSONCompactEachRowRowOutputFormat(WriteBuffer & out_, const Block & header_, FormatFactory::WriteCallback callback, const FormatSettings & settings_, bool with_names);
19
20 String getName() const override { return "JSONCompactEachRowRowOutputFormat"; }
21
22 void writePrefix() override;
23
24 void writeBeforeTotals() override {}
25 void writeTotals(const Columns & columns, size_t row_num) override;
26 void writeAfterTotals() override {}
27
28 void writeField(const IColumn & column, const IDataType & type, size_t row_num) override;
29 void writeFieldDelimiter() override;
30 void writeRowStartDelimiter() override;
31 void writeRowEndDelimiter() override;
32
33protected:
34 void consumeTotals(Chunk) override;
35 /// No extremes.
36 void consumeExtremes(Chunk) override {}
37
38private:
39 FormatSettings settings;
40
41 NamesAndTypes fields;
42
43 bool with_names;
44};
45}
46