📜  使用指定的交换和关联二元运算符减少此 RDD 的元素 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:30.625000             🧑  作者: Mango

代码示例1
from operator import add
sc.parallelize([1, 2, 3, 4, 5]).reduce(add)
# 15
sc.parallelize((2 for _ in range(10))).map(lambda x: 1).cache().reduce(add)
# 10
sc.parallelize([]).reduce(add)
"""
Traceback (most recent call last):
    ...
ValueError: Can not reduce() empty RDD
"""