AGGR operator
The AGGR operator creates an aggregation.
Syntax
AGGR [eventClause] aggrClass WHERE aggrExpr [NEW [newEventClause]] [DELETE [deleteEventClause]]
Description
In addition to the property that is the result of this operator and contains the value of the aggregated object, for each parameter the AGGR operator also creates a data property with one parameter of type aggrClass. The value class and name of this property match the class and name of the corresponding parameter; when the aggregated object is created, the value of the parameter is automatically written to this property.
eventClause specifies the base check event; NEW and DELETE specify resolution events for creating and deleting aggregated objects respectively.
Unlike other context-dependent operators, the AGGR operator cannot be used in expressions inside other operators (in this sense it is more like context-independent operators), or in the JOIN operator (inside [= ])
Parameters
-
eventClauseEvent description block. The base check event. Default — global
APPLY. -
aggrClassThe value class of the aggregated object. Must be a user-defined class; built-in classes are not allowed.
-
aggrExprAn expression whose non-
NULLvalues drive the aggregation; its typed parameters determine the parameters of the result property and of the auto-created properties for each parameter. -
NEWKeyword. Specifies the resolution event for creating aggregated objects.
-
newEventClauseEvent description block. If
NEWis absent, the resolution event inherits only the scope (GLOBAL/LOCAL) ofeventClause; itsFORMS,AFTER/GOAFTER, and event name are not carried over. IfNEWis specified butnewEventClauseis omitted, the default globalAPPLYevent is used. -
DELETEKeyword. Specifies the resolution event for deleting aggregated objects.
-
deleteEventClauseEvent description block. If
DELETEis absent, the resolution event inherits only the scope (GLOBAL/LOCAL) ofeventClause; itsFORMS,AFTER/GOAFTER, and event name are not carried over. IfDELETEis specified butdeleteEventClauseis omitted, the default globalAPPLYevent is used.
Examples
CLASS A; CLASS B; CLASS C;
f = DATA INTEGER (A, B);
c = AGGR C WHERE f(A a, B b) MATERIALIZED INDEXED;
CLASS AB;
ab = AGGR AB WHERE A a IS A AND B b IS B; // for each A B pair creates an object AB
CLASS Shipment 'Delivery';
date = ABSTRACT DATE (Shipment);
CLASS Invoice 'Invoice';
createShipment 'Create delivery' = DATA BOOLEAN (Invoice);
date 'Shipment date' = DATA DATE (Invoice);
CLASS ShipmentInvoice 'Delivery by invoice' : Shipment;
// creating a delivery by invoice, if the option for delivery creation is defined for the invoice
shipment(Invoice invoice) = AGGR ShipmentInvoice WHERE createShipment(invoice);
date(ShipmentInvoice si) += sum(date(invoice(si)),1); // delivery date = invoice date + 1
// LOCAL base event: all three events run within the session
sessionAggr(Invoice invoice) = AGGR LOCAL ShipmentInvoice WHERE createShipment(invoice);
// explicit NEW event clause: creation runs locally, deletion inherits the base (global) event
newLocalAggr(Invoice invoice) = AGGR ShipmentInvoice WHERE createShipment(invoice) NEW LOCAL;
// separate events: creation — global (empty NEW clause defaults to APPLY), deletion — local
splitAggr(Invoice invoice) = AGGR ShipmentInvoice WHERE createShipment(invoice) NEW DELETE LOCAL;