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

 ##########
 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:
   I don't think we can do that. Imagine the case when all the columns depend 
on the previously added one: if we would do that, we would end up with an 
invalid plan. Or am I missing something?

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

Reply via email to