You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This page documents the design and internals of Spark's Java API and is intended for those developing Spark itself; if you are a user and want to learn to use Spark from Java, please see the Java programming guide.

This page is a draft; I'm still completing it. - Josh Rosen

Why a Java API?

Scala and Java are fairly interoperable, but there are several subtleties that make it difficult to directly call Spark's Scala APIs from Java:

  • Spark uses Scala's implicit conversions to define additional operations on RDDs of key-value pairs and doubles, such as `reduceByKey`, `join`, and `stdev`.
    Since Java doesn't support implicit conversions, users have to manually instantiate the `PairRDDFunctions` and `DoubleRDDFunctions` classes to access these methods.
  • Many Spark functions take implicit `ClassManifest` arguments; users have to manually pass `ClassManifest` instances when calling these functions from Java.
  • To express user-defined functions in Java, users have to subclass Scala's internal function classes, which can be confusing.
  • Many of Spark's methods accept or return Scala collection types; this is inconvenient and often results in users manually converting to and from Java types.

These difficulties made for an unpleasant user experience. To address this, the Spark 0.7 release introduced a Java API that hides these Scala <-> Java interoperability concerns.

Implementation

Function Classes

Workarounds for compiler bugs

TODO: describe the Java/Scala compiler bugs that were reported while developing the Java API, and the workarounds for them.

Keeping the Java API up-to-date

TODO: Describe JavaAPICompletenessChecker

  • No labels