pyspark.RDD.treeReduce

RDD.treeReduce(f: Callable[[T, T], T], depth: int = 2) → T

Reduces the elements of this RDD in a multi-level tree pattern.

Parameters
ffunction
depthint, optional

suggested depth of the tree (default: 2)

Examples

>>> add = lambda x, y: x + y
>>> rdd = sc.parallelize([-5, -4, -3, -2, -1, 1, 2, 3, 4], 10)
>>> rdd.treeReduce(add)
-5
>>> rdd.treeReduce(add, 1)
-5
>>> rdd.treeReduce(add, 2)
-5
>>> rdd.treeReduce(add, 5)
-5
>>> rdd.treeReduce(add, 10)
-5