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

    https://github.com/apache/spark/pull/9305#discussion_r43350325
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala
 ---
    @@ -201,15 +200,23 @@ private[sql] object DataSourceStrategy extends 
Strategy with Logging {
           // Builds `AttributeReference`s for all partition columns so that we 
can use them to project
           // required partition columns.  Note that if a partition column 
appears in `requiredColumns`,
           // we should use the `AttributeReference` in `requiredColumns`.
    -      val requiredColumnMap = requiredColumns.map(a => a.name -> a).toMap
    -      val partitionColumns = partitionColumnSchema.toAttributes.map { a =>
    -        requiredColumnMap.getOrElse(a.name, a)
    +      val partitionColumns = {
    +        val requiredColumnMap = requiredColumns.map(a => a.name -> a).toMap
    +        partitionColumnSchema.toAttributes.map { a =>
    +          requiredColumnMap.getOrElse(a.name, a)
    +        }
           }
     
           val mapPartitionsFunc = (_: TaskContext, _: Int, iterator: 
Iterator[InternalRow]) => {
    -        val projection = UnsafeProjection.create(requiredColumns, 
dataColumns ++ partitionColumns)
             val mutableJoinedRow = new JoinedRow()
    -        iterator.map(dataRow => projection(mutableJoinedRow(dataRow, 
partitionValues)))
    +        val unsafePartitionValues = 
UnsafeProjection.create(partitionColumnSchema)(partitionValues)
    +        val unsafeProjection =
    +          UnsafeProjection.create(requiredColumns, dataColumns ++ 
partitionColumns)
    +
    +        iterator.map { dataRow =>
    +          val unsafeDataRow = dataRow.asInstanceOf[UnsafeRow]
    +          unsafeProjection(mutableJoinedRow(unsafeDataRow, 
unsafePartitionValues))
    --- End diff --
    
    The projection done here may also adjust column order, so it's not 
avoidable. Using both `UnsafeRowJoiner` and `UnsafeProjection` here can be a 
waste.


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