在使用Go语言编写的Apache Beam中的Pcollection中使用Protobuf消息时出现错误。

huangapple go评论92阅读模式
英文:

Using Protobuf messages in a Pcollection in Apache Beam using Go causing an error

问题

func processPubSubMsgFn(ctx context.Context, in *pubsub.PubsubMessage) v1.someProto {
	someProto := &v1.someProto{}
	if err := proto.Unmarshal(in.Data, someProto); err != nil {
		log.Fatalln("解析地址簿失败:", err)
	}
	return *someProto
}

原因:
返回类型错误
由以下原因引起:
编码结构体 v1.someProto
类型具有未导出的字段:state

当尝试运行流水线时,在Java中,我会为消息类型设置编码器,不确定如何在Go版本的Apache Beam中实现这一点。

英文:
func processPubSubMsgFn(ctx context.Context, in *pubsub.PubsubMessage) v1.someProto {
	someProto := &v1.someProto{}
	if err := proto.Unmarshal((in.Data), someProto); err != nil {
		log.Fatalln("Failed to parse address book:", err)
	}
	return *someProto
}

Causes:
bad return type
caused by:
encoding struct v1.someProto
type has unexported field: state

When trying to run the pipeline, In java I would set the coder for the message type, not sure how to do this in the Go Version of Apache Beam

答案1

得分: 1

根据我在apache beam sdk中的观察,你应该返回*v1.someProto而不是v1.someProto

英文:

From what i see in apache beam sdk you should return *v1.someProto instead of v1.someProto.

huangapple
  • 本文由 发表于 2021年8月9日 09:30:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/68705952.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定