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

Outer JOIN column ambiguity #251

Open
linhr opened this issue Oct 17, 2024 · 1 comment
Open

Outer JOIN column ambiguity #251

linhr opened this issue Oct 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@linhr
Copy link
Contributor

linhr commented Oct 17, 2024

Spark handles projection differently for outer join outputs, based on how the join column is specified in .select(). Here is an example for the behavior that we should support.

>>> df = spark.createDataFrame([(2, "Alice"), (5, "Bob")]).toDF("age", "name")
>>> df2 = spark.createDataFrame([Row(height=80, name="Tom"), Row(height=85, name="Bob")])

>>> df.join(df2, 'name', 'outer').sort(desc("name")).show()
+-----+----+------+
| name| age|height|
+-----+----+------+
|  Tom|NULL|    80|
|  Bob|   5|    85|
|Alice|   2|  NULL|
+-----+----+------+

>>> df.join(df2, 'name', 'outer').select('name', 'height').sort(desc("name")).show()
+-----+------+
| name|height|
+-----+------+
|  Tom|    80|
|  Bob|    85|
|Alice|  NULL|
+-----+------+

>>> df.join(df2, 'name', 'outer').select(df.name, 'height').sort(desc("name")).show()
+-----+------+
| name|height|
+-----+------+
|  Bob|    85|
|Alice|  NULL|
| NULL|    80|
+-----+------+

>>> df.join(df2, 'name', 'outer').select(df2.name, 'height').sort(desc("name")).show()
+----+------+
|name|height|
+----+------+
| Tom|    80|
| Bob|    85|
|NULL|  NULL|
+----+------+

The example is extended from DataFrame.join() doctest in Spark.

@linhr linhr added the bug Something isn't working label Oct 17, 2024
@linhr
Copy link
Contributor Author

linhr commented Oct 18, 2024

Here are more examples.

>>> df.join(df2, 'name', 'outer').sort(desc(df.name)).show()
+-----+----+------+                                                             
| name| age|height|
+-----+----+------+
|  Bob|   5|    85|
|Alice|   2|  NULL|
|  Tom|NULL|    80|
+-----+----+------+

>>> df.join(df2, 'name', 'outer').sort(desc(df2.name)).show()
+-----+----+------+
| name| age|height|
+-----+----+------+
|  Tom|NULL|    80|
|  Bob|   5|    85|
|Alice|   2|  NULL|
+-----+----+------+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant