blob: 2de9369846b0f5ef175bd6887bb9f51fac3be550 (
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
|
#pragma once
#include <Core/Block.h>
#include <IO/WriteBuffer.h>
#include <IO/PeekableWriteBuffer.h>
#include <Processors/Formats/OutputFormatWithUTF8ValidationAdaptor.h>
#include <Processors/Formats/RowOutputFormatWithExceptionHandlerAdaptor.h>
#include <Formats/FormatSettings.h>
namespace DB
{
/** The stream for outputting data in JSON format, by object per line.
*/
class JSONEachRowRowOutputFormat : public RowOutputFormatWithExceptionHandlerAdaptor<RowOutputFormatWithUTF8ValidationAdaptor, bool>
{
public:
JSONEachRowRowOutputFormat(
WriteBuffer & out_,
const Block & header_,
const FormatSettings & settings_,
bool pretty_json_ = false);
String getName() const override { return "JSONEachRowRowOutputFormat"; }
/// Content-Type to set when sending HTTP response.
String getContentType() const override
{
return settings.json.array_of_rows ? "application/json; charset=UTF-8" : "application/x-ndjson; charset=UTF-8" ;
}
protected:
void writeField(const IColumn & column, const ISerialization & serialization, size_t row_num) override;
void writeFieldDelimiter() override;
void writeRowStartDelimiter() override;
void writeRowEndDelimiter() override;
void writeRowBetweenDelimiter() override;
void writePrefix() override;
void writeSuffix() override;
void resetFormatterImpl() override;
size_t field_number = 0;
bool pretty_json;
FormatSettings settings;
WriteBuffer * ostr;
private:
Names fields;
};
}
|