join
Joins this DataFrame with the other DataFrame using the selected key columns.
Creates a new DataFrame by combining rows from two input dataframes according to one or more matching key columns.
There are two categories of joins:
Merging joins — merge matching rows from both
DataFrames into a single row.Non-merging joins — select rows from the left
DataFramebased on whether a match exists in the right one, without merging columns.
The exact behavior depends on the specified join type:
Merging joins:
JoinType.Inner(default) — Includes only matching rows from bothDataFrames; rows are merged.JoinType.Left— Includes all rows from the leftDataFrame; matching rows are merged, unmatched right-side values are filled withnull.JoinType.Right— Includes all rows from the rightDataFrame; matching rows are merged, unmatched left-side values are filled withnull.JoinType.Full— Includes all rows from bothDataFrames; matching rows are merged, all mismatches are filled withnull.
Non-merging joins:
JoinType.Filter— Includes only rows from the leftDataFramethat have a match in the right one; right-side columns are not merged.JoinType.Exclude— Includes only rows from the leftDataFramethat do not have a match in the right one; right-side columns are not merged.
If no join columns are specified, all columns with matching names in both DataFrames are used.
If both DataFrames contain columns with the same name that are not part of the join keys, such columns are treated as distinct. Such a column from the right DataFrame will be automatically renamed in the resulting DataFrame.
Each join type has a corresponding shortcut function: innerJoin, leftJoin, rightJoin, fullJoin, filterJoin, and excludeJoin.
See also joinWith, which performs a join by a condition that matches row values.
This can include column groups and nested columns.
See Selecting Columns.
For more information: See join on the documentation website.
This join overload
Select join columns (including those that have different names in different DataFrames) using JoinDsl.
JoinDsl allows you to define the columns used for joining DataFrames and provides methods to match columns with different names between the left and right side.
Provides the left DataFrame both as the receiver (this) and as the argument (it), allowing you to reference its columns directly. Use right to access columns from the right DataFrame, and match to explicitly pair columns with different names.
See also Columns selection via DSL.
For more information: See join on the documentation website.
Examples
// Join by two columns with the same names in both dataframes
dfLeft.join(dfRight) { name and city }
// Join by one column with different names —
// "firstName" in the left dataframe and "name" in the right one
dfLeft.join(dfRight) { left -> left.firstName match right.name }
// Match columns using String API
dfLeft.join(dfRight) { "symbol" match right.getValue<Char>("char") }Return
joined DataFrame.
Parameters
DataFrame to join with.
JoinType defining how the resulting rows are constructed.
JoinColumnsSelector specifying join columns; if null, same-name columns are used.
Joins this DataFrame with the other DataFrame using the selected key columns.
Creates a new DataFrame by combining rows from two input dataframes according to one or more matching key columns.
There are two categories of joins:
Merging joins — merge matching rows from both
DataFrames into a single row.Non-merging joins — select rows from the left
DataFramebased on whether a match exists in the right one, without merging columns.
The exact behavior depends on the specified join type:
Merging joins:
JoinType.Inner(default) — Includes only matching rows from bothDataFrames; rows are merged.JoinType.Left— Includes all rows from the leftDataFrame; matching rows are merged, unmatched right-side values are filled withnull.JoinType.Right— Includes all rows from the rightDataFrame; matching rows are merged, unmatched left-side values are filled withnull.JoinType.Full— Includes all rows from bothDataFrames; matching rows are merged, all mismatches are filled withnull.
Non-merging joins:
JoinType.Filter— Includes only rows from the leftDataFramethat have a match in the right one; right-side columns are not merged.JoinType.Exclude— Includes only rows from the leftDataFramethat do not have a match in the right one; right-side columns are not merged.
If no join columns are specified, all columns with matching names in both DataFrames are used.
If both DataFrames contain columns with the same name that are not part of the join keys, such columns are treated as distinct. Such a column from the right DataFrame will be automatically renamed in the resulting DataFrame.
Each join type has a corresponding shortcut function: innerJoin, leftJoin, rightJoin, fullJoin, filterJoin, and excludeJoin.
See also joinWith, which performs a join by a condition that matches row values.
This can include column groups and nested columns.
See Selecting Columns.
For more information: See join on the documentation website.
This join overload
Select single or multiple columns using their names as Strings. (String API).
Example
// Join by two columns with the same names in both dataframes
dfLeft.join(dfRight, "name", "city")Return
joined DataFrame.
Parameters
DataFrame to join with.
Column Names specifying join columns.
JoinType defining how the resulting rows are constructed.