HyukjinKwon commented on a change in pull request #29516:
URL: https://github.com/apache/spark/pull/29516#discussion_r476085489



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv/CSVExprUtils.scala
##########
@@ -25,16 +25,21 @@ object CSVExprUtils {
    * This is currently being used in CSV reading path and CSV schema inference.
    */
   def filterCommentAndEmpty(iter: Iterator[String], options: CSVOptions): 
Iterator[String] = {
-    iter.filter { line =>
-      line.trim.nonEmpty && !line.startsWith(options.comment.toString)
+    if (options.isCommentSet) {
+      val commentPrefix = options.comment.toString
+      iter.filter { line =>
+        line.trim.nonEmpty && !line.startsWith(commentPrefix)
+      }
+    } else {
+      iter.filter(_.trim.nonEmpty)
     }
   }
 
   def skipComments(iter: Iterator[String], options: CSVOptions): 
Iterator[String] = {
     if (options.isCommentSet) {
       val commentPrefix = options.comment.toString
       iter.dropWhile { line =>
-        line.trim.isEmpty || line.trim.startsWith(commentPrefix)
+        line.trim.isEmpty || line.startsWith(commentPrefix)

Review comment:
       @srowen, I think we should fix here too:
   
   ```diff
   --- 
a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVUtils.scala
   +++ 
b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVUtils.scala
   @@ -34,12 +34,12 @@ object CSVUtils {
        // might have to be removed in the near future if possible.
        import lines.sqlContext.implicits._
        val aliased = lines.toDF("value")
   -    val nonEmptyLines = aliased.filter(length(trim($"value")) > 0)
   -    if (options.isCommentSet) {
   -      
nonEmptyLines.filter(!$"value".startsWith(options.comment.toString)).as[String]
   +    val df = if (options.isCommentSet) {
   +      aliased.filter(!$"value".startsWith(options.comment.toString))
        } else {
   -      nonEmptyLines.as[String]
   +      aliased
        }
   +    df.filter(length(trim($"value")) > 0).as[String]
      }
   
      /**
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to