From 23e2d17d9dc18d2b039e7b0752eb162686179e17 Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Fri, 9 Aug 2019 18:58:07 +0300 Subject: [PATCH] Added JSONEachRowWithProgressRowOutputFormat. --- ...JSONEachRowWithProgressRowOutputStream.cpp | 47 ------------------- .../JSONEachRowWithProgressRowOutputStream.h | 27 ----------- .../Formats/Impl/JSONEachRowRowOutputFormat.h | 3 +- ...JSONEachRowWithProgressRowOutputFormat.cpp | 43 +++++++++++++++++ .../JSONEachRowWithProgressRowOutputFormat.h | 20 ++++++++ 5 files changed, 65 insertions(+), 75 deletions(-) delete mode 100644 dbms/src/Formats/JSONEachRowWithProgressRowOutputStream.cpp delete mode 100644 dbms/src/Formats/JSONEachRowWithProgressRowOutputStream.h create mode 100644 dbms/src/Processors/Formats/Impl/JSONEachRowWithProgressRowOutputFormat.cpp create mode 100644 dbms/src/Processors/Formats/Impl/JSONEachRowWithProgressRowOutputFormat.h diff --git a/dbms/src/Formats/JSONEachRowWithProgressRowOutputStream.cpp b/dbms/src/Formats/JSONEachRowWithProgressRowOutputStream.cpp deleted file mode 100644 index 4f59e99ff6..0000000000 --- a/dbms/src/Formats/JSONEachRowWithProgressRowOutputStream.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include -#include - - -namespace DB -{ - - -void JSONEachRowWithProgressRowOutputStream::writeRowStartDelimiter() -{ - writeCString("{\"row\":{", ostr); -} - - -void JSONEachRowWithProgressRowOutputStream::writeRowEndDelimiter() -{ - writeCString("}}\n", ostr); - field_number = 0; -} - - -void JSONEachRowWithProgressRowOutputStream::onProgress(const Progress & value) -{ - progress.incrementPiecewiseAtomically(value); - writeCString("{\"progress\":", ostr); - progress.writeJSON(ostr); - writeCString("}\n", ostr); -} - - -void registerOutputFormatJSONEachRowWithProgress(FormatFactory & factory) -{ - factory.registerOutputFormat("JSONEachRowWithProgress", []( - WriteBuffer & buf, - const Block & sample, - const Context &, - const FormatSettings & format_settings) - { - return std::make_shared( - std::make_shared(buf, sample, format_settings), sample); - }); -} - -} diff --git a/dbms/src/Formats/JSONEachRowWithProgressRowOutputStream.h b/dbms/src/Formats/JSONEachRowWithProgressRowOutputStream.h deleted file mode 100644 index e8cef8e147..0000000000 --- a/dbms/src/Formats/JSONEachRowWithProgressRowOutputStream.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include -#include - - -namespace DB -{ - -/** The stream for outputting data in JSON format, by object per line - * that includes progress rows. Does not validate UTF-8. - */ -class JSONEachRowWithProgressRowOutputStream : public JSONEachRowRowOutputStream -{ -public: - using JSONEachRowRowOutputStream::JSONEachRowRowOutputStream; - - void writeRowStartDelimiter() override; - void writeRowEndDelimiter() override; - void onProgress(const Progress & value) override; - -private: - Progress progress; -}; - -} - diff --git a/dbms/src/Processors/Formats/Impl/JSONEachRowRowOutputFormat.h b/dbms/src/Processors/Formats/Impl/JSONEachRowRowOutputFormat.h index a45f193ea3..de93d01276 100644 --- a/dbms/src/Processors/Formats/Impl/JSONEachRowRowOutputFormat.h +++ b/dbms/src/Processors/Formats/Impl/JSONEachRowRowOutputFormat.h @@ -29,8 +29,9 @@ protected: void consumeTotals(Chunk) override {} void consumeExtremes(Chunk) override {} -private: size_t field_number = 0; + +private: Names fields; FormatSettings settings; diff --git a/dbms/src/Processors/Formats/Impl/JSONEachRowWithProgressRowOutputFormat.cpp b/dbms/src/Processors/Formats/Impl/JSONEachRowWithProgressRowOutputFormat.cpp new file mode 100644 index 0000000000..d3d07f1dcb --- /dev/null +++ b/dbms/src/Processors/Formats/Impl/JSONEachRowWithProgressRowOutputFormat.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include + + +namespace DB +{ + + +void JSONEachRowWithProgressRowOutputFormat::writeRowStartDelimiter() +{ + writeCString("{\"row\":{", out); +} + +void JSONEachRowWithProgressRowOutputFormat::writeRowEndDelimiter() +{ + writeCString("}}\n", out); + field_number = 0; +} + +void JSONEachRowWithProgressRowOutputFormat::onProgress(const Progress & value) +{ + progress.incrementPiecewiseAtomically(value); + writeCString("{\"progress\":", out); + progress.writeJSON(out); + writeCString("}\n", out); +} + + +void registerOutputFormatProcessorJSONEachRow(FormatFactory & factory) +{ + factory.registerOutputFormatProcessor("JSONEachRowWithProgress", []( + WriteBuffer & buf, + const Block & sample, + const Context &, + const FormatSettings & format_settings) + { + return std::make_shared(buf, sample, format_settings); + }); +} + +} diff --git a/dbms/src/Processors/Formats/Impl/JSONEachRowWithProgressRowOutputFormat.h b/dbms/src/Processors/Formats/Impl/JSONEachRowWithProgressRowOutputFormat.h new file mode 100644 index 0000000000..3062d66419 --- /dev/null +++ b/dbms/src/Processors/Formats/Impl/JSONEachRowWithProgressRowOutputFormat.h @@ -0,0 +1,20 @@ +#pragma once +#include + +namespace DB +{ + +class JSONEachRowWithProgressRowOutputFormat : public JSONEachRowRowOutputFormat +{ +public: + using JSONEachRowRowOutputFormat::JSONEachRowRowOutputFormat; + + void writeRowStartDelimiter() override; + void writeRowEndDelimiter() override; + void onProgress(const Progress & value) override; + +private: + Progress progress; +}; + +} -- GitLab