title: How does the collectAsMap() function work for Spark API
body: <p>I am trying to understand as to what happens when we run the <code>collectAsMap</code>() function in spark. As per the Pyspark docs,it says,</p>
  
  <blockquote>
    <p>collectAsMap(self)
    Return the key-value pairs in this RDD to the master as a dictionary.</p>
  </blockquote>
  
  <p>and for core spark it says,</p>
  
  <blockquote>
    <p>def collectAsMap(): Map[K, V] Return the key-value pairs in this RDD
    to the master as a Map.</p>
  </blockquote>
  
  <p>When I try to run a sample code in pyspark for a List, I get this result:
  <a href="https://i.stack.imgur.com/67ob1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/67ob1.jpg" alt="pyspark result"></a></p>
  
  <p>and for scala  I get this result:
  <a href="https://i.stack.imgur.com/y2Clo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y2Clo.jpg" alt="scala result"></a></p>
  
  <p>I am a little confused as to why it is not returning all the elements in the List. Can somebody help me understand what is happening in this scenario as to why I am getting selective results.</p>
  
  <p>Thanks.</p>