# SimpleAggregator reference

SimpleAggregator provides an easier way to describe aggregations with the SQL-like aggregation functions. It also supports the user-defined aggregation functions.

The table types with SimpleAggregator cannot be currently exported between threads through a nexus, see &xrsp; for more detail.

    $tabType = Triceps::SimpleAggregator::make($optName => $optValue, ...);

Creates an aggregator type from the high-level description and sets it on an index type in the table type. Returns back the table type passed as an option argument. Confesses on errors. This is not a class constructor. It creates a common AggregatorType with the automatically generated code for the initialization and handler functions.

Most of the options are mandatory, unless noted otherwise. The options are:

    name => $name

  The aggregator type name.

    tabType => $tabType

  Table type to put the aggregator on. It must be un-initialized yet.

    idxPath => [ @path ]

  A reference to an array of index names, forming the path to the index where the aggregator type will be set. For example,

      ["index", "subIndex"]

  .

    result => [ [fieldName => $type, $funcName, $argFunc], ... ]

  A reference to an array defining the result of the aggregation. It consists of the repeating groups of four elements:

      fieldName => $type, $funcName, $argFunc,

  Here

      $type

  is the field type name,

      $funcName

  is the name of the aggregtion function (case-sensitive, see the list in &xrsp;), and

      $argFunc

  is the code reference that computes the argument of the aggregation function. It's a function that receives the current row being aggregated as

      $_[0]

  and computes a value from its fields. These values from all the rows in the group then get fed to the aggregation function. If the aggregation function requires no argument,

      argFunc

  must be

      undef

  . For example:

      	result => [
      		symbol => "string", "last", sub {$_[0]->get("symbol");},
      		count => "int32", "count_star", undef,
      		cost => "float64", "sum", sub {$_[0]->get("size") * $_[0]->get("price")];},
      		vwap => "float64", "nth_simple", sub { [1, $_[0]->get("price")];},
      	],

    saveRowTypeTo => \$rt

  Optional. A reference to a scalar where to save the result row type. It will be available when

      Triceps::SimpleAggregator::make()

  returns. Later when a table with this aggregator type gets constructed, its result row type may also be found with

      $table->getAggregatorLabel("aggName")->getRowType()

  .

    saveInitTo => \$code

  Optional. A reference to a scalar where to save the auto-generated source code of the initialization function for diagnostics.

    saveComputeTo => \$code

  Optional. A reference to a scalar where to save the auto-generated source code of the handler function for diagnostics.

    functions => { %definitions }

  Optional. The additional user-defined aggregation functions. See the description of their structure in &xrsp;.

The aggregator types produced by the SimpleAggregator would be equal and matching only if they have been produced by copying (you can also copy a table type or index type with an AggregatorType in it).

SimpleAggregator