join

fun <A, B> DataFrame<A>.join(other: DataFrame<B>, type: JoinType = JoinType.Inner, selector: JoinColumnsSelector<A, B>? = null): DataFrame<A>

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 DataFrame based 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 both DataFrames; rows are merged.

  • JoinType.Left — Includes all rows from the left DataFrame; matching rows are merged, unmatched right-side values are filled with null.

  • JoinType.Right — Includes all rows from the right DataFrame; matching rows are merged, unmatched left-side values are filled with null.

  • JoinType.Full — Includes all rows from both DataFrames; matching rows are merged, all mismatches are filled with null.

Non-merging joins:

  • JoinType.Filter — Includes only rows from the left DataFrame that have a match in the right one; right-side columns are not merged.

  • JoinType.Exclude — Includes only rows from the left DataFrame that 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

other

DataFrame to join with.

type

JoinType defining how the resulting rows are constructed.

selector

JoinColumnsSelector specifying join columns; if null, same-name columns are used.


fun <A, B> DataFrame<A>.join(other: DataFrame<B>, vararg columns: String, type: JoinType = JoinType.Inner): DataFrame<A>

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 DataFrame based 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 both DataFrames; rows are merged.

  • JoinType.Left — Includes all rows from the left DataFrame; matching rows are merged, unmatched right-side values are filled with null.

  • JoinType.Right — Includes all rows from the right DataFrame; matching rows are merged, unmatched left-side values are filled with null.

  • JoinType.Full — Includes all rows from both DataFrames; matching rows are merged, all mismatches are filled with null.

Non-merging joins:

  • JoinType.Filter — Includes only rows from the left DataFrame that have a match in the right one; right-side columns are not merged.

  • JoinType.Exclude — Includes only rows from the left DataFrame that 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

other

DataFrame to join with.

columns

Column Names specifying join columns.

type

JoinType defining how the resulting rows are constructed.