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

    https://github.com/apache/spark/pull/12002#discussion_r57595023
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/DefaultSource.scala
 ---
    @@ -91,6 +96,70 @@ class DefaultSource extends FileFormat with 
DataSourceRegister {
         new CSVOutputWriterFactory(csvOptions)
       }
     
    +  override def buildReader(
    +      sqlContext: SQLContext,
    +      physicalSchema: StructType,
    +      partitionSchema: StructType,
    +      dataSchema: StructType,
    +      filters: Seq[Filter],
    +      options: Map[String, String]): (PartitionedFile) => 
Iterator[InternalRow] = {
    +    val csvOptions = new CSVOptions(options)
    +    val headers = dataSchema.fields.map(_.name)
    +
    +    val conf = new 
Configuration(sqlContext.sparkContext.hadoopConfiguration)
    +    val broadcastedConf = sqlContext.sparkContext.broadcast(new 
SerializableConfiguration(conf))
    +
    +    (file: PartitionedFile) => {
    +      val fileSplit = {
    +        val filePath = new Path(new URI(file.filePath))
    +        new FileSplit(filePath, file.start, file.length, Array.empty)
    +      }
    +
    +      val hadoopAttemptContext = {
    +        val conf = broadcastedConf.value.value
    +        val attemptID = new TaskAttemptID(new TaskID(new JobID(), 
TaskType.MAP, 0), 0)
    +        new TaskAttemptContextImpl(conf, attemptID)
    +      }
    +
    +      val reader = new LineRecordReader()
    +      reader.initialize(fileSplit, hadoopAttemptContext)
    +
    +      val lineIterator = new RecordReaderIterator(reader).map { line =>
    +        new String(line.getBytes, 0, line.getLength, csvOptions.charset)
    +      }
    --- End diff --
    
    `RecordReaderIterator` instantiation can be simplified using 
[`HadoopFileLinesReader`][1] introduced in PR #11960.
    
    [1]: 
https://github.com/apache/spark/pull/11960/files#diff-c0332718b0741d1b84c7157120b87888R33


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to