Skip to content

[SPARK-52503][SQL][CONNECT] Fix drop when the input column is not existent #51196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

zhengruifeng
Copy link
Contributor

@zhengruifeng zhengruifeng commented Jun 17, 2025

What changes were proposed in this pull request?

Fix drop when the input column is not existent

Why are the changes needed?

bugfix

import pyspark.sql.functions as F

df1 = spark.createDataFrame([("a", "b", "c") ], schema='colA string, colB string, colC string')

df2 = spark.createDataFrame([("c", "d", "") ], schema='colC string, colD string, colE string')

df3 = df1.join(df2, df1["colC"] == df2["colC"]).withColumn("colB", F.when(df1["colB"] == "b", F.concat(df1["colB"].cast("string"), F.lit("_newValue"))).otherwise(df1["colB"]))

df3
DataFrame[colA: string, colB: string, colC: string, colC: string, colD: string, colE: string]

df3.drop(df1["colB"])
DataFrame[colA: string, colC: string, colC: string, colD: string, colE: string]

df3 doesn't contains df1["colB"], so no columns should be dropped.

Does this PR introduce any user-facing change?

yes, bug fix

How was this patch tested?

added tests

Was this patch authored or co-authored using generative AI tooling?

no

@zhengruifeng zhengruifeng changed the title [WIP][SQL][CONNECT] Fix drop when the input column is not existent [SPARK-52503][SQL][CONNECT] Fix drop when the input column is not existent Jun 17, 2025
@zhengruifeng zhengruifeng requested a review from cloud-fan June 17, 2025 08:11
@zhengruifeng zhengruifeng marked this pull request as ready for review June 17, 2025 08:13
@github-actions github-actions bot removed the CONNECT label Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant