# Class TableGroup

java.lang.Object
uk.ac.starlink.ttools.task.ConsumerTask
uk.ac.starlink.ttools.task.SingleMapperTask
uk.ac.starlink.ttools.task.TableGroup

All Implemented Interfaces:
  `uk.ac.starlink.task.Task`

public class TableGroup extends SingleMapperTask
Task for performing aggregation operations on groups of rows of an input table.

Since:
  17 Nov 2022
Author:
  Mark Taylor

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`TableGroup.AggSpec`
Defines the aggregation that should be done to form an output column.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final char`
`AGGCOL_DELIM`
Delimiter character for aggcol parameter entries.

## Constructor Summary

Constructors
Constructor
Description
`TableGroup()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`static uk.ac.starlink.table.StarTable`
`aggregateRows(uk.ac.starlink.table.StarTable inTable, String[] keyExprs, TableGroup.AggSpec[] aggSpecs, uk.ac.starlink.table.RowRunner runner, boolean isSort, boolean isCache)`
Does the aggregation work.
`TableProducer`
`createProducer(uk.ac.starlink.task.Environment env)`
Returns an object which can produce the effective output table which will be consumed by this task.
`static TableGroup.AggSpec`
`parseAggSpec(String aggSpecTxt, char delimChr)`
Parses an aggregate specification string to an AggSpec.

### Methods inherited from class SingleMapperTask

`createInputProducer, getInputFilterParameter, getInputTableParameter`

### Methods inherited from class ConsumerTask

`createExecutable, createProducer, getIdentity, getOutputMode, getParameterList, getParameters, getPurpose`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### AGGCOL_DELIM

public static final char AGGCOL_DELIM
Delimiter character for aggcol parameter entries.

See Also:
  - Constant Field Values

## Constructor Details

### TableGroup

public TableGroup()
Constructor.

## Method Details

### createProducer

public TableProducer createProducer(uk.ac.starlink.task.Environment env) throws uk.ac.starlink.task.TaskException
Description copied from class: `ConsumerTask`
Returns an object which can produce the effective output table which will be consumed by this task. The table produced by the resulting producer can be fed to the `ConsumerTask.getIdentity(StarTable)` method.

Specified by:
  `createProducer` in class `ConsumerTask`
Parameters:
  `env` - execution environment
Returns:
  table producer
Throws:
  `uk.ac.starlink.task.TaskException`

### parseAggSpec

public static TableGroup.AggSpec parseAggSpec(String aggSpecTxt, char delimChr) throws uk.ac.starlink.task.UsageException
Parses an aggregate specification string to an AggSpec. The returned value can be passed to the `aggregateRows` method. The input string is as documented of the form "`<input-expr><delim><aggregator-name>[<delim><output-name>]`". If the input string cannot be so parsed, a UsageException with an informative message is thrown.

Parameters:
  `aggSpecTxt` - text specifying aggregated output
  `delimChr` - delimiter character between the three parts of the expression
Returns:
  parsed specification
Throws:
  `uk.ac.starlink.task.UsageException`

### aggregateRows

public static uk.ac.starlink.table.StarTable aggregateRows(uk.ac.starlink.table.StarTable inTable, String[] keyExprs, TableGroup.AggSpec[] aggSpecs, uk.ac.starlink.table.RowRunner runner, boolean isSort, boolean isCache) throws IOException, uk.ac.starlink.task.TaskException
Does the aggregation work.

Parameters:
  `inTable` - input table
  `keyExprs` - input table values that define grouping
  `aggSpecs` - specification for output aggregated columns
  `runner` - row runner
  `isSort` - if true, output table is sorted before return (where possible)
  `isCache` - if true, output table is cached before return
Returns:
  output table containing aggregated values
Throws:
  `IOException`
  `uk.ac.starlink.task.TaskException`