Skip to content

Commit

Permalink
avoid npe
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhfy committed Mar 26, 2020
1 parent f206bbd commit bdc3d77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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)
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

0 comments on commit bdc3d77

Please sign in to comment.