2015-07-18 04:27:38 +00:00
|
|
|
#include <DB/IO/WriteHelpers.h>
|
|
|
|
#include <DB/DataStreams/TSKVRowOutputStream.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
TSKVRowOutputStream::TSKVRowOutputStream(WriteBuffer & ostr_, const Block & sample_)
|
2017-04-01 07:20:54 +00:00
|
|
|
: TabSeparatedRowOutputStream(ostr_, sample_)
|
2015-07-18 04:27:38 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
NamesAndTypesList columns(sample_.getColumnsList());
|
|
|
|
fields.assign(columns.begin(), columns.end());
|
|
|
|
|
|
|
|
for (auto & field : fields)
|
|
|
|
{
|
|
|
|
String prepared_field_name;
|
|
|
|
{
|
|
|
|
WriteBufferFromString wb(prepared_field_name);
|
|
|
|
writeAnyEscapedString<'='>(field.name.data(), field.name.data() + field.name.size(), wb);
|
|
|
|
writeCString("=", wb);
|
|
|
|
}
|
|
|
|
field.name = prepared_field_name;
|
|
|
|
}
|
2015-07-18 04:27:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-16 16:39:39 +00:00
|
|
|
void TSKVRowOutputStream::writeField(const IColumn & column, const IDataType & type, size_t row_num)
|
2015-07-18 04:27:38 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
writeString(fields[field_number].name, ostr);
|
|
|
|
type.serializeTextEscaped(column, row_num, ostr);
|
|
|
|
++field_number;
|
2015-07-18 04:27:38 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 16:39:39 +00:00
|
|
|
|
|
|
|
void TSKVRowOutputStream::writeRowEndDelimiter()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
writeChar('\n', ostr);
|
|
|
|
field_number = 0;
|
2016-02-16 16:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-18 04:27:38 +00:00
|
|
|
}
|