mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
dbms: added format TSKV [#METR-2944].
This commit is contained in:
parent
aa225476e8
commit
3ca8bb4448
24
dbms/include/DB/DataStreams/TSKVRowOutputStream.h
Normal file
24
dbms/include/DB/DataStreams/TSKVRowOutputStream.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <DB/DataStreams/TabSeparatedRowOutputStream.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
/** Поток для вывода данных в формате TSKV.
|
||||
* TSKV похож на TabSeparated, но перед каждым значением указывается его имя и знак равенства: name=value.
|
||||
* Этот формат весьма неэффективен.
|
||||
*/
|
||||
class TSKVRowOutputStream : public TabSeparatedRowOutputStream
|
||||
{
|
||||
public:
|
||||
TSKVRowOutputStream(WriteBuffer & ostr_, const Block & sample_);
|
||||
void writeField(const Field & field) override;
|
||||
|
||||
protected:
|
||||
NamesAndTypes fields;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <DB/DataStreams/BlockOutputStreamFromRowOutputStream.h>
|
||||
#include <DB/DataStreams/JSONRowOutputStream.h>
|
||||
#include <DB/DataStreams/JSONCompactRowOutputStream.h>
|
||||
#include <DB/DataStreams/TSKVRowOutputStream.h>
|
||||
#include <DB/DataStreams/PrettyCompactMonoBlockOutputStream.h>
|
||||
#include <DB/DataStreams/FormatFactory.h>
|
||||
|
||||
@ -83,6 +84,8 @@ BlockOutputStreamPtr FormatFactory::getOutput(const String & name, WriteBuffer &
|
||||
return new BlockOutputStreamFromRowOutputStream(new JSONRowOutputStream(buf, sample));
|
||||
else if (name == "JSONCompact")
|
||||
return new BlockOutputStreamFromRowOutputStream(new JSONCompactRowOutputStream(buf, sample));
|
||||
else if (name == "TSKV")
|
||||
return new BlockOutputStreamFromRowOutputStream(new TSKVRowOutputStream(buf, sample));
|
||||
else if (name == "Null")
|
||||
return new NullBlockOutputStream;
|
||||
else if (name == "PrettyCompactMonoBlock")
|
||||
|
37
dbms/src/DataStreams/TSKVRowOutputStream.cpp
Normal file
37
dbms/src/DataStreams/TSKVRowOutputStream.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <DB/IO/WriteHelpers.h>
|
||||
#include <DB/DataStreams/TSKVRowOutputStream.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
using Poco::SharedPtr;
|
||||
|
||||
|
||||
TSKVRowOutputStream::TSKVRowOutputStream(WriteBuffer & ostr_, const Block & sample_)
|
||||
: TabSeparatedRowOutputStream(ostr_, sample_)
|
||||
{
|
||||
NamesAndTypesList columns(sample_.getColumnsList());
|
||||
fields.assign(columns.begin(), columns.end());
|
||||
|
||||
for (auto & field : fields)
|
||||
{
|
||||
String escaped_field_name;
|
||||
{
|
||||
WriteBufferFromString wb(escaped_field_name);
|
||||
writeAnyEscapedString<'='>(field.name.data(), field.name.data() + field.name.size(), wb);
|
||||
}
|
||||
field.name = escaped_field_name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TSKVRowOutputStream::writeField(const Field & field)
|
||||
{
|
||||
writeString(fields[field_number].name, ostr);
|
||||
writeCString("=", ostr);
|
||||
data_types[field_number]->serializeTextEscaped(field, ostr);
|
||||
++field_number;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user