Partition

We assume 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

Partition distributes individual input data records among different output ports.

Component Same input metadata Sorted inputs Inputs Outputs Java CTL
Partition-no11-nyes/no1)yes/no1)

Legend

1) Partition can use either transformation or other two attributes (Ranges and/or Partition key). A transformation must be defined unless at least one of these is specified.

Abstract

Partition distributes individual input data records among different output ports.

To distribute data records, user-defined transformation, ranges of Partition key or RoundRobin algorithm may be used. Ranges of Partition key are either those specified in the Ranges attribute or calculated hash values. It uses a CTL template for Partition or implements a PartitionFunction interface. Its methods are listed below. In this component no mapping may be defined since it does not change input data records. It only distributes them unchanged among output ports.

[Tip]Tip

Note that you can use the Partition component as a filter similarly to ExtFilter. With the Partition component you can define much more sophisticated filter expressions and distribute input data records among more outputs than 2.

Neither Partition nor ExtFilter allow to modify records.

[Important]Important

Partition is high-performance component, thus you cannot modify input and output records - it would result in an error. If you need to do so, consider using Reformat instead.

Icon

Ports

Port typeNumberRequiredDescriptionMetadata
Input0yesFor input data recordsAny
Output0yesFor output data recordsInput 01)
1-NnoFor output data recordsInput 01)

Legend:

1): Metadata can be propagated through this component.

Partition Attributes

AttributeReqDescriptionPossible values
Basic
Partition1)Definition of the way how records should be distributed among output ports written in the graph in CTL or Java. 
Partition URL1)Name of external file, including path, containing the definition of the way how records should be distributed among output ports written in CTL or Java. 
Partition class1)Name of external class defining the way how records should be distributed among output ports. 
Ranges1),2)Ranges expressed as a sequence of individual ranges separated from each other by semicolon. Each individual range is a sequence of intervals for some set of fields that are adjacent to each other without any delimiter. It is expressed also whether the minimum and maximum margin is included to the interval or not by bracket and parenthesis, respectively. Example of Ranges: <1,9)(,31.12.2008);<1,9)<31.12.2008,);<9,)(,31.12.2008); <9,)<31.12.2008). 
Partition key1),2)Key according to which input records are distributed among different output ports. Expressed as the sequence of individual input field names separated from each other by semicolon. Example of Partition key: first_name;last_name. 
Advanced
Partition source charset Encoding of external file defining the transformation.ISO-8859-1 (default) | other encoding
Deprecated
Locale Locale to be used when internationalization is set to true. By default, system value is used unless value of Locale specified in the defaultProperties file is uncommented and set to the desired Locale. For more information on how Locale may be changed in the defaultProperties see Changing Default CloudConnect Settings.system value or specified default value (default) | other locale
Use internationalization By default, no internationalization is used. If set to true, sorting according national properties is performed.false (default) | true

Legend:

1): If one of these transformation attributes is specified, both Ranges and Partition key will be ignored since they have less priority. Any of these transformation attributes must use a CTL template for Partition or implement a PartitionFunction interface.

See CTL Scripting Specifics or Java Interfaces for Partition (and ClusterPartitioner) for more information.

See also Defining Transformations for detailed information about transformations.

2): If no transformation attribute is defined, Ranges and Partition key are used in one of the following three ways:

CTL Scripting Specifics

When you define any of the three transformation attributes, which is optional, you must specify a transformation that assigns a number of output port to each input record.

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.

Partition uses the following transformation teplate:

CTL Templates for Partition (or ClusterPartitioner)

This transformation template is used in Partition, and ClusterPartitioner.

Once you have written your transformation in CTL, you can also convert it to Java language code by clicking corresponding button at the upper right corner of the tab.

Source Tab of the Transform Editor in the Partitioning Component

Figure 55.5. Source Tab of the Transform Editor in the Partitioning Component


You can open the transformation definition as another tab of a graph (in addition to the Graph and Source tabs of Graph Editor) by clicking corresponding button at the upper right corner of the tab.

Table 55.4. Functions in Partition (or ClusterPartitioner)

CTL Template Functions
void init()
RequiredNo
DescriptionInitialize the component, setup the environment, global variables
InvocationCalled before processing the first record
Returnsvoid
integer getOutputPort()
Requiredyes
Input Parametersnone
ReturnsInteger numbers. See Return Values of Transformations for detailed information.
InvocationCalled repeatedly for each input record
DescriptionIt does not transform the records, it does not change them nor remove them, it only returns integer numbers. Each of these returned numbers is a number of the output port to which individual record should be sent. In ClusterPartitioner, these ports are virtual and mean Cluster nodes. If any part of the getOutputPort() function for some output record causes fail of the getOutputPort() function, and if user has defined another function (getOutputPortOnError()), processing continues in this getOutputPortOnError() at the place where getOutputPort() failed. If getOutputPort() fails and user has not defined any getOutputPortOnError(), the whole graph will fail. The getOutputPortOnError() function gets the information gathered by getOutputPort() that was get from previously successfully processed code. Also error message and stack trace are passed to getOutputPortOnError().
Example
function integer getOutputPort() {
    switch (expression) {
      case const0 : return 0; break;
      case const1 : return 1; break;
      ...
      case constN : return N; break;
      [default : return N+1;]
   }
}
integer getOutputPortOnError(string errorMessage, string stackTrace)
Requiredno
Input Parametersstring errorMessage
string stackTrace
ReturnsInteger numbers. See Return Values of Transformations for detailed information.
InvocationCalled if getOutputPort() throws an exception.
DescriptionIt does not transform the records, it does not change them nor remove them, it only returns integer numbers. Each of these returned numbers is a number of the output port to which individual record should be sent. In ClusterPartitioner, these ports are virtual and mean Cluster nodes. If any part of the getOutputPort() function for some output record causes fail of the getOutputPort() function, and if user has defined another function (getOutputPortOnError()), processing continues in this getOutputPortOnError() at the place where getOutputPort() failed. If getOutputPort() fails and user has not defined any getOutputPortOnError(), the whole graph will fail. The getOutputPortOnError() function gets the information gathered by getOutputPort() that was get from previously successfully processed code. Also error message and stack trace are passed to getOutputPortOnError().
Example
function integer getOutputPortOnError(
                    string errorMessage, 
                    string stackTrace) {
   printErr(errorMessage);
   printErr(stackTrace);
}
string getMessage()
RequiredNo
DescriptionPrints error message specified and invocated by user
InvocationCalled in any time specified by user (called only when either getOutputPort() or getOutputPotOnError() returns value less than or equal to -2).
Returnsstring
void preExecute()
RequiredNo
Input parametersNone
Returnsvoid
DescriptionMay be used to allocate and initialize resources. 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 getOutputPort() and getOutputPortOnError() functions only.

  • Output records or fields

    Output records or fields are not accessible at all as records are mapped to the output without any modification and mapping.

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

[Warning]Warning

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

Java Interfaces for Partition (and ClusterPartitioner)

The transformation implements methods of the PartitionFunction interface and inherits other common methods from the Transform interface. See Common Java Interfaces.

Following are the methods of PartitionFunction interface: