Skip to main content
Version: Java (Groovy)

groupBy

groupBy groups column content into arrays.

Syntax

table.groupBy()
table.groupBy(groupByColumns...)

Parameters

ParameterTypeDescription
groupByColumnsString...

The column(s) by which to group data.

  • NULL the content of each column is grouped into its own array.
  • "X" will output an array of values for each group in column X.
  • "X", "Y" will output an array of values for each group designated from the X and Y columns.
groupByColumnsCollection<? extends ColumnName>

The column(s) by which to group data.

  • NULL the content of each column is grouped into its own array.
  • "X" will output an array of values for each group in column X.
  • "X", "Y" will output an array of values for each group designated from the X and Y columns.

Returns

A new table containing grouping columns and grouped data. Column content is grouped into arrays.

Examples

In this example, groupBy creates an array of values for each column.

source = newTable(
stringCol("X", "A", "B", "A", "C", "B", "A", "B", "B", "C"),
stringCol("Y", "M", "N", "O", "N", "P", "M", "O", "P", "M"),
intCol("Number", 55, 76, 20, 130, 230, 50, 73, 137, 214),
)

result = source.groupBy()

In this example, groupBy creates an array of values, as grouped by X.

source = newTable(
stringCol("X", "A", "B", "A", "C", "B", "A", "B", "B", "C"),
stringCol("Y", "M", "N", "O", "N", "P", "M", "O", "P", "M"),
intCol("Number", 55, 76, 20, 130, 230, 50, 73, 137, 214),
)

result = source.groupBy("X")

In this example, groupBy creates an array of values, as grouped by X and Y.

source = newTable(
stringCol("X", "A", "B", "A", "C", "B", "A", "B", "B", "C"),
stringCol("Y", "M", "N", "O", "N", "P", "M", "O", "P", "M"),
intCol("Number", 55, 76, 20, 130, 230, 50, 73, 137, 214),
)

result = source.groupBy("X", "Y")