ClickHouse/dbms/src/DataStreams/TSKVRowOutputStream.cpp

41 lines
964 B
C++
Raw Normal View History

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