Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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 @@ -188,12 +188,13 @@ class UnivocityParser(
}
}

private val doParse = if (requiredSchema.nonEmpty) {
(input: String) => convert(tokenizer.parseLine(input))
} else {
private val doParse = if (options.columnPruning && requiredSchema.isEmpty) {
// If `columnPruning` enabled and partition attributes scanned only,
// `schema` gets empty.
(_: String) => InternalRow.empty
Comment thread
HyukjinKwon marked this conversation as resolved.
} else {
// parse if the columnPruning is disabled or requiredSchema is nonEmpty
(input: String) => convert(tokenizer.parseLine(input))
}

/**
Expand Down
5 changes: 5 additions & 0 deletions sql/core/src/test/resources/test-data/malformedRow.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fruit,color,price,quantity
apple,red,1,3
banana,yellow,2,4
orange,orange,3,5
malformedrow
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CSVSuite extends QueryTest with SharedSparkSession with TestCsvData {
private val unescapedQuotesFile = "test-data/unescaped-quotes.csv"
private val valueMalformedFile = "test-data/value-malformed.csv"
private val badAfterGoodFile = "test-data/bad_after_good.csv"
private val malformedRowFile = "test-data/malformedRow.csv"

/** Verifies data and schema. */
private def verifyCars(
Expand Down Expand Up @@ -2109,4 +2110,17 @@ class CSVSuite extends QueryTest with SharedSparkSession with TestCsvData {
"expect the TextParsingException truncate the error content to be 1000 length.")
}
}

test("SPARK-29101 test count with DROPMALFORMED mode") {
Seq((true, 4), (false, 3)).foreach { case (csvColumnPruning, expectedCount) =>
withSQLConf(SQLConf.CSV_PARSER_COLUMN_PRUNING.key -> csvColumnPruning.toString) {
val count = spark.read
.option("header", "true")
.option("mode", "DROPMALFORMED")
.csv(testFile(malformedRowFile))
.count()
assert(expectedCount == count)
}
}
}
}