cloud-fan commented on a change in pull request #23285: [SPARK-26224][SQL]
Avoid creating many project on subsequent calls to withColumn
URL: https://github.com/apache/spark/pull/23285#discussion_r240575095
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala
##########
@@ -2164,16 +2164,16 @@ class Dataset[T] private[sql](
columnMap.find { case (colName, _) =>
resolver(field.name, colName)
} match {
- case Some((colName: String, col: Column)) => col.as(colName)
- case _ => Column(field)
+ case Some((colName: String, col: Column)) => col.as(colName).named
+ case _ => field
}
}
- val newColumns = columnMap.filter { case (colName, col) =>
+ val newColumns = columnMap.filter { case (colName, _) =>
!output.exists(f => resolver(f.name, colName))
- }.map { case (colName, col) => col.as(colName) }
+ }.map { case (colName, col) => col.as(colName).named }
- select(replacedAndExistingColumns ++ newColumns : _*)
+ CollapseProject(Project(replacedAndExistingColumns ++ newColumns,
logicalPlan))
Review comment:
Can we reduce the scope of this optimization? e.g. if the root node of this
query is `Project`, update its project list to include `withColumns`, otherwise
add a new Project.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]