Repository navigation
[SPARK-60775][SQL][PYTHON] Add SparkSession.getOrCreate for dataframes - #60000
Open
amoghrajesh wants to merge 1 commit into
Open
amoghrajesh wants to merge 1 commit into
amoghrajesh wants to merge 1 commit into
Conversation
Given a path, load the dataset if it is already there; otherwise compute it, store it as Parquet, and return it. Lets a rerun skip work an earlier run finished. Classic only. Completeness is tracked with a marker file instead of reusing `_SUCCESS`, which can be disabled or left by an unrelated writer.
amoghrajesh
force-pushed
the
SPARK-60775
branch
from
November 1, 2026 11:10
311a0d7 to
891a647
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Given a path, load the dataset if it is already there; otherwise compute it, store it as Parquet, and return it. Lets a rerun skip work an earlier run finished.
Classic only. Completeness is tracked with a marker file instead of reusing
_SUCCESS, which can be disabled or left by an unrelated writer.What changes were proposed in this pull request?
Adds
SparkSession.getOrCreate(path, create)to Spark Classic, in Scala andPySpark.
First call computes and saves. Later calls load and skip the work. A marker file records completeness, so a path left by an interrupted write is recomputed.
Classic only,
DataFramenotDataset[T], Parquet hardcoded, caller supplies the path.Why are the changes needed?
A batch job that dies in a late stage reruns from the start. Under an orchestrator, users pay for the same stages twice, usually after a spot reclaim where the same code would have worked.
People hand-roll this today and get it wrong quietly: a path-exists check returns partial data, and a
_SUCCESScheck returns an unrelated job's data. Both report success.Dev list: Thoughts around getOrCreate for Dataset / DataFrame
Does this PR introduce any user-facing change?
Yes, a new public method. No change to existing APIs.
How was this patch tested?
New suites in Scala and PySpark, three tests each: computes on first call, loads instead of recomputing, recomputes when the marker is absent.
Pyspark
Using this function for the test - imitates a function run by daily pipeline that passes in the date
Result:
Listing the files:
Scala
Running same / similar case with scala. Run the shell first:
./bin/spark-shellLets use this block:
Running this:
That notes the time, calls getOrCreate on an empty path, counts the rows, then prints how long it took and how many times the work ran.
Then this:
Daily pipeline similar to pyspark
Result:
Open questions
Was this patch authored or co-authored using generative AI tooling?
Yes, Claude Code - sonnet