1 | #pragma once |
---|---|
2 | |
3 | #include <Core/Block.h> |
4 | #include <Processors/Formats/IRowOutputFormat.h> |
5 | #include <Formats/FormatSettings.h> |
6 | |
7 | |
8 | namespace DB |
9 | { |
10 | |
11 | class WriteBuffer; |
12 | |
13 | |
14 | /** The stream for outputting data in csv format. |
15 | * Does not conform with https://tools.ietf.org/html/rfc4180 because it uses LF, not CR LF. |
16 | */ |
17 | class CSVRowOutputFormat : public IRowOutputFormat |
18 | { |
19 | public: |
20 | /** with_names - output in the first line a header with column names |
21 | * with_types - output in the next line header with the names of the types |
22 | */ |
23 | CSVRowOutputFormat(WriteBuffer & out_, const Block & header_, bool with_names_, FormatFactory::WriteCallback callback, const FormatSettings & format_settings_); |
24 | |
25 | String getName() const override { return "CSVRowOutputFormat"; } |
26 | |
27 | void writeField(const IColumn & column, const IDataType & type, size_t row_num) override; |
28 | void writeFieldDelimiter() override; |
29 | void writeRowEndDelimiter() override; |
30 | void writePrefix() override; |
31 | void writeBeforeTotals() override; |
32 | void writeBeforeExtremes() override; |
33 | |
34 | /// https://www.iana.org/assignments/media-types/text/csv |
35 | String getContentType() const override |
36 | { |
37 | return String("text/csv; charset=UTF-8; header=") + (with_names ? "present": "absent"); |
38 | } |
39 | |
40 | protected: |
41 | |
42 | bool with_names; |
43 | const FormatSettings format_settings; |
44 | DataTypes data_types; |
45 | }; |
46 | |
47 | } |
48 |