ClickHouse/src/Processors/Formats/Impl/ProtobufRowOutputFormat.h

54 lines
1.7 KiB
C++
Raw Normal View History

2019-02-19 18:41:18 +00:00
#pragma once
2021-10-27 23:10:39 +00:00
#include "config_formats.h"
2019-04-05 10:52:07 +00:00
#if USE_PROTOBUF
# include <Core/Block.h>
# include <Formats/FormatSchemaInfo.h>
# include <Formats/FormatSettings.h>
# include <Processors/Formats/IRowOutputFormat.h>
2019-02-19 18:41:18 +00:00
namespace DB
{
class ProtobufWriter;
class ProtobufSerializer;
class FormatSchemaInfo;
struct FormatSettings;
2019-02-19 18:41:18 +00:00
/** Stream designed to serialize data in the google protobuf format.
* Each row is written as a separated message.
2020-09-25 16:17:57 +00:00
*
2020-10-06 14:32:01 +00:00
* With use_length_delimiters=0 it can write only single row as plain protobuf message,
2020-09-25 16:17:57 +00:00
* otherwise Protobuf messages are delimited according to documentation
2019-02-19 18:41:18 +00:00
* 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_,
const Block & header_,
const RowOutputFormatParams & params_,
const FormatSchemaInfo & schema_info_,
const FormatSettings & settings_,
bool with_length_delimiter_);
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;
2021-03-09 14:46:52 +00:00
void writeField(const IColumn &, const ISerialization &, size_t) override {}
2019-02-19 18:41:18 +00:00
std::string getContentType() const override { return "application/octet-stream"; }
private:
std::unique_ptr<ProtobufWriter> writer;
std::unique_ptr<ProtobufSerializer> serializer;
const bool allow_multiple_rows;
2019-02-19 18:41:18 +00:00
};
}
2019-04-05 10:52:07 +00:00
#endif