snowflake.snowpark.DataFrame.lateral_join¶
- DataFrame.lateral_join(right: DataFrame, on: Optional[Column] = None, *, lsuffix: str = '', rsuffix: str = '') DataFrame[source]¶
Performs an inner lateral join with the current DataFrame and another DataFrame (
right).- Parameters:
right – The other
DataFrameto join.on – A
Columnexpression for the lateral join condition. This condition will be used to filter the right DataFrame in the lateral subquery (e.g., WHERE t1.a = t2.a).lsuffix – Suffix to add to the overlapping columns of the left DataFrame.
rsuffix – Suffix to add to the overlapping columns of the right DataFrame.
Note
When both
lsuffixandrsuffixare empty, the overlapping columns will have random column names in the resulting DataFrame. You can reference to these randomly named columns usingColumn.alias().- Examples::
>>> df1 = session.create_dataframe([[1, 2], [3, 4], [5, 6]], schema=["a", "b"]) >>> df2 = session.create_dataframe([[1, 7], [3, 8]], schema=["a", "c"]) >>> df1.lateral_join(df2, df1.a == df2.a).select(df1.a.alias("a_1"), df2.a.alias("a_2"), df1.b, df2.c).show() ----------------------------- |"A_1" |"A_2" |"B" |"C" | ----------------------------- |1 |1 |2 |7 | |3 |3 |4 |8 | -----------------------------
>>> # With lsuffix and rsuffix for column disambiguation >>> df1.lateral_join(df2, df1.b * 2 > df2.c, lsuffix="_l", rsuffix="_r").select("*").show() ----------------------------- |"A_L" |"B" |"A_R" |"C" | ----------------------------- |3 |4 |1 |7 | |5 |6 |1 |7 | |5 |6 |3 |8 | -----------------------------