aboutsummaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorhyukjinkwon <gurwls223@gmail.com>2016-02-21 13:21:59 -0800
committerReynold Xin <rxin@databricks.com>2016-02-21 13:21:59 -0800
commit7eb83fefd19e137d80a23b5174b66b14831c291a (patch)
treead57156e0eaff85aea164b14cc9de7fcbc65de91 /sql
parentb6a873d6d4682796f55dbafadd0b5cad881f96ea (diff)
downloadspark-7eb83fefd19e137d80a23b5174b66b14831c291a.tar.gz
spark-7eb83fefd19e137d80a23b5174b66b14831c291a.tar.bz2
spark-7eb83fefd19e137d80a23b5174b66b14831c291a.zip
[SPARK-13137][SQL] NullPoingException in schema inference for CSV when the first line is empty
https://issues.apache.org/jira/browse/SPARK-13137 This PR adds a filter in schema inference so that it does not emit NullPointException. Also, I removed `MAX_COMMENT_LINES_IN_HEADER `but instead used a monad chaining with `filter()` and `first()`. Lastly, I simply added a newline rather than adding a new file for this so that this is covered with the original tests. Author: hyukjinkwon <gurwls223@gmail.com> Closes #11023 from HyukjinKwon/SPARK-13137.
Diffstat (limited to 'sql')
-rw-r--r--sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVOptions.scala3
-rw-r--r--sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVRelation.scala12
-rw-r--r--sql/core/src/test/resources/cars.csv1
3 files changed, 8 insertions, 8 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVOptions.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVOptions.scala
index bea8e97a9a..38aa2dd80a 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVOptions.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVOptions.scala
@@ -75,9 +75,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}.")
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVRelation.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVRelation.scala
index f8e3a1b6d4..471ed0d560 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVRelation.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVRelation.scala
@@ -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()
}
}
}
diff --git a/sql/core/src/test/resources/cars.csv b/sql/core/src/test/resources/cars.csv
index 2b9d74ca60..40ded573ad 100644
--- a/sql/core/src/test/resources/cars.csv
+++ b/sql/core/src/test/resources/cars.csv
@@ -1,3 +1,4 @@
+
year,make,model,comment,blank
"2012","Tesla","S","No comment",