You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by HyukjinKwon <gi...@git.apache.org> on 2018/12/01 09:58:06 UTC
[GitHub] spark pull request #23173: [SPARK-26208][SQL] add headers to empty csv files...
Github user HyukjinKwon commented on a diff in the pull request:
https://github.com/apache/spark/pull/23173#discussion_r238058594
--- 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 --
Wait .. is this going to create `UnivocityGenerator` for each record?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org