-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-20978][SQL] Set null for malformed column when the number of tokens is less than schema in CSV read/permissive mode #18200
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1174,4 +1174,12 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { | |
| } | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-20978: Set null for malformed column when the number of tokens is less than schema") { | ||
| val df = spark.read | ||
| .schema("a string, b string, unparsed string") | ||
| .option("columnNameOfCorruptRecord", "unparsed") | ||
| .csv(Seq("a").toDS()) | ||
| checkAnswer(df, Row("a", null, null)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not read the code yet, but it looks like the result is wrong? We should output the In addition, this scenario works if we pass the csv files that contain less column values than the schema, right?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for cutting in, but how to handle these longer/shorter cases is some arguable as @HyukjinKwon said in #16928 (comment). IMHO currently we just regard shorter cases as not-corrupted so as to keep existing behaviour (the previous Spark releases have regarded these case as not-corrupted, so other developers said that this behaviour change was not acceptable in earlier prs).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this PR, you can try this example. val corruptCVSRecords: Dataset[String] =
spark.createDataset(spark.sparkContext.parallelize(
"""1997, "b"""" ::
"""2015""" :: Nil))(Encoders.STRING)
val df1 = spark.read
.schema("col1 int, col2 String, __corrupted_column_name string")
.option("columnNameOfCorruptRecord", "__corrupted_column_name")
.option("mode", PermissiveMode.name)
.csv(corruptCVSRecords)
df1.show()The output result of |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
BTW, this looks only called when PERMISSIVE mode when the malformed column is defined.
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.
Look so, is this something wrong?
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.
(Sorry, I meant just a note for a review ...)
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.
(oh, ... sorry)