Running Sparkling Water on Google Cloud Dataproc

This section describes how to run Sparkling Water on Google Cloud Dataproc. It is meant to get you up and running with Sparkling Water on Google Cloud Dataproc as fast as possible so you can try it out. For further usage and productionizing some adjustments like initialization actions will be required. In this tutorial we will use Dataproc image version 2.0-debian10 which has Spark 3.1 and Scala 2.12.

  1. Install the Google Cloud SDK. Login to your account.

  2. Download Sparkling water.

  3. Create a Google Cloud Dataproc cluster.


gcloud dataproc clusters create $DATAPROC_CLUSTER_NAME \
--region $GCP_REGION \
--image-version 2.0-debian10 \
--num-workers 3 \


Set the variables.

# we need spark jars to compile the example
SPARK_JARS=$(echo "$SPARK_HOME"/jars/*.jar | tr ' ' ':')

Copy the example job source into a file named SparklingWaterGcpExampleJob.scala

import ai.h2o.sparkling._
import org.apache.spark.SparkFiles
import org.apache.spark.sql.SparkSession

object SparklingWaterGcpExampleJob extends App {
  // start the cluster
  val spark = SparkSession.builder.appName("Sparkling water example").getOrCreate()
  import spark.implicits._
  val hc = H2OContext.getOrCreate()

  val expectedClusterSize = 3
  val clusterSize = hc.getH2ONodes().length
  require(clusterSize != expectedClusterSize, s"H2O cluster should be of size $expectedClusterSize but is $clusterSize")

  // prepare the data
  val frame = H2OFrame(new URI("file://" + SparkFiles.get("prostate.csv")))
  val sparkDF = hc.asSparkFrame(frame).withColumn("CAPSULE", $"CAPSULE" cast "string")
  val Array(trainingDF, testingDF) = sparkDF.randomSplit(Array(0.8, 0.2))

  // train the model
  val estimator = new H2OGBM().setLabelCol("CAPSULE")
  val model =

  // run predictions

Compile the code into a jar file having Spark and Sparkling Water on the classpath.

scalac SparklingWaterGcpExampleJob.scala \
      -d $EXAMPLE_JOB_JAR \

Submit the job to the cluster.

gcloud dataproc jobs submit spark \
--class=SparklingWaterGcpExampleJob \
--region=$GCP_REGION \


Set the variables.


Copy the example job source into a file named

from pysparkling import *
from pyspark.sql import SparkSession
import h2o

# start the cluster
spark = SparkSession.builder.appName("Sparkling water example").getOrCreate()
hc = H2OContext.getOrCreate()
assert h2o.cluster().cloud_size == 3

# prepare the data
frame = h2o.import_file("")
sparkDF = hc.asSparkFrame(frame)
sparkDF = sparkDF.withColumn("CAPSULE", sparkDF.CAPSULE.cast("string"))
[trainingDF, testingDF] = sparkDF.randomSplit([0.8, 0.2])

# train the model
from import H2OGBM
estimator = H2OGBM(labelCol = "CAPSULE")
model =

# run predictions

Submit the job to the cluster.

gcloud dataproc jobs submit pyspark \
--region=$GCP_REGION \
--py-files $PYSPARKLING_ZIP \