Skip to content
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

[SPARK-49366][CONNECT] Treat Union node as leaf in dataframe column resolution #47853

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions python/pyspark/sql/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ def test_self_join_II(self):
self.assertTrue(df3.columns, ["aa", "b", "a", "b"])
self.assertTrue(df3.count() == 2)

def test_self_join_III(self):
df1 = self.spark.range(10).withColumn("value", lit(1))
df2 = df1.union(df1)
df3 = df1.join(df2, df1.id == df2.id, "left")
self.assertTrue(df3.columns, ["id", "value", "id", "value"])
self.assertTrue(df3.count() == 20)

def test_self_join_IV(self):
df1 = self.spark.range(10).withColumn("value", lit(1))
df2 = df1.withColumn("value", lit(2)).union(df1.withColumn("value", lit(3)))
df3 = df1.join(df2, df1.id == df2.id, "right")
self.assertTrue(df3.columns, ["id", "value", "id", "value"])
self.assertTrue(df3.count() == 20)

def test_duplicated_column_names(self):
df = self.spark.createDataFrame([(1, 2)], ["c", "c"])
row = df.select("*").first()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,12 @@ trait ColumnResolutionHelper extends Logging with DataTypeErrorsBase {
}
(resolved.map(r => (r, currentDepth)), true)
} else {
resolveDataFrameColumnByPlanId(u, id, isMetadataAccess, p.children, currentDepth + 1)
val children = p match {
// treat Union node as the leaf node
case _: Union => Seq.empty[LogicalPlan]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not specific to spark connect right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is specific to connect only.
spark classic won't reach this path

case _ => p.children
}
resolveDataFrameColumnByPlanId(u, id, isMetadataAccess, children, currentDepth + 1)
}

// In self join case like:
Expand Down