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

    https://github.com/apache/spark/pull/16976#discussion_r102651748
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/UnivocityParser.scala
 ---
    @@ -233,3 +236,28 @@ private[csv] class UnivocityParser(
         }
       }
     }
    +
    +private[csv] object UnivocityParser {
    +  def tokenizeStream(
    +      inputStream: InputStream,
    +      header: Boolean,
    +      settings: CsvParserSettings): Iterator[Array[String]] = new 
Iterator[Array[String]] {
    +    private val parser = new CsvParser(settings)
    +    // Note that, here we assume `inputStream` is the whole file that 
might include the header.
    +    parser.beginParsing(inputStream)
    +    private var nextRecord = {
    +      if (header) {
    +        parser.parseNext()
    +      }
    +      parser.parseNext()
    +    }
    +
    +    override def hasNext: Boolean = nextRecord != null
    +
    +    override def next(): Array[String] = {
    +      val curRecord = nextRecord
    --- End diff --
    
    nit: it's safer to add a check
    ```
    if (!hasNext) {
      throw new NoSuchElementException("End of stream")
    }
    ```


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