Skip to content

Commit 9894ef0

Browse files
committed
get rid of kwargs; support lsuffix & rsuffix
1 parent a3251bc commit 9894ef0

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

src/snowflake/snowpark/dataframe.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,8 +3528,10 @@ def lateral_join(
35283528
right: "DataFrame",
35293529
condition: Optional[Column] = None,
35303530
how: Optional[str] = None,
3531+
*,
3532+
lsuffix: str = "",
3533+
rsuffix: str = "",
35313534
_emit_ast: bool = True,
3532-
**kwargs,
35333535
) -> "DataFrame":
35343536
"""Performs a lateral join of the specified type (``how``) with the
35353537
current DataFrame and another DataFrame (``right``).
@@ -3545,9 +3547,12 @@ def lateral_join(
35453547
- Left outer join: "left", "leftouter"
35463548
- Cross join: "cross"
35473549
3548-
You can also use ``join_type`` keyword to specify this condition.
3549-
Note that to avoid breaking changes, currently when ``join_type`` is specified,
3550-
it overrides ``how``.
3550+
lsuffix: Suffix to add to the overlapping columns of the left DataFrame.
3551+
rsuffix: Suffix to add to the overlapping columns of the right DataFrame.
3552+
3553+
Note:
3554+
When both ``lsuffix`` and ``rsuffix`` are empty, the overlapping columns will have random column names in the resulting DataFrame.
3555+
You can reference to these randomly named columns using :meth:`Column.alias`.
35513556
35523557
Examples::
35533558
>>> df1 = session.create_dataframe([[1, 2], [3, 4], [5, 6]], schema=["a", "b"])
@@ -3571,10 +3576,21 @@ def lateral_join(
35713576
|5 |NULL |6 |NULL |
35723577
------------------------------
35733578
<BLANKLINE>
3579+
3580+
>>> df1.lateral_join(df2, df1.b * 2 > df2.c, how="left", lsuffix="_l", rsuffix="_r").show()
3581+
------------------------------
3582+
|"A_L" |"B" |"A_R" |"C" |
3583+
------------------------------
3584+
|3 |4 |1 |7 |
3585+
|5 |6 |1 |7 |
3586+
|5 |6 |3 |8 |
3587+
|1 |2 |NULL |NULL |
3588+
------------------------------
3589+
<BLANKLINE>
35743590
"""
3575-
join_type = create_join_type(kwargs.get("join_type") or how or "inner")
3591+
join_type = create_join_type(how or "inner")
35763592
(lhs, rhs) = _disambiguate(
3577-
self, right, LateralJoin(join_type), [], lsuffix="", rsuffix=""
3593+
self, right, LateralJoin(join_type), [], lsuffix=lsuffix, rsuffix=rsuffix
35783594
)
35793595

35803596
condition_expr = condition._expression if condition is not None else None

tests/integ/test_dataframe.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5653,7 +5653,7 @@ def test_df_join_how_on_overwrite(session):
56535653
"config.getoption('local_testing_mode', default=False)",
56545654
reason="Lateral join is not supported in Local Testing",
56555655
)
5656-
def test_lateral_join_how_on_overwrite(session):
5656+
def test_lateral_join(session):
56575657
table1 = Utils.random_table_name()
56585658
table2 = Utils.random_table_name()
56595659

@@ -5666,17 +5666,16 @@ def test_lateral_join_how_on_overwrite(session):
56665666
df1 = session.table(table1)
56675667
df2 = session.table(table2)
56685668

5669-
# Test join_type overwriting how parameter
5670-
df_inner = df1.lateral_join(df2, df1.a == df2.a, how="left", join_type="inner")
5671-
df_left = df1.lateral_join(df2, df1.a == df2.a, how="inner", join_type="left")
5669+
df_inner = df1.lateral_join(df2, df1.a == df2.a, how="inner")
5670+
df_left = df1.lateral_join(df2, df1.a == df2.a, how="left")
56725671

5673-
# Compare with equivalent SQL - inner lateral join
5672+
# Test inner lateral join vs SQL
56745673
sql_inner = session.sql(
56755674
f"SELECT * FROM {table1}, LATERAL (SELECT * FROM {table2} WHERE {table1}.a = {table2}.a)"
56765675
)
56775676
Utils.check_answer(df_inner, sql_inner)
56785677

5679-
# Compare with equivalent SQL - left outer lateral join
5678+
# Test left outer lateral join vs SQL
56805679
sql_left = session.sql(
56815680
f"SELECT * FROM {table1} LEFT OUTER JOIN LATERAL (SELECT * FROM {table2} WHERE {table1}.a = {table2}.a) ON TRUE"
56825681
)

tests/integ/test_simplifier_suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ def test_lateral_join_simplifier(session, use_simplified_query_generation):
11321132
Utils.check_answer(df, [Row(3, 4, 3, 8)])
11331133

11341134
df_chained = (
1135-
df1.lateral_join(df2, df1.id == df2.id)
1135+
df1.lateral_join(df2, df1.id == df2.id, lsuffix="_l", rsuffix="_r")
11361136
.select("value", "amount")
11371137
.filter(col("value") > 1)
11381138
.sort("value")

0 commit comments

Comments
 (0)