Rollup

Commercial Component

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.

Short Summary

Rollup creates one or more output records from one or more input records.

Component Same input metadata Sorted inputs Inputs Outputs Java CTL
Rollup-no11-Nyesyes

Abstract

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.

Icon

Ports

Port typeNumberRequiredDescriptionMetadata
Input0yesFor input data recordsAny(In0)
Output0yesFor output data recordsAny(Out0)
1-NnoFor output data recordsAny(Out1-N)

Rollup Attributes

AttributeReqDescriptionPossible 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
Transform1)Definition of the transformation written in the graph in CTL or Java. 
Transform URL1)Name of external file, including path, containing the definition of the transformation written in CTL or Java. 
Transform class1)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.

CTL Scripting Specifics

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.

CTL Templates for Rollup

Here is an example of how the Source tab for defining the transformation looks like:

Source Tab of the Transform Editor in the Rollup Component (I)

Figure 55.6. Source Tab of the Transform Editor in the Rollup Component (I)


Source Tab of the Transform Editor in the Rollup Component (II)

Figure 55.7. Source Tab of the Transform Editor in the Rollup Component (II)


Source Tab of the Transform Editor in the Rollup Component (III)

Figure 55.8. Source Tab of the Transform Editor in the Rollup Component (III)


Table 55.5. Functions in Rollup

CTL Template Functions
void init()
RequiredNo
DescriptionInitialize the component, setup the environment, global variables
InvocationCalled before processing the first record
Returnsvoid
void initGroup(<metadata name> groupAccumulator)
Requiredyes
Input Parameters<metadata name> groupAccumulator (metadata specified by user) If groupAccumulator is not defined, VoidMetadata Accumulator is used in the function signature.
Returnsvoid
InvocationCalled repeatedly, once for the first input record of each group. Called before updateGroup(groupAccumulator).
DescriptionInitializes information for specific group.
Example
function void initGroup(
      companyCustomers groupAccumulator) {
   groupAccumulator.count = 0;
   groupAccumulator.totalFreight = 0;
}
boolean updateGroup(<metadata name> groupAccumulator)
Requiredyes
Input Parameters<metadata name> groupAccumulator (metadata specified by user) If groupAccumulator is not defined, VoidMetadata Accumulator is used in the function signature.
Returnsfalse (updateTransform(counter,groupAccumulator) is not called) | true (updateTransform(counter,groupAccumulator) is called)
InvocationCalled 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.
DescriptionUpdates 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 this updateGroupOnError() at the place where updateGroup() failed. If updateGroup() fails and user has not defined any updateGroupOnError(), the whole graph will fail. The updateGroup() passes to updateGroupOnError() 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)
Requiredyes
Input Parameters<metadata name> groupAccumulator (metadata specified by user) If groupAccumulator is not defined, VoidMetadata Accumulator is used in the function signature.
Returnstrue (transform(counter,groupAccumulator) is called) | false (transform(counter,groupAccumulator) is not called)
InvocationCalled 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.
DescriptionFinalizes 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 this finishGroupOnError() at the place where finishGroup() failed. If finishGroup() fails and user has not defined any finishGroupOnError(), the whole graph will fail. The finishGroup() passes to finishGroupOnError() 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)
Requiredyes
Input Parametersinteger counter (starts from 0, specifies the number of created records. should be terminated as shown in example below. Function calls end when SKIP is returned.)
<metadata name> groupAccumulator (metadata specified by user) If groupAccumulator is not defined, VoidMetadata Accumulator is used in the function signature.
ReturnsInteger numbers. See Return Values of Transformations for detailed information.
InvocationCalled repeatedly as specified by user. Called after updateGroup(groupAccumulator) returns true. The function is called until SKIP is returned.
DescriptionIt creates output records based on individual record information. If any part of the transform() function for some output record causes fail of the updateTransform() function, and if user has defined another function (updateTransformOnError()), processing continues in this updateTransformOnError() at the place where updateTransform() failed. If updateTransform() fails and user has not defined any updateTransformOnError(), the whole graph will fail. The updateTransformOnError() function gets the information gathered by updateTransform() that was get from previously successfully processed code. Also error message and stack trace are passed to updateTransformOnError().
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)
Requiredyes
Input Parametersinteger counter (starts from 0, specifies the number of created records. should be terminated as shown in example below. Function calls end when SKIP is returned.)
<metadata name> groupAccumulator (metadata specified by user) If groupAccumulator is not defined, VoidMetadata Accumulator is used in the function signature.
ReturnsInteger numbers. See Return Values of Transformations for detailed information.
InvocationCalled repeatedly as specified by user. Called after finishGroup(groupAccumulator) returns true. The function is called until SKIP is returned.
DescriptionIt 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 the transform() function, and if user has defined another function (transformOnError()), processing continues in this transformOnError() at the place where transform() failed. If transform() fails and user has not defined any transformOnError(), the whole graph will fail. The transformOnError() function gets the information gathered by transform() that was get from previously successfully processed code. Also error message and stack trace are passed to transformOnError().
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)
Requiredno
Input Parametersstring errorMessage
string stackTrace
<metadata name> groupAccumulator (metadata specified by user) If groupAccumulator is not defined, VoidMetadata Accumulator is used in the function signature.
Returnsvoid
InvocationCalled if initGroup() throws an exception.
DescriptionInitializes 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)
Requiredno
Input Parametersstring errorMessage
string stackTrace
<metadata name> groupAccumulator (metadata specified by user) If groupAccumulator is not defined, VoidMetadata Accumulator is used in the function signature.
Returnsfalse (updateTransform(counter,groupAccumulator) is not called) | true (updateTransform(counter,groupAccumulator) is called)
InvocationCalled if updateGroup() throws an exception for a record of the group. Called repeatedly (once for each of the other input records of the group).
DescriptionUpdates 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)
Requiredno
Input Parametersstring errorMessage
string stackTrace
<metadata name> groupAccumulator (metadata specified by user) If groupAccumulator is not defined, VoidMetadata Accumulator is used in the function signature.
Returnstrue (transform(counter,groupAccumulator) is called) | false (transform(counter,groupAccumulator) is not called)
InvocationCalled if finishGroup() throws an exception.
DescriptionFinalizes 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)
Requiredyes
Input Parametersstring 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 when SKIP is returned.)
<metadata name> groupAccumulator (metadata specified by user) If groupAccumulator is not defined, VoidMetadata Accumulator is used in the function signature.
ReturnsInteger numbers. See Return Values of Transformations for detailed information.
InvocationCalled if updateTransform() throws an exception.
DescriptionIt 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)
Requiredno
Input Parametersstring 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 when SKIP is returned.)
<metadata name> groupAccumulator (metadata specified by user) If groupAccumulator is not defined, VoidMetadata Accumulator is used in the function signature.
ReturnsInteger numbers. See Return Values of Transformations for detailed information.
InvocationCalled if transform() throws an exception.
DescriptionIt 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()
RequiredNo
DescriptionPrints error message specified and invocated by user
InvocationCalled in any time specified by user (called only when either updateTransform(), transform(), updateTransformOnError(), or transformOnError() returns value less than or equal to -2).
Returnsstring
void preExecute()
RequiredNo
Input parametersNone
Returnsvoid
DescriptionMay be used to allocate and initialize resources required by the transform. All resources allocated within this function should be released by the postExecute() function.
InvocationCalled during each graph run before the transform is executed.
void postExecute()
RequiredNo
Input parametersNone
Returnsvoid
DescriptionShould be used to free any resources allocated within the preExecute() function.
InvocationCalled during each graph run after the entire transform was executed.

[Important]Important
  • Input records or fields

    Input records or fields are accessible within the initGroup(), updateGroup(), finishGroup(), initGroupOnError(), updateGroupOnError(), and finishGroupOnError() functions.

    They are also accessible within the updateTransform(), transform(), updateTansformOnError(), and transformOnError() functions.

  • Output records or fields

    Output records or fields are accessible within the updateTransform(), transform(), updateTansformOnError(), and transformOnError() functions.

  • Group accumulator

    Group accumulator is accessible within the initGroup(), updateGroup(), finishGroup(), initGroupOnError(), updateGroupOnError(), and finishGroupOnError() functions.

    It is also accessible within the updateTransform(), transform(), updateTansformOnError(), and transformOnError() functions.

  • All of the other CTL template functions allow to access neither inputs nor outputs or groupAccumulator.

[Warning]Warning

Remember that if you do not hold these rules, NPE will be thrown!

Java Interfaces for Rollup

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: