
We suppose that you have already learned what is described in:
If you want to find the right Transformer for your purposes, see Transformers Comparison.
Rollup creates one or more output records from one or more input records.
| Component | Same input metadata | Sorted inputs | Inputs | Outputs | Java | CTL | 
|---|---|---|---|---|---|---|
| Rollup | - | no | 1 | 1-N | yes | yes | 
Rollup receives potentially unsorted data through single input port, transforms them and creates one or more output records from one or more input records.
Component can sent different records to different output ports as specified by user.
A transformation must be defined. The transformation uses a CTL
        template for Rollup, implements a
        RecordRollup interface or inherits from a
        DataRecordRollup superclass. The interface methods
        are listed below.

| Port type | Number | Required | Description | Metadata | 
|---|---|---|---|---|
| Input | 0 | yes | For input data records | Any(In0) | 
| Output | 0 | yes | For output data records | Any(Out0) | 
| 1-N | no | For output data records | Any(Out1-N) | 
| Attribute | Req | Description | Possible values | 
|---|---|---|---|
| Basic | |||
| Group key | Key according to which the records are considered to be included into one group. Expressed as the sequence of individual input field names separated from each other by semicolon. See Group Key for more information. If not specified, all records are considered to be members of a single group. | ||
| Group accumulator | ID of metadata that serve to create group accumulators. Metadata serve to store values used for transformation of individual groups of data records. | no metadata (default) | any metadata | |
| Transform | 1) | Definition of the transformation written in the graph in CTL or Java. | |
| Transform URL | 1) | Name of external file, including path, containing the definition of the transformation written in CTL or Java. | |
| Transform class | 1) | Name of external class defining the transformation. | |
| Transform source charset | Encoding of external file defining the transformation. | ISO-8859-1 (default) | |
| Sorted input | By default, records are considered to be sorted. Either
                in ascending or descending order. Different fields may even
                have different sort order. If your records are not sorted,
                switch this attribute to false. | true (default) | false | |
| Equal NULL | By default, records with null values of key fields are
                considered to be equal. If set to false,
                they are considered to be different from each other. | true (default) | false | |
Legend:
1): One of these must specified. Any of these transformation
        attributes uses a CTL template for Rollup or
        implements a RecordRollup interface.
See CTL Scripting Specifics or Java Interfaces for Rollup for more information.
See also Defining Transformations for detailed information about transformations.
When you define any of the three transformation attributes, you must specify the way how input should be transformed into output.
Transformations implement a RecordRollup
        interface or inherit from a DataRecordRollup
        superclass. Below is the list of RecordRollup
        interface methods. See Java
        Interfaces for Rollup for detailed information
        this interface.
For detailed information about CloudConnect Transformation Language see Part XI, CTL - CloudConnect Transformation Language. (CTL is a full-fledged, yet simple language that allows you to perform almost any imaginable transformation.)
CTL scripting allows you to specify custom transformation using the simple CTL scripting language.
Once you have written your transformation, you can also convert it to Java language code by clicking corresponding button at the upper right corner of the tab.
You can open the transformation definition as another tab of the graph (in addition to the Graph and Source tabs of Graph Editor) by clicking corresponding button at the upper right corner of the tab.
Here is an example of how the Source tab for defining the transformation looks like:
Table 55.5. Functions in Rollup
| CTL Template Functions | |
|---|---|
| void init() | |
| Required | No | 
| Description | Initialize the component, setup the environment, global variables | 
| Invocation | Called before processing the first record | 
| Returns | void | 
| void initGroup(<metadata name> groupAccumulator) | |
| Required | yes | 
| Input Parameters | <metadata name> groupAccumulator(metadata specified by user) IfgroupAccumulatoris not defined,VoidMetadata Accumulatoris used in the function signature. | 
| Returns | void | 
| Invocation | Called repeatedly, once for the first input record of each group. Called before updateGroup(groupAccumulator). | 
| Description | Initializes information for specific group. | 
| Example | function void initGroup(
      companyCustomers groupAccumulator) {
   groupAccumulator.count = 0;
   groupAccumulator.totalFreight = 0;
} | 
| boolean updateGroup(<metadata name> groupAccumulator) | |
| Required | yes | 
| Input Parameters | <metadata name> groupAccumulator(metadata specified by user) IfgroupAccumulatoris not defined,VoidMetadata Accumulatoris used in the function signature. | 
| Returns | false (updateTransform(counter,groupAccumulator) is not called) | true (updateTransform(counter,groupAccumulator) is called) | 
| Invocation | Called repeatedly (once for each input record of the group, including the first and the last record) after the initGroup(groupAccumulator) function has already been called for the whole group. | 
| Description | Updates information for specific group. If any of the input records causes fail of the updateGroup()function, 
                and if user has defined another function (updateGroupOnError()), 
                processing continues in thisupdateGroupOnError()at the place whereupdateGroup()failed. IfupdateGroup()fails 
                and user has not defined anyupdateGroupOnError(), 
                the whole graph will fail. TheupdateGroup()passes toupdateGroupOnError()error message and stack trace as arguments. | 
| Example | function boolean updateGroup(companyCustomers groupAccumulator) {
   groupAccumulator.count++;
   groupAccumulator.totalFreight = groupAccumulator.totalFreight + $0.Freight;
   return true;
} | 
| boolean finishGroup(<metadata name> groupAccumulator) | |
| Required | yes | 
| Input Parameters | <metadata name> groupAccumulator(metadata specified by user) IfgroupAccumulatoris not defined,VoidMetadata Accumulatoris used in the function signature. | 
| Returns | true (transform(counter,groupAccumulator) is called) | false (transform(counter,groupAccumulator) is not called) | 
| Invocation | Called repeatedly, once for the last input record of each group. Called after updateGroup(groupAccumulator) has already been called for all input records of the group. | 
| Description | Finalizes the group information. If any of the input records causes fail of the finishGroup()function, 
                and if user has defined another function (finishGroupOnError()), 
                processing continues in thisfinishGroupOnError()at the place wherefinishGroup()failed. IffinishGroup()fails 
                and user has not defined anyfinishGroupOnError(), 
                the whole graph will fail. ThefinishGroup()passes tofinishGroupOnError()error message and stack trace as arguments. | 
| Example | function boolean finishGroup(companyCustomers groupAccumulator) {
   groupAccumulator.avgFreight = groupAccumulator.totalFreight / groupAccumulator.count;
   return true;
} | 
| integer updateTransform(integer counter, <metadata name> groupAccumulator) | |
| Required | yes | 
| Input Parameters | integer counter(starts from 0, specifies the number of created records. should be terminated as shown in example below. Function calls end whenSKIPis returned.) | 
| <metadata name> groupAccumulator(metadata specified by user) IfgroupAccumulatoris not defined,VoidMetadata Accumulatoris used in the function signature. | |
| Returns | Integer numbers. See Return Values of Transformations for detailed information. | 
| Invocation | Called repeatedly as specified by user. Called after
                updateGroup(groupAccumulator) returns true. The function is called untilSKIPis returned. | 
| Description | It creates output records based on individual record
                information. If any part of the transform()function for some output record 
                causes fail of theupdateTransform()function, 
                and if user has defined another function (updateTransformOnError()), 
                processing continues in thisupdateTransformOnError()at the place whereupdateTransform()failed. IfupdateTransform()fails 
                and user has not defined anyupdateTransformOnError(), 
                the whole graph will fail. TheupdateTransformOnError()function 
                gets the information gathered byupdateTransform()that was get from previously successfully processed code. 
                Also error message and stack trace are passed toupdateTransformOnError(). | 
| Example | function integer updateTransform(integer counter, companyCustomers groupAccumulator) {
   if (counter >= Length) {
      clear(customers); 
      return SKIP;
   }
   $0.customers = customers[counter];
   $0.EmployeeID = $0.EmployeeID;
   return ALL;
} | 
| integer transform(integer counter, <metadata name> groupAccumulator) | |
| Required | yes | 
| Input Parameters | integer counter(starts from 0, specifies the number of created records. should be terminated as shown in example below. Function calls end whenSKIPis returned.) | 
| <metadata name> groupAccumulator(metadata specified by user) IfgroupAccumulatoris not defined,VoidMetadata Accumulatoris used in the function signature. | |
| Returns | Integer numbers. See Return Values of Transformations for detailed information. | 
| Invocation | Called repeatedly as specified by user. Called after
                finishGroup(groupAccumulator) returns true. The function is called untilSKIPis returned. | 
| Description | It creates output records based on all of the records
                of the whole group. If any part of the transform()function for some output record 
                causes fail of thetransform()function, 
                and if user has defined another function (transformOnError()), 
                processing continues in thistransformOnError()at the place wheretransform()failed. Iftransform()fails 
                and user has not defined anytransformOnError(), 
                the whole graph will fail. ThetransformOnError()function 
                gets the information gathered bytransform()that was get from previously successfully processed code. 
                Also error message and stack trace are passed totransformOnError(). | 
| Example | function integer transform(integer counter, companyCustomers groupAccumulator) {
   if (counter > 0) return SKIP;
   $0.ShipCountry = $0.ShipCountry;
   $0.Count = groupAccumulator.count;
   $0.AvgFreight = groupAccumulator.avgFreight;
   return ALL;	
} | 
| void initGroupOnError(string errorMessage, string stackTrace, <metadata name> groupAccumulator) | |
| Required | no | 
| Input Parameters | string errorMessage | 
| string stackTrace | |
| <metadata name> groupAccumulator(metadata specified by user) IfgroupAccumulatoris not defined,VoidMetadata Accumulatoris used in the function signature. | |
| Returns | void | 
| Invocation | Called if initGroup()throws an exception. | 
| Description | Initializes information for specific group. | 
| Example | function void initGroupOnError(
        string errorMessage, 
        string stackTrace, 
        companyCustomers groupAccumulator)
   printErr(errorMessage);
} | 
| boolean updateGroupOnError(string errorMessage, string stackTrace, <metadata name> groupAccumulator) | |
| Required | no | 
| Input Parameters | string errorMessage | 
| string stackTrace | |
| <metadata name> groupAccumulator(metadata specified by user) IfgroupAccumulatoris not defined,VoidMetadata Accumulatoris used in the function signature. | |
| Returns | false (updateTransform(counter,groupAccumulator) is not called) | true (updateTransform(counter,groupAccumulator) is called) | 
| Invocation | Called if updateGroup()throws an exception for a record of the group. 
                Called repeatedly (once for each of the other input records of the
                group). | 
| Description | Updates information for specific group. | 
| Example | function boolean updateGroupOnError(string errorMessage, string stackTrace, companyCustomers groupAccumulator) {
   printErr(errorMessage);
   return true;
} | 
| boolean finishGroupOnError(string errorMessage, string stackTrace, <metadata name> groupAccumulator) | |
| Required | no | 
| Input Parameters | string errorMessage | 
| string stackTrace | |
| <metadata name> groupAccumulator(metadata specified by user) IfgroupAccumulatoris not defined,VoidMetadata Accumulatoris used in the function signature. | |
| Returns | true (transform(counter,groupAccumulator) is called) | false (transform(counter,groupAccumulator) is not called) | 
| Invocation | Called if finishGroup()throws an exception. | 
| Description | Finalizes the group information. | 
| Example | function boolean finishGroupOnError(string errorMessage, string stackTrace, <metadata name> groupAccumulator) {
   printErr(errorMessage);
   return true;
} | 
| integer updateTransformOnError(string errorMessage, string stackTrace, integer counter, <metadata name> groupAccumulator) | |
| Required | yes | 
| Input Parameters | string errorMessage | 
| string stackTrace | |
| integer counter(starts from 0, specifies the number of created records. should be terminated as shown in example below. Function calls end whenSKIPis returned.) | |
| <metadata name> groupAccumulator(metadata specified by user) IfgroupAccumulatoris not defined,VoidMetadata Accumulatoris used in the function signature. | |
| Returns | Integer numbers. See Return Values of Transformations for detailed information. | 
| Invocation | Called if updateTransform()throws an exception. | 
| Description | It creates output records based on individual record information | 
| Example | function integer updateTransformOnError(string errorMessage, string stackTrace, integer counter, companyCustomers groupAccumulator) {
   if (counter >= 0) {
      return SKIP;
   }
   printErr(errorMessage);
   return ALL;
} | 
| integer transformOnError(string errorMessage, string stackTrace, integer counter, <metadata name> groupAccumulator) | |
| Required | no | 
| Input Parameters | string errorMessage | 
| string stackTrace | |
| integer counter(starts from 0, 
                specifies the number of created records. should be terminated as shown in example below. 
                Function calls end whenSKIPis returned.) | |
| <metadata name> groupAccumulator(metadata specified by user) IfgroupAccumulatoris not defined,VoidMetadata Accumulatoris used in the function signature. | |
| Returns | Integer numbers. See Return Values of Transformations for detailed information. | 
| Invocation | Called if transform()throws an exception. | 
| Description | It creates output records based on all of the records of the whole group. | 
| Example | function integer transformOnError(string errorMessage, string stackTrace, integer counter, companyCustomers groupAccumulator) {
   if (counter >= 0) {
      return SKIP;
   }
   printErr(errorMessage);
   return ALL;
} | 
| string getMessage() | |
| Required | No | 
| Description | Prints error message specified and invocated by user | 
| Invocation | Called in any time specified by user 
                (called only when either updateTransform(),transform(),updateTransformOnError(), 
                ortransformOnError()returns value less than or equal to -2). | 
| Returns | string | 
| void preExecute() | |
| Required | No | 
| Input parameters | None | 
| Returns | void | 
| Description | May be used to allocate and initialize resources required by the transform. 
                All resources allocated within this function should be released by the postExecute()function. | 
| Invocation | Called during each graph run before the transform is executed. | 
| void postExecute() | |
| Required | No | 
| Input parameters | None | 
| Returns | void | 
| Description | Should be used to free any resources allocated within the preExecute()function. | 
| Invocation | Called during each graph run after the entire transform was executed. | 
| ![[Important]](figures/important.png) | Important | 
|---|---|
| 
 | 
| ![[Warning]](figures/warning.png) | Warning | 
|---|---|
| Remember that if you do not hold these rules, NPE will be thrown! | 
The transformation implements methods of the RecordRollup interface 
        and inherits other common methods from the Transform interface. 
        See Common Java Interfaces.
Following is the list of the
        RecordRollup interface methods:
void init(Properties parameters, DataRecordMetadata
            inputMetadata, DataRecordMetadata accumulatorMetadata,
            DataRecordMetadata[] outputMetadata)
Initializes the rollup transform. This method is called only once at the beginning of the life-cycle of the rollup transform. Any internal allocation/initialization code should be placed here.
void initGroup(DataRecord inputRecord, DataRecord
            groupAccumulator)
This method is called for the first data record in a group. Any initialization of the group "accumulator" should be placed here.
void initGroupOnError(Exception exception, DataRecord inputRecord, DataRecord
            groupAccumulator)
This method is called for the first data record in a group.
            Any initialization of the group "accumulator" should be placed
            here. 
            Called only if initGroup(DataRecord, DataRecord) throws an exception.
boolean updateGroup(DataRecord inputRecord,
            DataRecord groupAccumulator)
This method is called for each data record (including the first one as well as the last one) in a group in order to update the group "accumulator".
boolean updateGroupOnError(Exception exception, DataRecord inputRecord,
            DataRecord groupAccumulator)
This method is called for each data record (including the
            first one as well as the last one) in a group in order to update
            the group "accumulator". 
            Called only if updateGroup(DataRecord, DataRecord) throws an exception.
boolean finishGroup(DataRecord inputRecord,
            DataRecord groupAccumulator)
This method is called for the last data record in a group in order to finish the group processing.
boolean finishGroupOnError(Exception exception, DataRecord inputRecord,
            DataRecord groupAccumulator)
This method is called for the last data record in a group in
            order to finish the group processing. 
            Called only if finishGroup(DataRecord, DataRecord) throws an exception.
int updateTransform(int counter, DataRecord
            inputRecord, DataRecord groupAccumulator, DataRecord[]
            outputRecords)
This method is used to generate output data records based on
            the input data record and the contents of the group "accumulator"
            (if it was requested). The output data record will be sent to the
            output when this method finishes. This method is called whenever
            the boolean updateGroup(DataRecord, DataRecord)
            method returns true. The
            counter argument is the number of previous
            calls to this method for the current group update. See Return Values of Transformations for detailed
            information about return values and their meaning.
int updateTransformOnError(Exception exception, int counter, DataRecord
            inputRecord, DataRecord groupAccumulator, DataRecord[]
            outputRecords)
This method is used to generate output data records based on
            the input data record and the contents of the group "accumulator"
            (if it was requested). 
            Called only if updateTransform(int, DataRecord, DataRecord) throws an exception.
int transform(int counter, DataRecord inputRecord,
            DataRecord groupAccumulator, DataRecord[]
            outputRecords)
This method is used to generate output data records based on
            the input data record and the contents of the group "accumulator"
            (if it was requested). The output data record will be sent to the
            output when this method finishes. This method is called whenever
            the boolean finishGroup(DataRecord, DataRecord)
            method returns true. The
            counter argument is the number of previous
            calls to this method for the current group. See Return Values of Transformations for detailed
            information about return values and their meaning.
int transformOnError(Exception exception, int counter, DataRecord inputRecord,
            DataRecord groupAccumulator, DataRecord[]
            outputRecords)
This method is used to generate output data records based on
            the input data record and the contents of the group "accumulator"
            (if it was requested). 
            Called only if transform(int, DataRecord, DataRecord) throws an exception.