title: PySpark : sum RDD values , keep the key
body: <p>Just started with Spark</p>
  
  <p>I have rdd like following :</p>
  
  <blockquote>
    <p>(x,(a,1))</p>
  </blockquote>
  
  <p>I'd like sum each <strong>a</strong> as folowing </p>
  
  <pre><code>sumRDD = filteredRdd.map(lambda (x, (a, b)): (a, b)).reduceByKey(add)
  </code></pre>
  
  <p>It's works
  then , I'd like to add <strong>x</strong> as it was previously ,like this</p>
  
  <pre><code>(x,(a,sum_of_a)) 
  </code></pre>
  
  <p>I tried :</p>
  
  <pre><code> sumRDD = filteredRdd.map(lambda (x, (a, b)): (a, b)).reduceByKey(add).map(lambda (a, b): (x,(a, b)))
  </code></pre>
  
  <p>it fails :(</p>
  
  <p><strong>Edit</strong> : I'd like to keep  x during calculation the sum of b , it's my important key</p>