You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Chaerim Yeo (JIRA)" <ji...@apache.org> on 2018/09/29 04:17:00 UTC
[jira] [Commented] (SPARK-25571) Add withColumnsRenamed method to
Dataset
[ https://issues.apache.org/jira/browse/SPARK-25571?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16632777#comment-16632777 ]
Chaerim Yeo commented on SPARK-25571:
-------------------------------------
I'm working on it now.
> Add withColumnsRenamed method to Dataset
> ----------------------------------------
>
> Key: SPARK-25571
> URL: https://issues.apache.org/jira/browse/SPARK-25571
> Project: Spark
> Issue Type: Improvement
> Components: SQL
> Affects Versions: 2.3.2
> Reporter: Chaerim Yeo
> Priority: Major
>
> There are two general approaches to rename several columns.
> * Using *withColumnRenamed* method
> * Using *select* method
> {code}
> // Using withColumnRenamed
> ds.withColumnRenamed("first_name", "firstName")
> .withColumnRenamed("last_name", "lastName")
> .withColumnRenamed("postal_code", "postalCode")
> // Using select
> ds.select(
> $"id",
> $"first_name" as "firstName",
> $"last_name" as "lastName",
> $"address",
> $"postal_code" as "postalCode"
> )
> {code}
> However, both approaches are still inefficient and redundant due to following limitations.
> * withColumnRenamed: it is required to call method several times
> * select: it is required to pass all columns to select method
> It is necessary to implement new method, such as *withColumnsRenamed*, which can rename many columns at once.
> {code}
> ds.withColumnsRenamed(
> "first_name" -> "firstName",
> "last_name" -> "lastName",
> "postal_code" -> "postalCode"
> )
> // or
> ds.withColumnsRenamed(Map(
> "first_name" -> "firstName",
> "last_name" -> "lastName",
> "postal_code" -> "postalCode"
> ))
> {code}
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org