Develops and executes Spark code on Managed Spark on Google Cloud (Dataproc Clusters and Serverless). Reads and writes data using BigLake Iceberg catalogs, BigQuery and Spanner. Debugs execution failures. Use when: - Writing Spark ETL pipelines on Google Cloud Platform. - Training or running inference with Machine Learning models with spark on Google Cloud Platform. - Managing Spark clusters, jobs, batches, and interactive sessions. Don't use when: - Writing generic Python scripts that don't use Spark. - Performing simple SQL queries that can be done directly in BigQuery.
You MUST ALWAYS follow the Task Execution Workflow when writing spark code.
Task Execution Workflow
Understand schemas: ALWAYS use @skill:discovering-gcp-data-assets
skill or references/schema_direct_inspection.md to understand input and
output schemas. Include the schema in your thought process BEFORE generating
any code. Do NOT guess column names. Unless explicitly specified, assume
that the assets are located in the same project. Avoid scanning for assets
across other projects as it can take a long time. If an expected dataset or
table does not exist, use @skill:discovering-gcp-data-assets to discover
all similar tables in the namespace or project.
MINOR TYPO RULE: If there is a minor typo (e.g. employees vs
employee), you can fix the error and proceed.
STRICT HALT RULE: If the discovered table names differ from the requested
table by more than a minor typo (e.g. completely different words, prefixes,
or suffixes), you must IMMEDIATELY report the missing table and a neutral
list of all available alternatives in the same namespace to the user without
making any recommendations. You MUST ask the user which alternative to use
and then STOP EXECUTING your turn. Do NOT write any Spark code or notebooks.
Do NOT proceed with code generation, do NOT add fallback logic to code, and
do NOT automatically substitute any alternative table (even if its schema
seems to match) without explicit user permission.
Verify source accessibility: verify access/existence using gcloud storage ls gs://<path-to-dataset>. If accessing or reading a GCS path fails
with a storage error e.g., permission errors like 403 Forbidden/Forbidden/PermissionDenied, or location errors like 404 Not Found/NotFound/FileNotFoundException you should report the error
immediately. Either (1) ask the user what to do next, or (2) if asked to
execute a notebook, save the notebook with the error output and recommend
next steps to resolve the issue. Do NOT scan all buckets for alternative
fallback datasets when encountering GCS errors.
Generate spark code:
Output Format: ALWAYS generate code in Python Notebooks
(.ipynb) format. Generate scripts (.py) only if explicitly requested.
Read and Write data: ALWAYS Refer to
references/read_write_data.md when reading or writing data.
Machine Learning Tasks: Refer to @skill:ml-best-practices skill and
references/ml_tasks.md when generating Machine Learning code.
Spark Optimizations: ALWAYS refer to
references/spark_optimizations.md when generating spark code and apply
optimization whenever applicable.
Verify schema before write: ALWAYS verify that the dataframe and
destination schema match, use df.printSchema() for dataframe schema and
refer to @skill:discovering-gcp-data-assets skill or
references/schema_direct_inspection.md to verify destination schema.
Compile code before executing: For notebooks convert them to python
script using jupyter nbconvert --to script your-notebook.ipynb first. Then
compile the resulting python script using python3 -m py_compile your-script.py. The same can be done for pyspark source code.
Execute script: When requested to run a job, script, session, or Spark
Connect session, refer to references/gcloud_dataproc.md on how to execute
generated code on Managed Spark. This DOES NOT apply when generating
notebooks.
Common Mistakes Checklist
[!CAUTION]
Ensure you verify this checklist to avoid mistakes
Before submitting a job, verify:
All imports present (col, when, lit, etc. from
pyspark.sql.functions)
vector_to_array from correct module use from pyspark.ml.functions import vector_to_array (NOT pyspark.sql.functions)
DataFrame schema matches target Iceberg table verify with
df.printSchema() before writing
CSV files read with header and inferSchema without these, the
header row becomes data and all columns are strings
Driver memory safety (toPandas() / collect()) NEVER call
.toPandas() or .collect() on raw or un-aggregated DataFrames. ALWAYS
perform transformations, aggregations (groupBy().agg()), or data reduction
(limit(), sample()) in Spark before converting small summaries to Pandas
for plotting or display.
No inline pip install in Spark jobs: NEVER run pip install or
subprocess package installations inside PySpark scripts. Pass dependencies
using --properties=spark.jars.packages=...,
--archives=gs://.../env.tar.gz#environment, --py-files, or a custom
--container-image.
IAM Requirements
The Managed Spark (Dataproc) service account needs:
roles/dataproc.worker: Job execution
roles/biglake.admin: Iceberg table management
roles/bigquery.jobUser: Query materialization
roles/storage.objectUser: Read/write GCS
roles/spanner.databaseUser: Spanner writes
Spark resource management
Refer to references/gcloud_dataproc.md for detailed guidelines on managing
Spark clusters, jobs, batches, interactive sessions, and Spark Connect sessions.
1---2name: gcp-spark3description: |4 Develops and executes Spark code on Managed Spark on Google Cloud (Dataproc Clusters and Serverless).5 Reads and writes data using BigLake Iceberg catalogs, BigQuery and Spanner.6 Debugs execution failures.7 Use when:8 - Writing Spark ETL pipelines on Google Cloud Platform.9 - Training or running inference with Machine Learning models with spark on Google Cloud Platform.10 - Managing Spark clusters, jobs, batches, and interactive sessions.11 Don't use when:12 - Writing generic Python scripts that don't use Spark.13 - Performing simple SQL queries that can be done directly in BigQuery.14license: Apache-2.015metadata:16 version: v1117 publisher: google18---1920# Managed Spark on Google Cloud2122> [!IMPORTANT]23>24> You MUST ALWAYS follow the Task Execution Workflow when writing spark code.2526## Task Execution Workflow27281. **Understand schemas**: **ALWAYS** use `@skill:discovering-gcp-data-assets`29 skill or `references/schema_direct_inspection.md` to understand input and30 output schemas. Include the schema in your thought process BEFORE generating31 any code. Do NOT guess column names. Unless explicitly specified, assume32 that the assets are located in the same project. Avoid scanning for assets33 across other projects as it can take a long time. If an expected dataset or34 table does not exist, use `@skill:discovering-gcp-data-assets` to discover35 all similar tables in the namespace or project.3637 *MINOR TYPO RULE*: If there is a minor typo (e.g. `employees` vs38 `employee`), you can fix the error and proceed.3940 *STRICT HALT RULE*: If the discovered table names differ from the requested41 table by more than a minor typo (e.g. completely different words, prefixes,42 or suffixes), you must IMMEDIATELY report the missing table and a neutral43 list of all available alternatives in the same namespace to the user without44 making any recommendations. You MUST ask the user which alternative to use45 and then STOP EXECUTING your turn. Do NOT write any Spark code or notebooks.46 Do NOT proceed with code generation, do NOT add fallback logic to code, and47 do NOT automatically substitute any alternative table (even if its schema48 seems to match) without explicit user permission.492. **Verify source accessibility**: verify access/existence using `gcloud50 storage ls gs://<path-to-dataset>`. If accessing or reading a GCS path fails51 with a storage error e.g., permission errors like `40352 Forbidden`/`Forbidden`/`PermissionDenied`, or location errors like `404 Not53 Found`/`NotFound`/`FileNotFoundException` you should report the error54 immediately. Either (1) ask the user what to do next, or (2) if asked to55 execute a notebook, save the notebook with the error output and recommend56 next steps to resolve the issue. Do NOT scan all buckets for alternative57 fallback datasets when encountering GCS errors.583. **Generate spark code**:5960 * **Output Format**: **ALWAYS** generate code in **Python Notebooks61 (.ipynb)** format. Generate scripts (.py) only if explicitly requested.62 * **Read and Write data**: **ALWAYS** Refer to63 `references/read_write_data.md` when reading or writing data.64 * **Machine Learning Tasks**: Refer to `@skill:ml-best-practices` skill and65 `references/ml_tasks.md` when generating Machine Learning code.66 * **Spark Optimizations**: **ALWAYS** refer to67 `references/spark_optimizations.md` when generating spark code and apply68 optimization whenever applicable.694. **Verify schema before write**: **ALWAYS** verify that the dataframe and70 destination schema match, use `df.printSchema()` for dataframe schema and71 refer to `@skill:discovering-gcp-data-assets` skill or72 `references/schema_direct_inspection.md` to verify destination schema.735. **Compile code before executing**: For notebooks convert them to python74 script using `jupyter nbconvert --to script your-notebook.ipynb` first. Then75 compile the resulting python script using `python3 -m py_compile76 your-script.py`. The same can be done for pyspark source code.776. **Execute script**: When requested to run a job, script, session, or Spark78 Connect session, refer to `references/gcloud_dataproc.md` on how to execute79 generated code on Managed Spark. This DOES NOT apply when generating80 notebooks.8182--------------------------------------------------------------------------------8384## Common Mistakes Checklist8586> [!CAUTION]87>88> Ensure you verify this checklist to avoid mistakes8990Before submitting a job, verify:9192- [ ] **All imports present** (`col`, `when`, `lit`, etc. from93 `pyspark.sql.functions`)94- [ ] **`vector_to_array` from correct module** use `from pyspark.ml.functions95 import vector_to_array` (NOT `pyspark.sql.functions`)96- [ ] **DataFrame schema matches target Iceberg table** verify with97 `df.printSchema()` before writing98- [ ] **CSV files read with `header` and `inferSchema`** without these, the99 header row becomes data and all columns are strings100- [ ] **Driver memory safety (`toPandas()` / `collect()`)** NEVER call101 `.toPandas()` or `.collect()` on raw or un-aggregated DataFrames. ALWAYS102 perform transformations, aggregations (`groupBy().agg()`), or data reduction103 (`limit()`, `sample()`) in Spark before converting small summaries to Pandas104 for plotting or display.105- [ ] **No inline pip install in Spark jobs**: NEVER run pip install or106 subprocess package installations inside PySpark scripts. Pass dependencies107 using --properties=spark.jars.packages=...,108 --archives=gs://.../env.tar.gz#environment, --py-files, or a custom109 --container-image.110111--------------------------------------------------------------------------------112113## IAM Requirements114115The Managed Spark (Dataproc) service account needs:116117* `roles/dataproc.worker`: Job execution118* `roles/biglake.admin`: Iceberg table management119* `roles/bigquery.jobUser`: Query materialization120* `roles/storage.objectUser`: Read/write GCS121* `roles/spanner.databaseUser`: Spanner writes122123--------------------------------------------------------------------------------124125## Spark resource management126127Refer to `references/gcloud_dataproc.md` for detailed guidelines on managing128Spark clusters, jobs, batches, interactive sessions, and Spark Connect sessions.
Run npx skillmds@latest add gemini-cli-extensions-data-agent-kit-starter-pack/gcp-spark in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Develops and executes Spark code on Managed Spark on Google Cloud (Dataproc Clusters and Serverless). Reads and writes data using BigLake Iceberg catalogs, BigQuery and Spanner. Debugs execution failures. Use when: - Writing Spark ETL pipelines on Google Cloud Platform. - Training or running inference with Machine Learning models with spark on Google Cloud Platform. - Managing Spark clusters, jobs, batches, and interactive sessions. Don't use when: - Writing generic Python scripts that don't use Spark. - Performing simple SQL queries that can be done directly in BigQuery. It is listed under DevOps & Infra on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. Capability flags: docs only. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free. This skill is licensed under Apache-2.
gemini-cli-extensions (@gemini-cli-extensions-data-agent-kit-starter-pack) published this skill. Their other Agent Skills are listed on their SkillMD profile.