Gather

class Gather<T, C, K, R>(val df: DataFrame<T>, val columns: ColumnsSelector<T, C>, val filter: RowValueFilter<T, C>? = null, val keyType: KType? = null, val keyTransform: (String) -> K, val valueTransform: (C) -> R? = null, val explode: Boolean = false)

An intermediate class used in the gather operation.

This class itself does not perform the reshaping — it serves as a transitional step before specifying how to structure the gathered data. It must be followed by one of the reshaping methods to produce a new DataFrame with the transformed layout.

Use the following methods to complete the gathering:

  • into – reshapes into both key and value columns.

  • keysInto – reshapes into a single key column.

  • valuesInto – reshapes into a single value column.

You can also configure the transformation using:

  • where / notNull – to filter gathered values.

  • explodeLists – to flatten list values.

  • mapKeys – to transform the generated keys.

  • mapValues – to transform the gathered values.

  • cast – to specify the resulting value type.

This operation is the reverse of pivot.

See Grammar for more details.

Constructors

Link copied to clipboard
constructor(df: DataFrame<T>, columns: ColumnsSelector<T, C>, filter: RowValueFilter<T, C>? = null, keyType: KType? = null, keyTransform: (String) -> K, valueTransform: (C) -> R? = null, explode: Boolean = false)

Properties

Link copied to clipboard
Link copied to clipboard
internal val df: DataFrame<T>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
internal val keyTransform: (String) -> K
Link copied to clipboard
internal val keyType: KType?
Link copied to clipboard
internal val valueTransform: (C) -> R?

Functions

Link copied to clipboard
fun <P> cast(): Gather<T, P, K, P>

Casts the type of values in the columns previously selected by gather without modifying the values themselves.

Link copied to clipboard
fun <T, C, K, R> Gather<T, C, K, R>.explodeLists(): Gather<T, C, K, R>

Explodes List values — i.e., splits each list into individual elements, creating a separate row for each element, and duplicating all other columns — in the columns previously selected by gather.

@JvmName(name = "explodeListsTyped")
fun <T, C, K, R> Gather<T, List<C>, K, R>.explodeLists(): Gather<T, C, K, R>

Explodes List values in the columns previously selected by gather.

Link copied to clipboard
internal fun <T, C, K, R> Gather<T, C, K, R>.gatherImpl(namesTo: String? = null, valuesTo: String? = null): DataFrame<T>
Link copied to clipboard
fun <T, C, K, R> Gather<T, C, K, R>.into(keyColumn: String, valueColumn: String): DataFrame<T>

Reshapes the columns previously selected by gather into two new columns: keyColumn, containing the original column names, and valueColumn, containing the corresponding cell values.

fun <T, C, K, R> Gather<T, C, K, R>.into(keyColumn: KProperty<K>, valueColumn: KProperty<R>): DataFrame<T>
fun <T, C, K, R> Gather<T, C, K, R>.into(keyColumn: ColumnAccessor<K>, valueColumn: ColumnAccessor<R>): DataFrame<T>
Link copied to clipboard
fun <T, C, K, R> Gather<T, C, K, R>.keysInto(keyColumn: String): DataFrame<T>

Reshapes the columns previously selected by gather into a new keyColumn, containing the original column names. The value column is omitted.

fun <T, C, K, R> Gather<T, C, K, R>.keysInto(keyColumn: KProperty<K>): DataFrame<T>
fun <T, C, K, R> Gather<T, C, K, R>.keysInto(keyColumn: ColumnAccessor<K>): DataFrame<T>
Link copied to clipboard
inline fun <T, C, reified K, R> Gather<T, C, *, R>.mapKeys(noinline transform: (String) -> K): Gather<T, C, K, R>

Applies transform to the gathering keys — that is, the names of the columns previously selected by gather.

Link copied to clipboard
fun <T, C, K, R> Gather<T, C, K, *>.mapValues(transform: (C) -> R): Gather<T, C, K, R>

Applies transform to the values from the columns previously selected by gather.

Link copied to clipboard
fun <T, C, K, R> Gather<T, C?, K, R>.notNull(): Gather<T, C, K, R>

Filters out null values from the columns previously selected by gather, keeping only non-null entries.

Link copied to clipboard
fun <T, C, K, R> Gather<T, C, K, R>.valuesInto(valueColumn: String): DataFrame<T>

Reshapes the columns previously selected by gather into a new valueColumn, containing the original column values. The key column is omitted.

fun <T, C, K, R> Gather<T, C, K, R>.valuesInto(valueColumn: KProperty<K>): DataFrame<T>
fun <T, C, K, R> Gather<T, C, K, R>.valuesInto(valueColumn: ColumnAccessor<K>): DataFrame<T>
Link copied to clipboard
fun <T, C, K, R> Gather<T, C, K, R>.where(filter: RowValueFilter<T, C>): Gather<T, C, K, R>

Filter values in columns previously selected by gather using a filter.