1#pragma once
2
3#include <Core/Block.h>
4#include <IO/Progress.h>
5#include <IO/WriteBuffer.h>
6#include <Common/Stopwatch.h>
7#include <Formats/FormatSettings.h>
8#include <Processors/Formats/IRowOutputFormat.h>
9
10
11namespace DB
12{
13
14/** A stream for outputting data in XML format.
15 */
16class XMLRowOutputFormat : public IRowOutputFormat
17{
18public:
19 XMLRowOutputFormat(WriteBuffer & out_, const Block & header_, FormatFactory::WriteCallback callback, const FormatSettings & format_settings_);
20
21 String getName() const override { return "XMLRowOutputFormat"; }
22
23 void writeField(const IColumn & column, const IDataType & type, size_t row_num) override;
24 void writeRowStartDelimiter() override;
25 void writeRowEndDelimiter() override;
26 void writePrefix() override;
27 void writeSuffix() override;
28 void writeLastSuffix() override;
29
30 void writeMinExtreme(const Columns & columns, size_t row_num) override;
31 void writeMaxExtreme(const Columns & columns, size_t row_num) override;
32 void writeTotals(const Columns & columns, size_t row_num) override;
33
34 void writeBeforeTotals() override;
35 void writeAfterTotals() override;
36 void writeBeforeExtremes() override;
37 void writeAfterExtremes() override;
38
39 void flush() override
40 {
41 ostr->next();
42
43 if (validating_ostr)
44 out.next();
45 }
46
47 void setRowsBeforeLimit(size_t rows_before_limit_) override
48 {
49 applied_limit = true;
50 rows_before_limit = rows_before_limit_;
51 }
52
53 void onProgress(const Progress & value) override;
54
55 String getContentType() const override { return "application/xml; charset=UTF-8"; }
56
57protected:
58 void writeExtremesElement(const char * title, const Columns & columns, size_t row_num);
59 void writeRowsBeforeLimitAtLeast();
60 void writeStatistics();
61
62 std::unique_ptr<WriteBuffer> validating_ostr; /// Validates UTF-8 sequences, replaces bad sequences with replacement character.
63 WriteBuffer * ostr;
64
65 size_t field_number = 0;
66 size_t row_count = 0;
67 bool applied_limit = false;
68 size_t rows_before_limit = 0;
69 NamesAndTypes fields;
70 Names field_tag_names;
71
72 Progress progress;
73 Stopwatch watch;
74 const FormatSettings format_settings;
75};
76
77}
78