-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19709][SQL] Read empty file with CSV data source #17068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1c80d4c
Fix: SPARK-19709 CSV datasource fails to read empty file
wojtek-szymanski 90f315c
test renamed
wojtek-szymanski aca1852
take(1).headOption instated of exception handling on empty CSV data f…
wojtek-szymanski aa4e315
master merged
wojtek-szymanski bdf1890
Code cleanup
wojtek-szymanski 351d4ba
Pattern matching over chaining calls on Option. Unified solution in t…
wojtek-szymanski b9e9a84
revert changes in tests
wojtek-szymanski e7faa80
scala style fixed
wojtek-szymanski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -298,13 +298,21 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { | |
| test("test with empty file and known schema") { | ||
| val result = spark.read | ||
| .format("csv") | ||
| .schema(StructType(List(StructField("column", StringType, false)))) | ||
| .schema(StructType(List(StructField("column", StringType, nullable = false)))) | ||
| .load(testFile(emptyFile)) | ||
|
|
||
| assert(result.collect.size === 0) | ||
| assert(result.collect().isEmpty) | ||
| assert(result.schema.fieldNames.size === 1) | ||
| } | ||
|
|
||
| test("test with empty file without schema") { | ||
|
||
| val result = spark.read | ||
| .csv(testFile(emptyFile)) | ||
|
|
||
| assert(result.collect().isEmpty) | ||
| assert(result.schema.fieldNames.isEmpty) | ||
| } | ||
|
|
||
| test("DDL test with empty file") { | ||
| withView("carsTable") { | ||
| spark.sql( | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @wojtek-szymanski I think we should not rely on exception handling. I can think of
take(1).headOptionbut we could use shorten one if you know any other good way. What do you think about this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolutely right. Relying on exception handling is smelly, while
Optiongives more opportunities. I also see no difference from performance point of view, since bothfirst()andtake(1)call the the same functionhead(1).