ClickHouse/dbms/src/Formats/CSVRowOutputStream.h
alexey-milovidov fafecb3c25
Better modularity of formats. (#2492)
* Formats: better modularity (development) #2447

* Formats: better modularity (development) #2447

* Formats: better modularity (development) #2447

* Formats: better modularity (development) #2447

* Formats: better modularity (development) #2447

* Formats: better modularity (development): removed very old tests #2447

* Formats: better modularity (development) #2447

* Formats: better modularity (development) #2447

* Formats: better modularity (development) #2447

* Formats: better modularity (development) #2447

* Formats: better modularity (development) #2447

* Formats: better modularity (development) #2447

* Formats: better modularity (development) #2447

* Formats: better modularity (development) #2447
2018-06-10 22:22:49 +03:00

57 lines
1.5 KiB
C++

#pragma once
#include <Core/Block.h>
#include <Formats/IRowOutputStream.h>
#include <Formats/FormatSettings.h>
namespace DB
{
class WriteBuffer;
/** The stream for outputting data in csv format.
* Does not conform with https://tools.ietf.org/html/rfc4180 because it uses LF, not CR LF.
*/
class CSVRowOutputStream : public IRowOutputStream
{
public:
/** with_names - output in the first line a header with column names
* with_types - output in the next line header with the names of the types
*/
CSVRowOutputStream(WriteBuffer & ostr_, const Block & sample_, bool with_names_, const FormatSettings & format_settings);
void writeField(const IColumn & column, const IDataType & type, size_t row_num) override;
void writeFieldDelimiter() override;
void writeRowEndDelimiter() override;
void writePrefix() override;
void writeSuffix() override;
void flush() override;
void setTotals(const Block & totals_) override { totals = totals_; }
void setExtremes(const Block & extremes_) override { extremes = extremes_; }
/// https://www.iana.org/assignments/media-types/text/csv
String getContentType() const override
{
return String("text/csv; charset=UTF-8; header=") + (with_names ? "present" : "absent");
}
protected:
void writeTotals();
void writeExtremes();
WriteBuffer & ostr;
const Block sample;
bool with_names;
const FormatSettings format_settings;
DataTypes data_types;
Block totals;
Block extremes;
};
}