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 @@ -62,9 +62,6 @@ private[sql] class CSVOptions(
val ignoreLeadingWhiteSpaceFlag = getBool("ignoreLeadingWhiteSpace")
val ignoreTrailingWhiteSpaceFlag = getBool("ignoreTrailingWhiteSpace")

// Limit the number of lines we'll search for a header row that isn't comment-prefixed
val MAX_COMMENT_LINES_IN_HEADER = 10

// Parse mode flags
if (!ParseModes.isValidMode(parseMode)) {
logWarning(s"$parseMode is not a valid parse mode. Using ${ParseModes.DEFAULT}.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ private[csv] class CSVRelation(
*/
private def findFirstLine(rdd: RDD[String]): String = {
if (params.isCommentSet) {
rdd.take(params.MAX_COMMENT_LINES_IN_HEADER)
.find(!_.startsWith(params.comment.toString))
.getOrElse(sys.error(s"No uncommented header line in " +
s"first ${params.MAX_COMMENT_LINES_IN_HEADER} lines"))
val comment = params.comment.toString
rdd.filter { line =>
line.trim.nonEmpty && !line.startsWith(comment)
}.first()
} else {
rdd.first()
rdd.filter { line =>
line.trim.nonEmpty
}.first()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions sql/core/src/test/resources/cars.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

year,make,model,comment,blank
"2012","Tesla","S","No comment",

Expand Down