1#include <IO/WriteHelpers.h>
2#include <IO/WriteBufferValidUTF8.h>
3#include <Processors/Formats/Impl/JSONEachRowWithProgressRowOutputFormat.h>
4#include <Formats/FormatFactory.h>
5
6
7namespace DB
8{
9
10
11void JSONEachRowWithProgressRowOutputFormat::writeRowStartDelimiter()
12{
13 writeCString("{\"row\":{", out);
14}
15
16void JSONEachRowWithProgressRowOutputFormat::writeRowEndDelimiter()
17{
18 writeCString("}}\n", out);
19 field_number = 0;
20}
21
22void JSONEachRowWithProgressRowOutputFormat::onProgress(const Progress & value)
23{
24 progress.incrementPiecewiseAtomically(value);
25 writeCString("{\"progress\":", out);
26 progress.writeJSON(out);
27 writeCString("}\n", out);
28}
29
30
31void registerOutputFormatProcessorJSONEachRowWithProgress(FormatFactory & factory)
32{
33 factory.registerOutputFormatProcessor("JSONEachRowWithProgress", [](
34 WriteBuffer & buf,
35 const Block & sample,
36 FormatFactory::WriteCallback callback,
37 const FormatSettings & format_settings)
38 {
39 return std::make_shared<JSONEachRowWithProgressRowOutputFormat>(buf, sample, callback, format_settings);
40 });
41}
42
43}
44