-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Create submit_pyspark_job_to_driver_node_group_cluster.py #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
base: main
Are you sure you want to change the base?
Conversation
Sample code to submit a PySpark job to a Dataproc driver node group cluster.
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this 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 specifyingDriverSchedulingConfig
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
-
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. ↩
There was a problem hiding this 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.
my_project_id = "your_cluster" # <-- REPLACE THIS | ||
my_region = "us-central1" # <-- REPLACE THIS | ||
my_cluster_name = "your-node-group-cluster" # <-- REPLACE THIS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script uses hardcoded placeholder values, which requires users to manually edit the file before running it. To make the sample easier to use and consistent with other samples in the repository, it should parse command-line arguments.
Additionally, the placeholder value for my_project_id
is "your_cluster"
, which is confusing. It should be something like "your-project-id"
.
Please consider replacing the current implementation with one that uses sys.argv
for argument parsing.
if __name__ == "__main__":
import sys
if len(sys.argv) != 4:
sys.exit(
f"Usage: python {sys.argv[0]} <project_id> <region> <cluster_name>"
)
project_id = sys.argv[1]
region = sys.argv[2]
cluster_name = sys.argv[3]
submit_job(project_id, region, cluster_name)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
corrected the placeholder value for my_project_id.
I intend the main function to be as is.
# python submit_pyspark_job_to_driver_node_group_cluster.py \ | ||
# --project_id <PROJECT_ID> --region <REGION> \ | ||
# --cluster_name <CLUSTER_NAME> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Usage
example suggests named arguments (--project_id
), but other samples in this directory (e.g., submit_job.py
) use positional arguments. To maintain consistency across samples, consider updating this to reflect positional arguments.
# python submit_pyspark_job_to_driver_node_group_cluster.py \ | |
# --project_id <PROJECT_ID> --region <REGION> \ | |
# --cluster_name <CLUSTER_NAME> | |
# python submit_pyspark_job_to_driver_node_group_cluster.py \ | |
# <PROJECT_ID> <REGION> <CLUSTER_NAME> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
import re | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
# Create the job config. 'main_jar_file_uri' can also be a | ||
# Google Cloud Storage URL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Added a END region tag
Improving readability
There was a problem hiding this 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)
@@ -0,0 +1,91 @@ | |||
#!/usr/bin/env python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs to be moved to the dataproc/snippets
folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please clarify that the existing "submit_spark_job_to_driver_node_group_cluster.py" sample is different to this "submit_pyspark_job_to_driver_node_group_cluster.py` sample.
# Create the job config. 'main_python_file_uri' can also be a | ||
# Google Cloud Storage URL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, the value already is a Storage URL. This comment should be updated.
job = { | ||
"placement": {"cluster_name": cluster_name}, | ||
"pyspark_job": { | ||
"main_python_file_uri": "gs://dataproc-examples/pyspark/hello-world/hello-world.py" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this object come from? Is there open source code for this object?
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
python-docs-samples/dataproc/snippets/submit_spark_job_to_driver_node_group_cluster.py
Line 93 in e06d3cf
parser = argparse.ArgumentParser( |
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
nox -s py-3.9
(see Test Environment Setup)nox -s lint
(see Test Environment Setup)