Я использую ProTobuf для отправки строк в BigQuery для заполнения таблиц.
Одна проблема, с которой я сталкиваюсь, - это вложенные поля /сообщения.
Действительно, я знаю, как добавить дескриптор для одного сообщения, Но в случае, когда они вложены, мне нужно добавить дескриптор нескольких сообщений. И я не знаю, как это сделать. > Вот мой фрагмент кода < /p>
python file < /p>
from google.cloud.bigquery_storage_v1 import types, writer, BigQueryWriteClient
from google.protobuf import descriptor_pb2
from test_pb2 import Bar
pb2_class=Bar
write_client = BigQueryWriteClient()
parent = write_client.table_path("my_project", "my_dataset", "my_table")
write_stream = types.WriteStream()
write_stream.type_ = types.WriteStream.Type.PENDING
write_stream = write_client.create_write_stream(
parent=parent, write_stream=write_stream
)
stream_name = write_stream.name
request_template = types.AppendRowsRequest()
request_template.write_stream = stream_name
proto_schema = types.ProtoSchema()
proto_descriptor = descriptor_pb2.DescriptorProto()
pb2_class.DESCRIPTOR.CopyToProto(proto_descriptor) # This only adds a descriptor for Bar ! Foo will be unknown when sending the messages to bigquery
proto_schema.proto_descriptor = proto_descriptor
proto_data = types.AppendRowsRequest.ProtoData()
proto_data.writer_schema = proto_schema
request_template.proto_rows = proto_data
append_rows_stream = writer.AppendRowsStream(write_client, request_template)
proto_rows = types.ProtoRows()
offset = 0
< /code>
.proto file < /p>
syntax = "proto3";
message Foo {
string key = 1;
string value = 2;
}
message Bar {
repeated Foo foo = 1;
string key = 2;
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... buf-python