title: Explain the aggregate functionality in Spark (with Python and Scala)
body: <p>I am looking for some better explanation of the aggregate functionality that is available via spark in python.  </p>
  
  <p>The example I have is as follows (using pyspark from Spark 1.2.0 version)</p>
  
  <pre><code>sc.parallelize([1,2,3,4]).aggregate(
    (0, 0),
    (lambda acc, value: (acc[0] + value, acc[1] + 1)),
    (lambda acc1, acc2: (acc1[0] + acc2[0], acc1[1] + acc2[1])))
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>(10, 4)
  </code></pre>
  
  <p>I get the expected result <code>(10,4)</code> which is sum of <code>1+2+3+4</code> and 4 elements.  If I change the initial value passed to the aggregate function to <code>(1,0)</code> from <code>(0,0)</code>  I get the following result</p>
  
  <pre><code>sc.parallelize([1,2,3,4]).aggregate(
      (1, 0),
      (lambda acc, value: (acc[0] + value, acc[1] + 1)),
      (lambda acc1, acc2: (acc1[0] + acc2[0], acc1[1] + acc2[1])))
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>(19, 4)
  </code></pre>
  
  <p>The value increases by 9.  If I change it to <code>(2,0)</code>,  the value goes to <code>(28,4)</code> and so on.</p>
  
  <p>Can someone explain to me how this value is calculated?  I expected the value to go up by 1 not by 9, expected to see <code>(11,4)</code> instead I am seeing <code>(19,4)</code>.  </p>