| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include "config_formats.h" |
| 4 | #if USE_PROTOBUF |
| 5 | |
| 6 | #include <DataTypes/IDataType.h> |
| 7 | #include <Processors/Formats/IRowInputFormat.h> |
| 8 | #include <Formats/ProtobufReader.h> |
| 9 | |
| 10 | namespace DB |
| 11 | { |
| 12 | class Block; |
| 13 | class FormatSchemaInfo; |
| 14 | |
| 15 | |
| 16 | /** Stream designed to deserialize data from the google protobuf format. |
| 17 | * Each row is read as a separated message. |
| 18 | * These messages are delimited according to documentation |
| 19 | * https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/util/delimited_message_util.h |
| 20 | * Serializing in the protobuf format requires the 'format_schema' setting to be set, e.g. |
| 21 | * INSERT INTO table FORMAT Protobuf SETTINGS format_schema = 'schema:Message' |
| 22 | * where schema is the name of "schema.proto" file specifying protobuf schema. |
| 23 | */ |
| 24 | class ProtobufRowInputFormat : public IRowInputFormat |
| 25 | { |
| 26 | public: |
| 27 | ProtobufRowInputFormat(ReadBuffer & in_, const Block & header_, Params params_, const FormatSchemaInfo & info_); |
| 28 | ~ProtobufRowInputFormat() override; |
| 29 | |
| 30 | String getName() const override { return "ProtobufRowInputFormat"; } |
| 31 | |
| 32 | bool readRow(MutableColumns & columns, RowReadExtension & extra) override; |
| 33 | bool allowSyncAfterError() const override; |
| 34 | void syncAfterError() override; |
| 35 | |
| 36 | private: |
| 37 | DataTypes data_types; |
| 38 | ProtobufReader reader; |
| 39 | }; |
| 40 | |
| 41 | } |
| 42 | #endif |
| 43 |