[英]in process NameError: name 'monitoring_v3' is not defined [while running 'PubSub Unread Messages-ptransform-32']
[英]NameError: name 'func' is not defined [while running 'Map(<lambda at testing.py:273>)-ptransform-38']
我正在 Google Dataflow 上使用 Apache Beam 和 ProtoBuf。
with beam.Pipeline(options=pipeline_options) as p:
data = (
p
| beam.io.ReadFromPubSub(subscription='projects/abc/subscriptions/abc-sub')
| beam.Map(lambda x: convert_proto_to_dict(x, protobuf_schema_pb2.Message))
)
这是我的 Apache Beam 调用 convert_proto_to_dict 函数。
功能代码如下(我认为这无关紧要):
def convert_proto_to_dict(data, schema_class):
from google.protobuf.json_format import MessageToDict
message = schema_class()
message.ParseFromString(data)
return MessageToDict(message, preserving_proto_field_name=True)
我得到以下回溯:
NameError:名称'convert_proto_to_dict'未定义[运行'Map(<lambda at testing.py:273>)-ptransform-38']
我研究了解决这个问题的方法,一些建议使用beam.Map(convert_proto_to_dict, protobuf_schema_pb2.Message
代替beam.Map(lambda x: convert_proto_to_dict(x, protobuf_schema_pb2.Message))
。但是这种方式 beam 将使用DoFn和DoFn可以不适用于 protobuf(我不知道为什么)。我不确定我错过了什么。请帮助我。
使用 DirectRunner 在本地运行管道是否有效? 如果是这样,它应该是一个常见问题NameError 。 您可以尝试将--save_main_session
管道选项设置为 True。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.