2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
2017-07-31 21:39:24 +00:00
|
|
|
#include <IO/WriteBufferFromString.h>
|
2018-06-10 19:22:49 +00:00
|
|
|
#include <Formats/TSKVRowOutputStream.h>
|
|
|
|
#include <Formats/FormatFactory.h>
|
|
|
|
#include <Formats/BlockOutputStreamFromRowOutputStream.h>
|
|
|
|
|
2015-07-18 04:27:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-06-08 01:51:55 +00:00
|
|
|
TSKVRowOutputStream::TSKVRowOutputStream(WriteBuffer & ostr_, const Block & sample_, const FormatSettings & format_settings)
|
|
|
|
: TabSeparatedRowOutputStream(ostr_, sample_, false, false, format_settings)
|
2015-07-18 04:27:38 +00:00
|
|
|
{
|
2017-12-25 21:57:29 +00:00
|
|
|
NamesAndTypesList columns(sample_.getNamesAndTypesList());
|
2017-04-01 07:20:54 +00:00
|
|
|
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();
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
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);
|
2018-06-08 01:51:55 +00:00
|
|
|
type.serializeTextEscaped(column, row_num, ostr, format_settings);
|
2017-04-01 07:20:54 +00:00
|
|
|
++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
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-10 19:22:49 +00:00
|
|
|
void registerOutputFormatTSKV(FormatFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerOutputFormat("TSKV", [](
|
|
|
|
WriteBuffer & buf,
|
|
|
|
const Block & sample,
|
|
|
|
const Context &,
|
|
|
|
const FormatSettings & settings)
|
|
|
|
{
|
|
|
|
return std::make_shared<BlockOutputStreamFromRowOutputStream>(
|
|
|
|
std::make_shared<TSKVRowOutputStream>(buf, sample, settings), sample);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-07-18 04:27:38 +00:00
|
|
|
}
|