Skip to content

feat(dataproc): create pyspark nodegroup cluster sample #13513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Supriya-Koppa
Copy link

Sample code to submit a PySpark job to a Dataproc driver node group cluster.

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

Sample code to submit a PySpark job to a Dataproc driver node group cluster.
@Supriya-Koppa Supriya-Koppa requested review from a team as code owners July 22, 2025 07:40
Copy link

snippet-bot bot commented Jul 22, 2025

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Jul 22, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @Supriya-Koppa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request adds a new, self-contained Python sample to the repository. Its primary purpose is to provide a clear and executable example for users looking to programmatically submit PySpark jobs to Dataproc clusters, specifically those configured with driver node groups, and to illustrate how to manage the job's resource allocation and retrieve its output.

Highlights

  • New Sample Code: Introduced a new Python sample, submit_pyspark_job_to_driver_node_group_cluster.py, demonstrating how to submit a PySpark job to a Google Cloud Dataproc cluster that utilizes a driver node group.
  • Dataproc Job Submission: The sample showcases the use of the google.cloud.dataproc_v1 client library to configure and submit a PySpark job, including specifying DriverSchedulingConfig for memory and vcores.
  • Output Retrieval: The code includes logic to retrieve and print the job's output from the Google Cloud Storage bucket where Dataproc stores job results.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a new Python sample for submitting a PySpark job to a Dataproc driver node group cluster. The code is a good starting point. My review includes suggestions for improving the script's usability by implementing command-line argument parsing, enhancing robustness with proper error handling, and increasing clarity and consistency through documentation and style adjustments. Addressing these points will make the sample more robust and user-friendly.

@Supriya-Koppa
Copy link
Author

hi @glasnt could you please review this PR?

it is similar to #13423

Thanks!

Copy link
Contributor

@glasnt glasnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your first submission to the python-docs-samples repo! 🎉

There are some changes required to this file, including:

  • moving it to the correct sample location for this product: dataproc/snippets/
  • including testing (you should be able to reference tests from similar samples in the dataproc folder as a starting point)

@glasnt glasnt changed the title Create submit_pyspark_job_to_driver_node_group_cluster.py feat(dataproc): create pyspark nodegroup cluster sample Jul 25, 2025
@product-auto-label product-auto-label bot added the api: dataproc Issues related to the Dataproc API. label Jul 25, 2025
@glasnt glasnt added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 8, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 8, 2025
@glasnt glasnt added the waiting-response Waiting for the author's response. label Aug 8, 2025
- moved the file to dataproc/snippets/
- updated the description for main_python_file_uri
@Supriya-Koppa Supriya-Koppa requested review from a team as code owners August 14, 2025 11:51
@@ -0,0 +1,91 @@
#!/usr/bin/env python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have not provided a test to go with this file. Given the similarity, you might be able to borrow from https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/dataproc/snippets/submit_spark_job_to_driver_node_group_cluster_test.py

job = {
"placement": {"cluster_name": cluster_name},
"pyspark_job": {
"main_python_file_uri": "gs://dataproc-examples/pyspark/hello-world/hello-world.py"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outstanding issue from previous review: "Where does this object come from? Is there open source code for this object?"

Comment on lines +86 to +91

my_project_id = "your_project_id" # <-- REPLACE THIS
my_region = "your_region" # <-- REPLACE THIS
my_cluster_name = "your_node_group_cluster" # <-- REPLACE THIS

submit_job(my_project_id, my_region, my_cluster_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outstanding comment from previous review: Please change this main method to copy the functionality from the spark job, which will remove the "REPLACE THIS" values. This can also help if you use command-line testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: dataproc Issues related to the Dataproc API. samples Issues that are directly related to samples. waiting-response Waiting for the author's response.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants