"Managed Service for Apache Spark" is the new name for the product formerly known as "Dataproc on Compute Engine" (cluster deployment) and "Google Cloud Serverless for Apache Spark" (serverless deployment).
Stay organized with collections
Save and categorize content based on your preferences.
Create a lakehouse with Spark and Lakehouse runtime catalog
A lakehouse architecture combines the flexibility of a data lake with the data
management features of a data warehouse. This document shows you how to set up a
lakehouse on Google Cloud. You use Apache Iceberg as the table format, Managed Service for Apache Spark for processing, and the Lakehouse runtime catalog Iceberg REST Catalog for
unified metadata management.
This architecture uses open table formats like Iceberg to add data warehousing
capabilities, such as transactions and schema evolution, to data in Cloud Storage. This approach creates a single source of truth for your data that is
accessible by various engines.
Diagram showing the components of a lakehouse architecture, including Managed Service for Apache Spark, Cloud Storage, and the Lakehouse REST Catalog.
Lakehouse architecture diagram.
Before you begin
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get 300ドル in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Roles required to select or create a project
Select a project: Selecting a project doesn't require a specific
IAM role—you can select any project that you've been
granted a role on.
Create a project: To create a project, you need the Project Creator role
(roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
Enable the Dataproc, BigQuery, and Cloud Storage APIs.
Roles required to enable APIs
To enable APIs, you need the serviceusage.services.enable permission. If you
created the project, then you likely already have this permission through the
Owner role (roles/owner). Otherwise, you can get this permission through the
Service Usage Admin role (roles/serviceusage.serviceUsageAdmin).
Learn how to grant roles.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Roles required to select or create a project
Select a project: Selecting a project doesn't require a specific
IAM role—you can select any project that you've been
granted a role on.
Create a project: To create a project, you need the Project Creator role
(roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
Enable the Dataproc, BigQuery, and Cloud Storage APIs.
Roles required to enable APIs
To enable APIs, you need the serviceusage.services.enable permission. If you
created the project, then you likely already have this permission through the
Owner role (roles/owner). Otherwise, you can get this permission through the
Service Usage Admin role (roles/serviceusage.serviceUsageAdmin).
Learn how to grant roles.
Certain Identity and Access Management (IAM) roles are required to
run the examples on this page. Depending on organization policies, these
roles may have already been granted. To check role grants, see
Do you need to grant roles?.
To get the permissions that
you need to create a Managed Service for Apache Spark cluster,
ask your administrator to grant you the
following IAM roles:
Service Account User (roles/iam.serviceAccountUser)
on the Compute Engine default service account
Service account role
To ensure that the Compute Engine default service account has the necessary
permissions to create a Managed Service for Apache Spark cluster,
ask your administrator to grant the
Dataproc Worker (roles/dataproc.worker) IAM role to the Compute Engine default service account on the project.
Create a Managed Service for Apache Spark cluster
Create a Managed Service for Apache Spark cluster with the Iceberg and Jupyter optional components.
To create the cluster, run the following gcloud command:
REGION: the Google Cloud region for the
cluster, for example, us-central1.
Note, setting dataproc:dataproc.lineage.enabled=true is not required for the Lakehouse runtime catalog Iceberg REST Catalog to work correctly. It is added for lineage tracking in the data lineage example below.
Connect to the cluster using a Jupyter Notebook. You can use a Vertex AI Workbench notebook or launch a notebook directly on the cluster.
Configure a Spark session
In your Jupyter Notebook, create a Spark session configured to use the Lakehouse runtime catalog
Iceberg REST Catalog.
CATALOG_NAME: a name for your Iceberg catalog,
for example, iceberg_catalog.
APP_NAME: the name of your Spark application.
GCS_BUCKET: the Cloud Storage bucket to store
your Iceberg table data.
PROJECT_ID: your Google Cloud project ID.
Manage data with Spark SQL
After you configure the Spark session, use Spark SQL to perform data management
operations.
Create a namespace. In the Lakehouse runtime catalog Iceberg REST Catalog, a namespace
corresponds to a BigQuery dataset.
spark.sql("CREATE NAMESPACE IF NOT EXISTS NAMESPACE_NAME")spark.sql("USE NAMESPACE_NAME")
Replace NAMESPACE_NAME with the name for your
namespace, for example, spark_lakehouse.
Create a base table in Iceberg format and insert data.
spark.sql("DROP TABLE IF EXISTS base_table PURGE")spark.sql("CREATE TABLE base_table (id LONG) USING iceberg")spark.sql("INSERT INTO base_table VALUES 0, 1, 2, 3, 4")spark.sql("SELECT * FROM base_table").show()
The output is similar to the following:
+---+
| id|
+---+
| 0|
| 1|
| 2|
| 3|
| 4|
+---+
Create a second table for new data.
spark.sql("DROP TABLE IF EXISTS newdata PURGE")spark.sql("CREATE TABLE newdata(id LONG) USING iceberg")spark.sql("INSERT INTO newdata VALUES 3, 4, 5, 6")spark.sql("SELECT * FROM newdata").show()
The output is similar to the following:
+---+
| id|
+---+
| 3|
| 4|
| 5|
| 6|
+---+
Merge the new data into the base table.
spark.sql("""MERGE INTO base_table USING newdata ON base_table.id = newdata.id WHEN MATCHED THEN UPDATE SET base_table.id = newdata.id WHEN NOT MATCHED THEN INSERT * """)spark.sql("SELECT * FROM base_table").show()
You can track data movement between Lakehouse runtime catalog
Iceberg REST Catalog tables
with data lineage, which
is available in Managed Service for Apache Spark 2.2 and later image versions.
Data lineage example
Create source and target Iceberg tables, then copy data.
spark.sql("DROP TABLE IF EXISTS source_table PURGE")spark.sql("DROP TABLE IF EXISTS target_table PURGE")spark.sql("CREATE TABLE source_table (id LONG) USING iceberg")spark.sql("""CREATE TABLE target_table USING ICEBERG AS SELECT max(id) as top_id FROM source_table """)
In the Google Cloud console, go to the Knowledge Catalog
Search page.
Search for one of the tables, and then click the Lineage tab:
Example of data lineage in the Knowledge Catalog page in the Google Cloud console.
Example of data lineage graph in the Knowledge Catalog page in the Google Cloud console.
Data lineage recognizes both the logical (Lakehouse runtime catalog table) and
physical (Cloud Storage) representations of Lakehouse runtime catalog
Iceberg REST Catalog tables.
Data lineage known issue
In some Managed Service for Apache Spark clusters the full data lineage may not be
generated due to an OpenLineage library issue.
Workaround: in the Spark session config, set the spark.sql.catalog.{catalog_name}.uri
property to https://biglake.googleapis.com/iceberg/v1beta/restcatalog.
[[["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 2026年08月26日 UTC."],[],[]]