ClickHouse/dbms/src/DataStreams/TSKVRowOutputStream.cpp

35 lines
808 B
C++
Raw Normal View History

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_)
: TabSeparatedRowOutputStream(ostr_, sample_)
{
NamesAndTypesList columns(sample_.getColumnsList());
fields.assign(columns.begin(), columns.end());
for (auto & field : fields)
{
2016-02-07 17:30:39 +00:00
String prepared_field_name;
2015-07-18 04:27:38 +00:00
{
2016-02-07 17:30:39 +00:00
WriteBufferFromString wb(prepared_field_name);
2015-07-18 04:27:38 +00:00
writeAnyEscapedString<'='>(field.name.data(), field.name.data() + field.name.size(), wb);
2016-02-07 17:30:39 +00:00
writeCString("=", wb);
2015-07-18 04:27:38 +00:00
}
2016-02-07 17:30:39 +00:00
field.name = prepared_field_name;
2015-07-18 04:27:38 +00:00
}
}
void TSKVRowOutputStream::writeField(const Field & field)
{
writeString(fields[field_number].name, ostr);
data_types[field_number]->serializeTextEscaped(field, ostr);
++field_number;
}
}