Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16680#discussion_r99530031
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVFileFormat.scala
 ---
    @@ -170,32 +111,21 @@ class CSVFileFormat extends TextBasedFileFormat with 
DataSourceRegister {
             }
           }
     
    -      // Consumes the header in the iterator.
    -      CSVRelation.dropHeaderLine(file, lineIterator, csvOptions)
    -
    -      val filteredIter = lineIterator.filter { line =>
    -        line.trim.nonEmpty && !line.startsWith(commentPrefix)
    +      val linesWithoutHeader = if (csvOptions.headerFlag && file.start == 
0) {
    +        // Note that if there are only comments in the first block, the 
header would probably
    +        // be not dropped.
    +        CSVUtils.dropHeaderLine(lines, csvOptions)
    +      } else {
    +        lines
           }
     
    +      val filteredLines = 
CSVUtils.filterCommentAndEmpty(linesWithoutHeader, csvOptions)
           val parser = new UnivocityParser(dataSchema, requiredSchema, 
csvOptions)
    -      filteredIter.flatMap(parser.parse)
    -    }
    -  }
    -
    -  /**
    -   * Returns the first line of the first non-empty file in path
    -   */
    -  private def findFirstLine(options: CSVOptions, lines: Dataset[String]): 
String = {
    -    import lines.sqlContext.implicits._
    -    val nonEmptyLines = lines.filter(length(trim($"value")) > 0)
    -    if (options.isCommentSet) {
    -      
nonEmptyLines.filter(!$"value".startsWith(options.comment.toString)).first()
    -    } else {
    -      nonEmptyLines.first()
    +      filteredLines.flatMap(parser.parse)
         }
       }
     
    -  private def readText(
    --- End diff --
    
    seems `readAsLines` is better?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to