# AggregatorType reference

The aggregator type describes an aggregation. It gets connected to an index type which defines the grouping for the aggregator. Whenever the aggregation is performed, the code from the aggregator type receives the group context as its argument.

    $at = Triceps::AggregatorType->new($resultRowType, "aggName", $initFunc,
    	$handlerFunc, @args);

Creates an aggregator type. The rows created by the aggregator will be of

    $resultRowType

. The aggregator name is used to name the aggregator result label in the table, tableName.aggName. It is also used to get the reference of that label from the table.

    $initFunc

and

    $handlerFunc

provide either references or source code strings for the init and handler functions (as usual, if the format is the source code, the

    sub { ... }

wrapper will be added implicitly, see &xrsp;). The init function is called when the row group (contained in an index of the type, on which this aggregator type is set) is created. It initializes the group's aggregation state. The handler function gets called on the changes to the group. See the details in &xrsp;, &xrsp; and &xrsp;. The optional

    @args

are passed to both the init and handler functions.

If any fatal errors (as in

    die()

) occur in the aggregator functions, they propagate properly through the table, and the table operations confess with the Perl handler's error message. But since an error in the aggregator function means that things are going very, very wrong, after that the table becomes inoperative and will die on all the subsequent operations as well. You need to be very careful in writing these functions.

    $result = $at1->same($at2);
    $result = $at1->equals($at2);
    $result = $at1->match($at2);
    $result = $at->print();
    $atCopy = $at->copy();

The methods for comparison, printing and copying work similarly to the index types.

The equal aggregator types have the equal result row types, same names, same initialization and handler function references, same arguments.

The matching aggregator types may differ in the aggregator name and in the field names of the result row type. However the function references and their arguments must still be the same.

    $rt = $at->getRowType();

Get back the result row type.

AggregatorType
IndexType equals
IndexType match