0
0
Apache Sparkdata~5 mins

Google Dataproc overview in Apache Spark

Choose your learning style9 modes available
Introduction

Google Dataproc helps you run big data jobs easily and quickly in the cloud. It makes managing Apache Spark and Hadoop simple so you can focus on analyzing data.

You want to process large datasets without managing servers.
You need to run Apache Spark or Hadoop jobs on demand.
You want to scale your data processing up or down quickly.
You want to save costs by using cloud resources only when needed.
You want to integrate with other Google Cloud services like BigQuery or Cloud Storage.
Syntax
Apache Spark
gcloud dataproc clusters create [CLUSTER_NAME] --region=[REGION] --single-node

# Submit a Spark job

gcloud dataproc jobs submit spark --cluster=[CLUSTER_NAME] --region=[REGION] --class=[MAIN_CLASS] --jars=[JAR_FILES] -- [JOB_ARGS]

Use gcloud dataproc clusters create to make a new cluster.

Use gcloud dataproc jobs submit spark to run Spark jobs on the cluster.

Examples
This creates a small single-node Dataproc cluster in the US Central region.
Apache Spark
gcloud dataproc clusters create my-cluster --region=us-central1 --single-node
This runs the SparkPi example job on the cluster with 1000 as input.
Apache Spark
gcloud dataproc jobs submit spark --cluster=my-cluster --region=us-central1 --class=org.apache.spark.examples.SparkPi --jars=file:///usr/lib/spark/examples/jars/spark-examples.jar -- 1000
Sample Program

This Python script uses the command line to create a Dataproc cluster and run a Spark job that calculates Pi.

Apache Spark
# This example shows how to create a cluster and run a Spark job using Python and subprocess
import subprocess

# Create cluster
create_cmd = [
    'gcloud', 'dataproc', 'clusters', 'create', 'test-cluster',
    '--region=us-central1', '--single-node'
]
subprocess.run(create_cmd, check=True)

# Submit Spark job
submit_cmd = [
    'gcloud', 'dataproc', 'jobs', 'submit', 'spark',
    '--cluster=test-cluster', '--region=us-central1',
    '--class=org.apache.spark.examples.SparkPi',
    '--jars=file:///usr/lib/spark/examples/jars/spark-examples.jar',
    '--', '10'
]
subprocess.run(submit_cmd, check=True)

print('Cluster created and Spark job submitted successfully.')
OutputSuccess
Important Notes

Dataproc clusters can be created quickly, often in under 90 seconds.

You only pay for the cluster while it runs, so delete it when done to save money.

Dataproc integrates well with Google Cloud Storage for input and output data.

Summary

Google Dataproc makes running Spark and Hadoop jobs easy in the cloud.

You create clusters to run jobs and delete them when finished to save costs.

It helps you process big data without managing servers yourself.