2019-02-21 18:36:46 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-04-16 12:31:57 +00:00
|
|
|
#if !defined(ARCADIA_BUILD)
|
|
|
|
# include "config_formats.h"
|
|
|
|
#endif
|
2019-02-21 18:36:46 +00:00
|
|
|
|
2020-04-16 12:31:57 +00:00
|
|
|
#if USE_PROTOBUF
|
|
|
|
# include <Processors/Formats/IRowInputFormat.h>
|
2019-02-21 18:36:46 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
class Block;
|
|
|
|
class FormatSchemaInfo;
|
2021-01-11 01:50:30 +00:00
|
|
|
class ProtobufReader;
|
|
|
|
class ProtobufSerializer;
|
2019-02-21 18:36:46 +00:00
|
|
|
|
|
|
|
|
2019-08-02 16:23:44 +00:00
|
|
|
/** Stream designed to deserialize data from the google protobuf format.
|
2020-09-23 15:10:04 +00:00
|
|
|
* One Protobuf message is parsed as one row of data.
|
|
|
|
*
|
2020-10-06 14:32:01 +00:00
|
|
|
* Input buffer may contain single protobuf message (use_length_delimiters_ = false),
|
|
|
|
* or any number of messages (use_length_delimiters = true). In the second case
|
2020-09-23 15:10:04 +00:00
|
|
|
* parser assumes messages are length-delimited according to documentation
|
2019-08-02 16:23:44 +00:00
|
|
|
* https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/util/delimited_message_util.h
|
2020-09-23 15:10:04 +00:00
|
|
|
* Parsing of the protobuf format requires the 'format_schema' setting to be set, e.g.
|
2019-08-02 16:23:44 +00:00
|
|
|
* INSERT INTO table FORMAT Protobuf SETTINGS format_schema = 'schema:Message'
|
|
|
|
* where schema is the name of "schema.proto" file specifying protobuf schema.
|
2019-02-21 18:36:46 +00:00
|
|
|
*/
|
|
|
|
class ProtobufRowInputFormat : public IRowInputFormat
|
|
|
|
{
|
|
|
|
public:
|
2021-01-11 01:50:30 +00:00
|
|
|
ProtobufRowInputFormat(ReadBuffer & in_, const Block & header_, const Params & params_, const FormatSchemaInfo & schema_info_, bool with_length_delimiter_);
|
2019-02-21 18:36:46 +00:00
|
|
|
~ProtobufRowInputFormat() override;
|
|
|
|
|
|
|
|
String getName() const override { return "ProtobufRowInputFormat"; }
|
|
|
|
|
2021-01-11 01:50:30 +00:00
|
|
|
bool readRow(MutableColumns & columns, RowReadExtension &) override;
|
2019-02-21 18:36:46 +00:00
|
|
|
bool allowSyncAfterError() const override;
|
|
|
|
void syncAfterError() override;
|
|
|
|
|
|
|
|
private:
|
2021-01-11 01:50:30 +00:00
|
|
|
std::unique_ptr<ProtobufReader> reader;
|
|
|
|
std::vector<size_t> missing_column_indices;
|
|
|
|
std::unique_ptr<ProtobufSerializer> serializer;
|
2019-02-21 18:36:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|