2019-02-19 18:41:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-08-17 22:53:46 +00:00
|
|
|
#include "config_formats.h"
|
2019-04-05 10:52:07 +00:00
|
|
|
#if USE_PROTOBUF
|
|
|
|
|
2019-02-19 18:41:18 +00:00
|
|
|
#include <Core/Block.h>
|
|
|
|
#include <Formats/FormatSettings.h>
|
2019-04-05 10:52:07 +00:00
|
|
|
#include <Formats/ProtobufWriter.h>
|
|
|
|
#include <Formats/FormatSchemaInfo.h>
|
2019-08-02 16:31:17 +00:00
|
|
|
#include <Processors/Formats/IRowOutputFormat.h>
|
2019-02-19 18:41:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace google
|
|
|
|
{
|
|
|
|
namespace protobuf
|
|
|
|
{
|
|
|
|
class Message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
/** Stream designed to serialize data in the google protobuf format.
|
|
|
|
* Each row is written as a separated message.
|
|
|
|
* These messages are delimited according to documentation
|
|
|
|
* https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/util/delimited_message_util.h
|
|
|
|
* Serializing in the protobuf format requires the 'format_schema' setting to be set, e.g.
|
|
|
|
* SELECT * from table FORMAT Protobuf SETTINGS format_schema = 'schema:Message'
|
|
|
|
* where schema is the name of "schema.proto" file specifying protobuf schema.
|
|
|
|
*/
|
2019-08-02 16:31:17 +00:00
|
|
|
class ProtobufRowOutputFormat : public IRowOutputFormat
|
2019-02-19 18:41:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-08-02 16:31:17 +00:00
|
|
|
ProtobufRowOutputFormat(
|
2019-04-09 09:25:57 +00:00
|
|
|
WriteBuffer & out_,
|
2019-04-05 10:52:07 +00:00
|
|
|
const Block & header,
|
|
|
|
const FormatSchemaInfo & format_schema);
|
2019-02-19 18:41:18 +00:00
|
|
|
|
2019-08-02 16:31:17 +00:00
|
|
|
String getName() const override { return "ProtobufRowOutputFormat"; }
|
2019-04-05 10:52:07 +00:00
|
|
|
|
2019-08-02 16:31:17 +00:00
|
|
|
void write(const Columns & columns, size_t row_num) override;
|
2019-08-02 16:34:20 +00:00
|
|
|
void writeField(const IColumn &, const IDataType &, size_t) override {}
|
2019-02-19 18:41:18 +00:00
|
|
|
std::string getContentType() const override { return "application/octet-stream"; }
|
|
|
|
|
|
|
|
private:
|
2019-04-05 10:52:07 +00:00
|
|
|
DataTypes data_types;
|
2019-02-19 18:41:18 +00:00
|
|
|
ProtobufWriter writer;
|
2019-04-05 10:52:07 +00:00
|
|
|
std::vector<size_t> value_indices;
|
2019-02-19 18:41:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2019-04-05 10:52:07 +00:00
|
|
|
#endif
|