2019-02-19 18:41:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/Block.h>
|
|
|
|
#include <IO/WriteBuffer.h>
|
2022-09-20 13:49:17 +00:00
|
|
|
#include <Processors/Formats/OutputFormatWithUTF8ValidationAdaptor.h>
|
2019-02-19 18:41:18 +00:00
|
|
|
#include <Formats/FormatSettings.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** The stream for outputting data in JSON format, by object per line.
|
|
|
|
*/
|
2022-09-20 13:49:17 +00:00
|
|
|
class JSONEachRowRowOutputFormat : public RowOutputFormatWithUTF8ValidationAdaptor
|
2019-02-19 18:41:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-09-02 04:05:02 +00:00
|
|
|
JSONEachRowRowOutputFormat(
|
|
|
|
WriteBuffer & out_,
|
|
|
|
const Block & header_,
|
2020-10-07 18:51:10 +00:00
|
|
|
const RowOutputFormatParams & params_,
|
2020-11-17 19:50:47 +00:00
|
|
|
const FormatSettings & settings_);
|
2019-02-19 18:41:18 +00:00
|
|
|
|
|
|
|
String getName() const override { return "JSONEachRowRowOutputFormat"; }
|
|
|
|
|
2021-12-02 05:25:17 +00:00
|
|
|
/// Content-Type to set when sending HTTP response.
|
|
|
|
String getContentType() const override
|
2021-12-03 09:48:28 +00:00
|
|
|
{
|
2021-12-06 07:49:14 +00:00
|
|
|
return settings.json.array_of_rows ? "application/json; charset=UTF-8" : "application/x-ndjson; charset=UTF-8" ;
|
2021-12-02 05:25:17 +00:00
|
|
|
}
|
|
|
|
|
2021-11-02 13:40:41 +00:00
|
|
|
protected:
|
2021-03-09 14:46:52 +00:00
|
|
|
void writeField(const IColumn & column, const ISerialization & serialization, size_t row_num) override;
|
2019-02-19 18:41:18 +00:00
|
|
|
void writeFieldDelimiter() override;
|
|
|
|
void writeRowStartDelimiter() override;
|
|
|
|
void writeRowEndDelimiter() override;
|
2020-11-17 19:50:47 +00:00
|
|
|
void writeRowBetweenDelimiter() override;
|
|
|
|
void writePrefix() override;
|
|
|
|
void writeSuffix() override;
|
2019-02-19 18:41:18 +00:00
|
|
|
|
|
|
|
size_t field_number = 0;
|
2019-08-09 15:58:07 +00:00
|
|
|
|
|
|
|
private:
|
2019-02-19 18:41:18 +00:00
|
|
|
Names fields;
|
|
|
|
|
|
|
|
FormatSettings settings;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|