Skip to content
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

[SPARK-31261][SQL] Avoid npe when reading bad csv input with columnNameCorruptRecord specified #28029

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ class UnivocityParser(

// Retrieve the raw record string.
private def getCurrentInput: UTF8String = {
UTF8String.fromString(tokenizer.getContext.currentParsedContent().stripLineEnd)
val currentContent = tokenizer.getContext.currentParsedContent()
if (currentContent == null) null else UTF8String.fromString(currentContent.stripLineEnd)
}

// This parser first picks some tokens from the input tokens, according to the required schema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1895,6 +1895,13 @@ abstract class CSVSuite extends QueryTest with SharedSparkSession with TestCsvDa
checkAnswer(spark.read.schema(schema).csv(input), Row(null))
checkAnswer(spark.read.option("multiLine", true).schema(schema).csv(input), Row(null))
assert(spark.read.csv(input).collect().toSet == Set(Row()))

val schemaWithCorruptField = schema.add("_corrupt_record", StringType)
wzhfy marked this conversation as resolved.
Show resolved Hide resolved
checkAnswer(
spark.read
.option("columnNameOfCorruptRecord", "_corrupt_record")
.schema(schemaWithCorruptField).csv(input),
Row(null, null))
}

test("field names of inferred schema shouldn't compare to the first row") {
Expand Down