concatWithKeys

Returns a DataFrame containing all groups in this GroupBy and every grouping key column that is missing from those groups.

Groups are concatenated in the order in which they appear in groups, and row order within every group is preserved. The grouping keys stored in keys are added to each group unless it already contains a column with the same name. Each added key value is repeated for every row in its group. An existing group column is preserved unchanged.

This function is especially useful when grouping by expressions or renamed columns, and you want the resulting DataFrame to include those keys as part of the output.

Check out groupBy Grammar for more information.

For more information: See groupBy on the documentation website. See concat on the documentation website.

See also GroupBy.concat, which ignores separate grouping keys.

Examples

val grouped = df.groupBy {
expr { if (age >= 20) "adult" else "teen" } named "ageGroup"
}

grouped.concatWithKeys()

Return

A DataFrame containing the rows from all groups and all missing grouping key columns.

Type Parameters

T

The schema marker type of the grouping keys.

G

The schema marker type of the groups.