[SPARK-56255][PYTHON][CONNECT] Make spark.read.csv accept DataFrame input#55274
Open
Yicong-Huang wants to merge 1 commit intoapache:masterfrom
Open
[SPARK-56255][PYTHON][CONNECT] Make spark.read.csv accept DataFrame input#55274Yicong-Huang wants to merge 1 commit intoapache:masterfrom
Yicong-Huang wants to merge 1 commit intoapache:masterfrom
Conversation
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().Changes:
readwriter.py): Updatedcsv()to acceptDataFrameinput, delegating toPythonSQLUtils.csvFromDataFrame().connect/readwriter.py): Updatedcsv()to acceptDataFrameinput, using the existingParselogical plan withPARSE_FORMAT_CSV.PythonSQLUtils.scala): AddedcsvFromDataFrame()method that validates the input DataFrame has a StringType first column, then delegates toDataFrameReader.csv().Why are the changes needed?
spark.read.json()already supports DataFrame input (SPARK-56253), butspark.read.csv()does not. This inconsistency means users who want to parse CSV strings stored in a DataFrame must use workarounds. Adding DataFrame support tocsv()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:
test_csv_with_dataframe_input(classic + connect)test_csv_with_dataframe_input_and_schema(classic + connect)test_csv_with_dataframe_input_non_string_column(classic + connect)test_csv_with_dataframe_input_multiple_columns(classic + connect)test_csv_with_dataframe_input_zero_columns(classic + connect)All tests pass locally.
Was this patch authored or co-authored using generative AI tooling?
No.