You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "zhengruifeng (via GitHub)" <gi...@apache.org> on 2024/03/08 07:16:28 UTC

[PR] [SPARK-47322][PYTHON][CONNECT] Make `withColumnsRenamed` duplicated column name handling consisten with `withColumnRenamed` [spark]

zhengruifeng opened a new pull request, #45431:
URL: https://github.com/apache/spark/pull/45431

   ### What changes were proposed in this pull request?
   Make `withColumnsRenamed` duplicated column name handling consistent with `withColumnRenamed`
   
   
   ### Why are the changes needed?
   `withColumnsRenamed` checks the column names duplication of output dataframe, this is not consistent with `withColumnRenamed`:
   1, `withColumnRenamed` doesn't do this check, and support output a dataframe with duplicated column names;
   2, when the input dataframe has duplicated column names, `withColumnsRenamed` always fail, even if the columns with the same name are not touched at all:
   
   
   ```
   In [8]: df1 = spark.createDataFrame([(1, "id2"),], ["id", "value"])
      ...: df2 = spark.createDataFrame([(1, 'x', 'id1'), ], ["id", 'a', "value"])
      ...: join = df2.join(df1, on=['id'], how='left')
      ...: join
   Out[8]: DataFrame[id: bigint, a: string, value: string, value: string]
   
   In [9]: join.withColumnRenamed('id', 'value')
   Out[9]: DataFrame[value: bigint, a: string, value: string, value: string]
   
   In [10]: join.withColumnsRenamed({'id' : 'value'})
   ...
   AnalysisException: [COLUMN_ALREADY_EXISTS] The column `value` already exists. Choose another name or rename the existing column. SQLSTATE: 42711
   
   In [11]: join.withColumnRenamed('a', 'b')
   Out[11]: DataFrame[id: bigint, b: string, value: string, value: string]
   
   In [12]: join.withColumnsRenamed({'a' : 'b'})
   ...
   AnalysisException: [COLUMN_ALREADY_EXISTS] The column `value` already exists. Choose another name or rename the existing column. SQLSTATE: 42711
   
   In [13]: join.withColumnRenamed('x', 'y')
   Out[13]: DataFrame[id: bigint, a: string, value: string, value: string]
   
   In [14]: join.withColumnsRenamed({'x' : 'y'})
   AnalysisException: [COLUMN_ALREADY_EXISTS] The column `value` already exists. Choose another name or rename the existing column. SQLSTATE: 42711
   
   In [15]: join.withColumnRenamed('value', 'new_value')
   Out[15]: DataFrame[id: bigint, a: string, new_value: string, new_value: string]
   
   In [16]: join.withColumnsRenamed({'value' : 'new_value'})
   AnalysisException: [COLUMN_ALREADY_EXISTS] The column `new_value` already exists. Choose another name or rename the existing column. SQLSTATE: 42711
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   yes
   
   
   
   
   ### How was this patch tested?
   updated tests
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   no


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


Re: [PR] [SPARK-47322][PYTHON][CONNECT] Make `withColumnsRenamed` column names duplication handling consistent with `withColumnRenamed` [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #45431:
URL: https://github.com/apache/spark/pull/45431#issuecomment-1985561435

   Merged to master.


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


Re: [PR] [SPARK-47322][PYTHON][CONNECT] Make `withColumnsRenamed` duplicated column name handling consisten with `withColumnRenamed` [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #45431:
URL: https://github.com/apache/spark/pull/45431#issuecomment-1985167614

   cc @cloud-fan 


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


Re: [PR] [SPARK-47322][PYTHON][CONNECT] Make `withColumnsRenamed` column names duplication handling consistent with `withColumnRenamed` [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #45431: [SPARK-47322][PYTHON][CONNECT] Make `withColumnsRenamed` column names duplication handling consistent with `withColumnRenamed`
URL: https://github.com/apache/spark/pull/45431


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