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
DataFrameand anotherDataFrame(right).If the current and
rightDataFrames 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 orrightDataFrame 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
DataFrameto 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
lsuffixandrsuffixare 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.