You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/09/06 06:14:33 UTC

[GitHub] [spark] cloud-fan commented on a diff in pull request #37761: [SPARK-40311][SQL][CORE][PYTHON] Add withColumnsRenamed to scala and pyspark API

cloud-fan commented on code in PR #37761:
URL: https://github.com/apache/spark/pull/37761#discussion_r963291217


##########
sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala:
##########
@@ -2808,6 +2808,53 @@ class Dataset[T] private[sql](
     }
   }
 
+  /**
+   * (Scala-specific)
+   * Returns a new Dataset with a columns renamed.
+   * This is a no-op if schema doesn't contain existingName.
+   *
+   * `colsMap` is a map of existing column name and new column name.
+   *
+   * @group untypedrel
+   * @since 3.4.0
+   */
+  def withColumnsRenamed(colsMap: Map[String, String]): DataFrame = {
+    val resolver = sparkSession.sessionState.analyzer.resolver
+    val output = queryExecution.analyzed.output
+

Review Comment:
   a simpler approach
   ```
   val projectList = output.map { attr =>
     if (resolver...) Alias(attr, ...) else attr
   }
   withPlan(Project(projectList, logicalPlan))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org