在Sp中导入自定义累加器类型

2024-09-27 23:21:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用自定义累加器类,如Spark documentation。如果我在本地定义类,这是可行的,但是当我尝试在另一个模块中定义它并使用sc.addPyFile导入文件时,我得到一个ImportError。在

当在rdd.foreach中导入一个helper函数时,我也遇到了同样的问题,我可以通过在中执行import按照this SO question来解决这个问题。但是,相同的修复对于自定义累加器不起作用(我也不希望它这样做)。在

太长了,读不下去了?在

扩展/累加器.py公司名称:

class ArrayAccumulatorParam(pyspark.AccumulatorParam):
    def zero(self, initialValue):
        return numpy.zeros(initialValue.shape)

    def addInPlace(self, a, b):
        a += b
        return a

跑/count.py公司名称:

^{pr2}$

错误:

ImportError: No module named extensions.accumulators

Tags: 模块pyself名称return定义defdocumentation

热门问题