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 @@ -203,12 +203,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
} 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 @@ -62,6 +62,7 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils with Te
private val datesFile = "test-data/dates.csv"
private val unescapedQuotesFile = "test-data/unescaped-quotes.csv"
private val valueMalformedFile = "test-data/value-malformed.csv"
private val malformedRowFile = "test-data/malformedRow.csv"

/** Verifies data and schema. */
private def verifyCars(
Expand Down Expand Up @@ -1861,4 +1862,17 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils with Te
}
}
}

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)
}
}
}
}