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

    https://github.com/apache/spark/pull/13431#discussion_r65305387
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/text/TextFileFormat.scala
 ---
    @@ -96,16 +96,23 @@ class TextFileFormat extends FileFormat with 
DataSourceRegister {
           sparkSession.sparkContext.broadcast(new 
SerializableConfiguration(hadoopConf))
     
         (file: PartitionedFile) => {
    -      val unsafeRow = new UnsafeRow(1)
    -      val bufferHolder = new BufferHolder(unsafeRow)
    -      val unsafeRowWriter = new UnsafeRowWriter(bufferHolder, 1)
    -
    -      new HadoopFileLinesReader(file, 
broadcastedHadoopConf.value.value).map { line =>
    -        // Writes to an UnsafeRow directly
    -        bufferHolder.reset()
    -        unsafeRowWriter.write(0, line.getBytes, 0, line.getLength)
    -        unsafeRow.setTotalSize(bufferHolder.totalSize())
    -        unsafeRow
    +      val reader = new HadoopFileLinesReader(file, 
broadcastedHadoopConf.value.value)
    +
    +      if (requiredSchema.isEmpty) {
    +        val emptyUnsafeRow = new UnsafeRow(0)
    +        reader.map(_ => emptyUnsafeRow)
    +      } else {
    +        val unsafeRow = new UnsafeRow(1)
    --- End diff --
    
    should we add an assert to guarantee `requiredSchema` has less than one 
element?


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