Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Apache Spark support different language APIs

Tags:

apache-spark

I have been wondering the high level architecture of a system like Apache Spark which supports different language APIs. For example Spark supports APIs in Scala, Python and Java.

Although the software is written in Scala, it is supporting multiple language APIs. How is it done in a programmatic level? Can someone explain the high level architecture of a system like this?

like image 228
DesirePRG Avatar asked May 31 '26 07:05

DesirePRG


1 Answers

Spark uses an RPC server to expose API to other languages. When you look at the source code you'll find that all objects from PySpark and SparkR are in fact JVM objects wrappers. Take a look at R DataFrame and Python DataFrame. In R, there is a lot of callJMethod() calls (which are calling JVM objects via some kind of proxy). In Python, each object has a handle to JVM object. In case of DataFrame it is _jdf (Java DataFrame). Under the hood, there is Spark (Scala implementation) running and there is an RPC server running which exposes JVM objects (i.e. SparkContext) to external processes (PySpark and SparkR in this case).

The question is, how to implement map()/mapPartitions() methods which take code in Python or R? As you might know the map() method creates an RDD which remembers the transformation. To support Python, in Scala Spark there is a special kind of an RDD called PythonRDD.

Also, there is a document about PySpark internals, if you're interested, of course.

like image 145
Wojciech Jurczyk Avatar answered Jun 01 '26 21:06

Wojciech Jurczyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!