gpt4 book ai didi

python - Beam : Metrics. 计数器创建计数器失败

转载 作者:行者123 更新时间:2023-12-01 07:21:34 25 4
gpt4 key购买 nike

beam.DoFn 定义如下,遵循此 exampleMetrics.counter

from apache_beam.metrics import Metrics


class ParseAndFilterFn(beam.DoFn):
def __init__(self):
super(ParseAndFilterFn, self).__init__()
self.num_parse_errors = Metrics.counter(self.__class__, 'num_parse_errors')

def process(self, element):
text_line = element.strip()
data = {}
try:
data = json.loads(text_line.decode('utf-8'))
yield data['id']
except Exception as ex:
print("Parse json exception of ParseAndFilterFn:", ex)
self.num_parse_errors.inc()

json.loads出现一个错误时,会出现此错误AttributeError: 'ParseAndFilterFn' object has no attribute 'num_parse_errors' [while running 'ParseAndFilterFn']

我的代码有什么问题或者我缺少什么?

光束版本:2.14.0

最佳答案

在 DoFn 中进行设置的正确方法是使用 setup .

关于python - Beam : Metrics. 计数器创建计数器失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57671000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com