Skip to content

Conversation

@jabbaugh
Copy link

What changes were proposed in this pull request?

The existing CSV DataSource allows one to set the delimiter/separator but does not allow the changing of the file extension. This means that a file can have values separated by tabs but me marked as a ".csv" file. This change allows one to change the file extension to match the delimiter/separator (e.g. ".tsv" for a tab separated value file).

Why are the changes needed?

This PR adds an additional option to set the fileExtension. The end result is that when a separator is set that is not a comma that the output file has a file extension that matches the separator (e.g. file.tsv, file.psv, etc...).

Notes on Previous Pull Request #17973
A pull request adding this option was discussed 7 years ago. One reason it wasn't added was:
"I would like to suggest to leave this out if there is no better reason for now. Downside of this is, it looks this allows arbitrary name and it does not gurantee the extention is, say, tsv when the delmiter is a tab. It is purely up to the user."

I don't believe this is a good reason to not let the user set the extension. If we let them set the delimiter/separator to an arbitrary string/char then why not let the user also set the file extension to specify the separator that the file uses (e.g. tsv, psv, etc...). This addition keeps the "csv" file extension as the default and has the benefit of allowing other separators to match the file extension.

Does this PR introduce any user-facing change?

Yes. This PR adds one row to the options table for the CSV DataSource documentation to include the "fileExtension" option.

How was this patch tested?

One unit test was added to validate a file is written with the new extension.

Was this patch authored or co-authored using generative AI tooling?

No

@jabbaugh jabbaugh force-pushed the jbaugh-add-csv-file-ext branch 2 times, most recently from cede15e to acd7d3e Compare December 18, 2024 21:18
@jabbaugh jabbaugh force-pushed the jbaugh-add-csv-file-ext branch from eee47c5 to de3b891 Compare December 18, 2024 21:50
@jabbaugh jabbaugh changed the title Add File Extension Option to CSV DataSource Writer [SPARK-50616] Add File Extension Option to CSV DataSource Writer Dec 18, 2024
@HyukjinKwon HyukjinKwon changed the title [SPARK-50616] Add File Extension Option to CSV DataSource Writer [SPARK-50616][SQL] Add File Extension Option to CSV DataSource Writer Dec 19, 2024
@jabbaugh jabbaugh force-pushed the jbaugh-add-csv-file-ext branch from de3b891 to 2ff5f81 Compare December 20, 2024 17:31
@github-actions github-actions bot added the CORE label Dec 20, 2024
@jabbaugh jabbaugh force-pushed the jbaugh-add-csv-file-ext branch 2 times, most recently from 3c63274 to ec7d8cc Compare December 20, 2024 22:11
@github-actions github-actions bot removed the CORE label Dec 20, 2024
Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use extension instead of fileExtension?

@jabbaugh jabbaugh force-pushed the jbaugh-add-csv-file-ext branch 5 times, most recently from 42721f7 to f9b7b0a Compare January 9, 2025 23:10
What changes were proposed in this pull request?
The existing CSV DataSource allows one to set the delimiter/separator but does not allow the changing of the file extension. This means that a file can have values separated by tabs but me marked as a ".csv" file. This change allows one to change the file extension to match the delimiter/separator (e.g. ".tsv" for a tab separated value file).

Why are the changes needed?
This PR adds an additional option to set the fileExtension. The end result is that when a separator is set that is not a comma that the output file has a file extension that matches the separator (e.g. file.tsv, file.psv, etc...).

Notes on Previous Pull Request apache#17973
A pull request adding this option was discussed 7 years ago. One reason it wasn't added was:
"I would like to suggest to leave this out if there is no better reason for now. Downside of this is, it looks this allows arbitrary name and it does not gurantee the extention is, say, tsv when the delmiter is a tab. It is purely up to the user."

I don't believe this is a good reason to not let the user set the extension. If we let them set the delimiter/separator to an arbitrary string/char then why not let the user also set the file extension to specify the separator that the file uses (e.g. tsv, psv, etc...). This addition keeps the "csv" file extension as the default and has the benefit of allowing other separators to match the file extension.

Does this PR introduce any user-facing change?
Yes. This PR adds one row to the options table for the CSV DataSource documentation to include the "fileExtension" option.

How was this patch tested?
One unit test was added to validate a file is written with the new extension.

Was this patch authored or co-authored using generative AI tooling?
No
@jabbaugh jabbaugh force-pushed the jbaugh-add-csv-file-ext branch from f9b7b0a to c9be504 Compare January 9, 2025 23:11
Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM. Thank you, @jabbaugh .
Merged to master for Apache Spark 4.0.0.

@dongjoon-hyun
Copy link
Member

Congratulations for your first commit.

I added you, James Baug, to the Apache Spark contributor group and assigned SPARK-50616 to you.

Welcome to the Apache Spark community, @jabbaugh !

@jabbaugh jabbaugh deleted the jbaugh-add-csv-file-ext branch January 10, 2025 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants