Skip to main content

Apache Spark

Bindings: %spark, %spark.sql, %spark.pyspark, %spark.ipyspark, %spark.r, %spark.ir, %spark.shiny

Runs distributed jobs against an Apache Spark cluster (or a local Spark instance), from a paragraph. A SparkSession is set up for you and shared across the bindings, so you can build a DataFrame in Scala in one paragraph and query it with %spark.sql in the next.

BindingUse it for
%sparkScala on Spark
%spark.sqlSQL on Spark (queries registered tables/views)
%spark.pysparkPython on Spark
%spark.ipysparkPython on Spark via an interactive IPython shell
%spark.r / %spark.irR on Spark
%spark.shinySpark-backed R Shiny applications
%spark.pyspark
df = spark.read.csv("/data/sales.csv", header=True, inferSchema=True)
df.createOrReplaceTempView("sales")
%spark.sql
SELECT region, sum(amount) AS total FROM sales GROUP BY region

Configuration

PropertyDefaultDescription
spark.masterlocal[*]Where Spark runs — local, YARN, or a standalone master address.
spark.submit.deployMode(empty)client or cluster deploy mode.
spark.driver.memory / spark.driver.cores1g / 1Resources for the Spark driver.
spark.executor.memory / spark.executor.cores / spark.executor.instances1g / 1 / 2Resources per executor, and how many executors to allocate.
spark.jars / spark.jars.packages(empty)Extra jars, or Maven coordinates of extra dependencies, to add to the job.
skeyenote.spark.useHiveContexttrueWhether the Spark session is Hive-aware.
skeyenote.spark.maxResult1000Max number of Spark SQL rows to display.
skeyenote.spark.concurrentSQL / skeyenote.spark.concurrentSQL.maxtrue / 10Whether SQL paragraphs can run concurrently, and how many at once.
skeyenote.spark.uiWebUrl / skeyenote.spark.ui.hiddenWhere (or whether) to expose the Spark UI link for a job.

These are set by your administrator from the interpreter settings screen, typically per cluster or per team.

See the notebook context object (ssnc) for displaying DataFrames and building dynamic forms from any of the Spark bindings.