Skip to content

Commit 9217f9a

Browse files
committed
wrote some comments on the join
1 parent e0da5a3 commit 9217f9a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

18-OuterJoinDemo/OuterJoinDemo.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@
4141

4242
product_renamed_df = product_df.withColumnRenamed("qty", "reorder_qty")
4343

44+
45+
order_df.join(product_renamed_df, join_expr, "left") \
46+
.drop(product_renamed_df.prod_id) \
47+
.select("order_id", "prod_id", "prod_name", "unit_price", "list_price", "qty") \
48+
.sort("order_id") \
49+
.show()
50+
51+
52+
# What the coalesce does is that for prod_name column, it will first look for prod_name, if it's null, it will replace with prod_id
53+
# What the coalesce does is that for list_price column, it will first look for list_price, if it's null, it will replace with unit_price
54+
4455
order_df.join(product_renamed_df, join_expr, "left") \
4556
.drop(product_renamed_df.prod_id) \
4657
.select("order_id", "prod_id", "prod_name", "unit_price", "list_price", "qty") \

0 commit comments

Comments
 (0)