[SPARK-56255][PYTHON][CONNECT] Make spark.read.csv accept DataFrame input#55274
Closed
Yicong-Huang wants to merge 10 commits intoapache:masterfrom
Closed
[SPARK-56255][PYTHON][CONNECT] Make spark.read.csv accept DataFrame input#55274Yicong-Huang wants to merge 10 commits intoapache:masterfrom
Yicong-Huang wants to merge 10 commits intoapache:masterfrom
Conversation
HyukjinKwon
reviewed
Apr 12, 2026
|
|
||
| from pyspark.sql.connect.dataframe import DataFrame | ||
|
|
||
| if isinstance(path, DataFrame): |
Member
There was a problem hiding this comment.
I think it's safer to add this if dataframe check first with return to avoid any behaviour changes. e.g., we might support sth else than list.
Contributor
Author
There was a problem hiding this comment.
Make sense. moved the check up.
HyukjinKwon
reviewed
Apr 12, 2026
| df: DataFrame): DataFrame = { | ||
| val classicReader = reader.asInstanceOf[ClassicDataFrameReader] | ||
| val fields = df.schema.fields | ||
| if (fields.isEmpty) { |
Contributor
Author
There was a problem hiding this comment.
Done. Applied the same pattern to reject multi-column input.
679a1f1 to
c8868ea
Compare
hvanhovell
reviewed
Apr 13, 2026
| def csvFromDataFrame( | ||
| reader: DataFrameReader, | ||
| df: DataFrame): DataFrame = { | ||
| val classicReader = reader.asInstanceOf[ClassicDataFrameReader] |
Contributor
There was a problem hiding this comment.
This the same code as above. Create a util for this?
Contributor
Author
There was a problem hiding this comment.
Makes sense. Extracted a helper method.
HyukjinKwon
approved these changes
Apr 13, 2026
Member
|
Merged to master. |
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.
What changes were proposed in this pull request?
This PR adds support for passing a
DataFramecontaining CSV strings directly tospark.read.csv(), following the same pattern established by #55097 (SPARK-56253) forspark.read.json().Why are the changes needed?
Adding DataFrame support to
csv()makes the API consistent withjson()and enables Connect-compatible CSV parsing withoutsc.parallelize().Does this PR introduce any user-facing change?
Yes.
spark.read.csv()now accepts aDataFramewith a single string column as input, in addition to the existingstr,list, andRDDinputs.How was this patch tested?
Added 10 new test cases.
Was this patch authored or co-authored using generative AI tooling?
No.