snowflake.snowpark.DataFrame.cross_join¶
- DataFrame.cross_join(right: DataFrame, *, lsuffix: str = '', rsuffix: str = '') DataFrame [source]¶
Performs a cross join, which returns the Cartesian product of the current
DataFrame
and anotherDataFrame
(right
).If the current and
right
DataFrames have columns with the same name, and you need to refer to one of these columns in the returned DataFrame, use thecol()
function on the current orright
DataFrame to disambiguate references to these columns.Example:
>>> df1 = session.create_dataframe([[1, 2], [3, 4]], schema=["a", "b"]) >>> df2 = session.create_dataframe([[5, 6], [7, 8]], schema=["c", "d"]) >>> df1.cross_join(df2).sort("a", "b", "c", "d").show() ------------------------- |"A" |"B" |"C" |"D" | ------------------------- |1 |2 |5 |6 | |1 |2 |7 |8 | |3 |4 |5 |6 | |3 |4 |7 |8 | ------------------------- >>> df3 = session.create_dataframe([[1, 2], [3, 4]], schema=["a", "b"]) >>> df4 = session.create_dataframe([[5, 6], [7, 8]], schema=["a", "b"]) >>> df3.cross_join(df4, lsuffix="_l", rsuffix="_r").sort("a_l", "b_l", "a_r", "b_r").show() --------------------------------- |"A_L" |"B_L" |"A_R" |"B_R" | --------------------------------- |1 |2 |5 |6 | |1 |2 |7 |8 | |3 |4 |5 |6 | |3 |4 |7 |8 | ---------------------------------
- Parameters:
right – the right
DataFrame
to join.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
If both
lsuffix
andrsuffix
are empty, the overlapping columns will have random column names in the result DataFrame. If either one is not empty, the overlapping columns won’t have random names.