title: Spark local variable broadcast to executor
body: <pre><code>var countryMap = Map("Amy" -&gt; "Canada", "Sam" -&gt; "US", "Bob" -&gt; "Canada")
  val names = List("Amy", "Sam", "Eric")
  sc.parallelize(names).flatMap(broadcastMap.value.get).collect.foreach(println)
  
  //output
  Canada
  US
  </code></pre>
  
  <p>I'm running this spark job in YARN mode, and I'm sure that driver and executors are not in the same node/JVM (see the attached pic). Since countryMap is not a broadcast variable, so the executor should not see it and this code shouldn't print anything. However, it printed <code>Canada</code> and <code>US</code>.</p>
  
  <p>My question is that does Spark populate local variables to executors automatically if they are serializable? if not, how does the executor see the driver's local variables?</p>
  
  <p><a href="https://i.stack.imgur.com/Mo1PP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mo1PP.png" alt="enter image description here"></a> </p>