Skip to content

feat: Add support for running Spark Connect client inside the Dataproc s8s batch - #150

Merged
ZhiweiLinnn merged 7 commits into
mainfrom
batch-session
Oct 10, 2025
Merged

feat: Add support for running Spark Connect client inside the Dataproc s8s batch#150
ZhiweiLinnn merged 7 commits into
mainfrom
batch-session

Conversation

@ZhiweiLinnn

Copy link
Copy Markdown
Contributor

For batch, we want initiated sessions.
Add integration test for batch environ

@ZhiweiLinnn
ZhiweiLinnn requested a review from medb October 9, 2025 22:11
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ZhiweiLinnn, 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 introduces essential support for running the Spark Connect client within Dataproc batch environments. The core change involves modifying the session creation mechanism to intelligently detect batch workloads and, under such conditions, ensure that the DataprocSparkSession correctly initializes or connects to a standard PySpark session. This adjustment is critical for batch jobs that expect pre-initiated Spark sessions, and its proper functioning is verified through newly added integration tests.

Highlights

  • Dataproc Batch Workload Detection: A new utility function, is_dataproc_batch(), has been added to environment.py to detect if the current execution environment is a Dataproc batch workload by checking the DATAPROC_WORKLOAD_TYPE environment variable.
  • Spark Session Handling for Batch Workloads: The DataprocSparkSession.getOrCreate() method in session.py has been updated. When a Dataproc batch workload is detected, it now defers to creating or getting a standard pyspark.sql.SparkSession instead of its custom Spark Connect session logic, aligning with the requirement for initiated sessions in batch environments.
  • Integration Test Coverage: New integration tests have been added in test_session.py to validate the behavior of DataprocSparkSession within a simulated batch workload environment. This includes fixtures for setting the batch environment and creating local Spark sessions, and a test to confirm that getOrCreate() returns a standard PySpark session in this context.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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.

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

Copy link
Copy Markdown
Contributor

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 support for running the Spark Connect client within a Dataproc serverless batch environment. When in a batch workload, instead of creating a new Dataproc session, it now correctly connects to the existing Spark session provided by the batch environment. The changes include a new environment detection function, a modification to the session creation logic, and new integration tests to verify this behavior.

My review has two main points:

  1. In session.py, the getOrCreate method's return type hint is now incorrect for batch environments. I've suggested adding a type: ignore to acknowledge this and prevent static analysis errors.
  2. In test_session.py, I've pointed out a redundant cleanup in the new integration test and suggested a simplification to align with pytest best practices for resource management.

Overall, the changes are logical and well-tested. Addressing these points will improve code correctness and maintainability.

Comment thread google/cloud/dataproc_spark_connect/session.py Outdated
Comment thread tests/integration/test_session.py
@medb medb changed the title Add support for running Spark Connect client inside the Dataproc s8s batch feat: Add support for running Spark Connect client inside the Dataproc s8s batch Oct 10, 2025
Comment thread google/cloud/dataproc_spark_connect/session.py Outdated
Comment thread google/cloud/dataproc_spark_connect/session.py Outdated
@ZhiweiLinnn
ZhiweiLinnn merged commit e5b1708 into main Oct 10, 2025
5 checks passed
@medb
medb deleted the batch-session branch October 10, 2025 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants