Why inconsistent results using subtraction in reduce?

前端 未结 3 1229
既然无缘
既然无缘 2021-01-19 13:50

Given the following:

val rdd = List(1,2,3)

I assumed that rdd.reduce((x,y) => (x - y)) would return -4 (i.e. <

3条回答
  •  无人及你
    2021-01-19 14:31

    You can easy replace subtraction v1 - v2 - ... - vN with v1 - (v2 + ... + vN), so your code can look like

    val v1 = 1
    val values = Seq(2, 3)
    val sum = sc.paralellize(values).reduce(_ + _)
    val result = v1 - sum
    

提交回复
热议问题