[英]Read Google Cloud Pubsub message and write to BigQuery using Golang
我正在使用此代码从 Google Cloud Pubsub 读取数据:
pubsubmessage := pubsubio.Read(s, project, *input, &pubsubio.ReadOptions{Subscription: sub.ID()})
并将此代码写入我的 bigquery 数据集:
bigqueryio.Write(s, project, *output, pubsubmessage)
我收到以下错误:
panic: schema type must be struct: []uint8
unable to convert []uint8/byte to schema type must be struct`
请帮我。
我正在关注这些例子:
https://github.com/apache/beam/blob/master/sdks/go/examples/streaming_wordcap/wordcap.go
pubsubio.Read 的返回值是pubsubio.Read
消息的 PCollection。 要将这些转换为 BigQuery 行,您需要应用一个DoFn
,它接收 Pubsub 消息并将其转换为 BigQuery 行。 这将返回您可以传递给bigqueryio.Write
的 BigQuery 行的 PCollection。 像这样的东西:
p := beam.NewPipeline()
s := p.Root()
pubsubmessages := pubsubio.Read(s, project, *input, &pubsubio.ReadOptions{Subscription: sub.ID()})
bigqueryrows := beam.ParDo(s, func(message []byte) string {
return ...
}, pubsubmessages)
bigqueryio.Write(s, project, *output, bigqueryrows)
您将...
替换为将 Pubsub 消息的原始字节转换为 BigQuery 行的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.