-
Notifications
You must be signed in to change notification settings - Fork 28.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-46260][PYTHON][SQL] DataFrame.withColumnsRenamed` should respe…
…ct the dict ordering ### What changes were proposed in this pull request? Make `DataFrame.withColumnsRenamed` respect the dict ordering ### Why are the changes needed? the ordering in `withColumnsRenamed` matters in scala ``` scala> val df = spark.range(1000) val df: org.apache.spark.sql.Dataset[Long] = [id: bigint] scala> df.withColumnsRenamed(Map("id" -> "a", "a" -> "b")) val res0: org.apache.spark.sql.DataFrame = [b: bigint] scala> df.withColumnsRenamed(Map("a" -> "b", "id" -> "a")) val res1: org.apache.spark.sql.DataFrame = [a: bigint] ``` However, in py4j the Python `dict` -> JVM `map` conversion can not guarantee the ordering ### Does this PR introduce _any_ user-facing change? yes, behavior change before this PR ``` In [1]: df = spark.range(10) In [2]: df.withColumnsRenamed({"id": "a", "a": "b"}) Out[2]: DataFrame[a: bigint] In [3]: df.withColumnsRenamed({"a": "b", "id": "a"}) Out[3]: DataFrame[a: bigint] ``` after this PR ``` In [1]: df = spark.range(10) In [2]: df.withColumnsRenamed({"id": "a", "a": "b"}) Out[2]: DataFrame[b: bigint] In [3]: df.withColumnsRenamed({"a": "b", "id": "a"}) Out[3]: DataFrame[a: bigint] ``` ### How was this patch tested? added ut ### Was this patch authored or co-authored using generative AI tooling? no Closes #44177 from zhengruifeng/sql_withColumnsRenamed_sql. Authored-by: Ruifeng Zheng <ruifengz@apache.org> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
- Loading branch information
1 parent
35a99a8
commit 032e782
Showing
5 changed files
with
52 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters