2019-02-19 18:41:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-04-05 10:52:07 +00:00
|
|
|
#include <Common/config.h>
|
|
|
|
#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-02-19 18:41:18 +00:00
|
|
|
#include <Processors/Formats/IOutputFormat.h>
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
class ProtobufBlockOutputFormat : public IOutputFormat
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProtobufBlockOutputFormat(
|
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
|
|
|
|
|
|
|
String getName() const override { return "ProtobufBlockOutputFormat"; }
|
|
|
|
|
2019-04-05 10:52:07 +00:00
|
|
|
void consume(Chunk) 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
|