All functions passed to Spark operations (like map or reduce) and executed on the remote machines uses their own local variables. It is important to notice that no variables are propagated back to the driver program.
Continue reading
Sharing variables on Apache Spark
Reply