Specify the region
where your cluster is located (confirm or replace "us-central1"). Your cluster's
region is listed on the Dataproc
Clusters page in the
Google Cloud console.
Request body:
job.placement.clusterName:
The name of the cluster where the job will run (confirm or replace "example-cluster").
job.sparkJob.jarFileUris:
"file:///usr/lib/spark/examples/jars/spark-examples.jar". This is
the local file path on the Dataproc cluster's master node
where the jar that contains the Spark Scala job code is installed.
job.sparkJob.mainClass:
"org.apache.spark.examples.SparkPi". The is the main method of
the job's pi calculation Scala application.
Click EXECUTE. The first time you
run the API template, you may be asked to choose and sign into
your Google account, then authorize the Google APIs Explorer to access your
account. If the request is successful, the JSON response
shows that job submission request is pending.
To view job output, open the
Dataproc Jobs page
in the Google Cloud console, then click the top (most recent) Job ID.
Click "LINE WRAP" to ON to bring lines that exceed the right margin into view.
...
Pi is roughly 3.141804711418047
...
Clean up
To avoid incurring charges to your Google Cloud account for
the resources used on this page, follow these steps.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[[["\u003cp\u003eThis guide demonstrates how to submit a Spark job to an existing Dataproc cluster using a Google APIs Explorer template.\u003c/p\u003e\n"],["\u003cp\u003eBefore submitting a job, a Dataproc cluster must be created using methods like the APIs Explorer, Google Cloud console, gcloud CLI, or Cloud Client Libraries.\u003c/p\u003e\n"],["\u003cp\u003eThe Spark job example provided calculates a rough value for pi, and requires parameters such as projectId, region, clusterName, and specific job details like task count, jar file path, and main class.\u003c/p\u003e\n"],["\u003cp\u003eAfter submitting the job through the API, you can view the job output in the Dataproc Jobs page in the Google Cloud console.\u003c/p\u003e\n"],["\u003cp\u003eTo avoid incurring charges, delete the Dataproc cluster using one of the provided methods if it is no longer needed.\u003c/p\u003e\n"]]],[],null,["# Quickstart: Submit a Spark job by using a template\n\nSubmit a Spark job by using a template\n======================================\n\nThis page shows you how to use an [Google APIs Explorer](https://developers.google.com/apis-explorer/#p/) template to\nrun a simple Spark job on an existing Dataproc cluster.\n\nFor other ways to submit a job to a Dataproc cluster, see:\n\n- [Create a Dataproc cluster by using the Google Cloud console](/dataproc/docs/quickstarts/create-cluster-console#submit_a_job)\n- [Create a Dataproc cluster by using the Google Cloud CLI](/dataproc/docs/quickstarts/create-cluster-gcloud#submit_a_job)\n- [Create a Dataproc cluster by using client libraries](/dataproc/docs/quickstarts/create-cluster-client-libraries)\n\nBefore you begin\n----------------\n\nBefore you can run a Dataproc job, you must create a cluster of one or more virtual machines (VMs) to run it on. You can use the [APIs Explorer](/dataproc/docs/quickstarts/create-cluster-template), the [Google Cloud console](/dataproc/docs/quickstarts/update-cluster-console#create_a_cluster), the gcloud CLI [gcloud](/dataproc/docs/quickstarts/update-cluster-gcloud#create_a_cluster) command-line tool, or the [Quickstarts using Cloud Client Libraries](/dataproc/docs/quickstarts/create-cluster-client-libraries) to create a cluster.\n\n\u003cbr /\u003e\n\nSubmit a job\n------------\n\nTo submit a sample [Apache Spark](http://spark.apache.org/)\njob that calculates a rough value for\n[pi](https://en.wikipedia.org/wiki/Pi), fill in and\nexecute the Google APIs Explorer **Try this API** template.\n| **Note:** The `region`, `clusterName` and `job` parameter values are filled in for you. Confirm or replace the `region` and `clusterName` parameter values to match your cluster's region and name. The `job` parameter values are required to run the a Spark job that is pre-installed on the Dataproc cluster's master node.\n\n1. **Request parameters:**\n\n 1. Insert your [**projectId**](https://console.cloud.google.com/).\n 2. Specify the [**region**](/compute/docs/regions-zones/regions-zones#available) where your cluster is located (confirm or replace \"us-central1\"). Your cluster's region is listed on the Dataproc [**Clusters**](https://console.cloud.google.com/dataproc/clusters) page in the Google Cloud console.\n2. **Request body:**\n\n 1. [**job.placement.clusterName**](/dataproc/docs/reference/rest/v1/SparkJob#JobPlacement.FIELDS.cluster_name): The name of the cluster where the job will run (confirm or replace \"example-cluster\").\n 2. [**job.sparkJob.args**](/dataproc/docs/reference/rest/v1/SparkJob#FIELDS.args): \"1000\", the number of job tasks.\n 3. [**job.sparkJob.jarFileUris**](/dataproc/docs/reference/rest/v1/SparkJob#FIELDS.jar_file_uris): \"file:///usr/lib/spark/examples/jars/spark-examples.jar\". This is the local file path on the Dataproc cluster's master node where the jar that contains the Spark Scala job code is installed.\n 4. [**job.sparkJob.mainClass**](/dataproc/docs/reference/rest/v1/SparkJob#FIELDS.main_class): \"org.apache.spark.examples.SparkPi\". The is the main method of the job's pi calculation Scala application.\n3. Click **EXECUTE**. The first time you\n run the API template, you may be asked to choose and sign into\n your Google account, then authorize the Google APIs Explorer to access your\n account. If the request is successful, the JSON response\n shows that job submission request is pending.\n\n4. To view job output, open the\n [Dataproc Jobs](https://console.cloud.google.com/dataproc/jobs) page\n in the Google Cloud console, then click the top (most recent) Job ID.\n Click \"LINE WRAP\" to ON to bring lines that exceed the right margin into view.\n\n ```\n ...\n Pi is roughly 3.141804711418047\n ...\n ```\n\nClean up\n--------\n\n\nTo avoid incurring charges to your Google Cloud account for\nthe resources used on this page, follow these steps.\n\n1. If you don't need the cluster to explore the other quickstarts or to run other jobs, use the [APIs Explorer](/dataproc/docs/quickstarts/quickstart-explorer-delete), the [Google Cloud console](/dataproc/docs/quickstarts/update-cluster-console#delete_a_cluster), the gcloud CLI [gcloud](/dataproc/docs/quickstarts/update-cluster-gcloud#delete_a_cluster) command-line tool, or the [Cloud Client Libraries](/dataproc/docs/quickstarts/create-cluster-client-libraries) to delete the cluster.\n\nWhat's next\n-----------\n\n- Learn how to [update a Dataproc cluster by using a template](/dataproc/docs/quickstarts/update-cluster-template)."]]