Github user koertkuipers commented on a diff in the pull request:

    https://github.com/apache/spark/pull/23173#discussion_r238068538
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVFileFormat.scala
 ---
    @@ -171,15 +171,21 @@ private[csv] class CsvOutputWriter(
     
       private var univocityGenerator: Option[UnivocityGenerator] = None
     
    -  override def write(row: InternalRow): Unit = {
    -    val gen = univocityGenerator.getOrElse {
    -      val charset = Charset.forName(params.charset)
    -      val os = CodecStreams.createOutputStreamWriter(context, new 
Path(path), charset)
    -      val newGen = new UnivocityGenerator(dataSchema, os, params)
    -      univocityGenerator = Some(newGen)
    -      newGen
    -    }
    +  if (params.headerFlag) {
    +    val gen = getGen()
    +    gen.writeHeaders()
    +  }
     
    +  private def getGen(): UnivocityGenerator = univocityGenerator.getOrElse {
    +    val charset = Charset.forName(params.charset)
    +    val os = CodecStreams.createOutputStreamWriter(context, new 
Path(path), charset)
    +    val newGen = new UnivocityGenerator(dataSchema, os, params)
    +    univocityGenerator = Some(newGen)
    +    newGen
    +  }
    +
    +  override def write(row: InternalRow): Unit = {
    +    val gen = getGen()
    --- End diff --
    
    ok i changed it to lazy val and flag


---

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

Reply via email to