Reformat
Short Description |
Ports |
Metadata |
Reformat Attributes |
Details |
Examples |
Best Practices |
See also |
Short Description
Reformat manipulates record’s structure or content.
Component | Same input metadata | Sorted inputs | Inputs | Outputs | Java | CTL | Auto-propagated metadata |
---|---|---|---|---|---|---|---|
Reformat | - | ⨯ | 1 | 1-N | ✓ | ✓ | ✓ |
Ports
Port type | Number | Required | Description | Metadata |
---|---|---|---|---|
Input | 0 | ✓ | for input data records | Any(In0) |
Output | 0 | ✓ | for transformed data records | Any(Out0) |
1-n | ⨯ | for transformed data records | Any(OutPortNo) |
This component has one input port and at least one output port.
The component can send different records to different output ports or even send the same data record to more output ports.
Metadata
Reformat propagates metadata from the input port to the output port (from left to right), but it does not propagate metadata from the output port to the input port (from right to left).
Metadata propagation through reformat has low priority.
Reformat Attributes
Attribute | Req | Description | Possible values |
---|---|---|---|
Basic | |||
Transform | [1] | The definition of how records should be reformatted. Written in the graph source either in CTL or in Java. | |
Transform URL | [1] | The name of the external file, including the path, containing the definition of the way how records should be reformatted; written in CTL or Java. | |
Transform class | [1] | The name of an external class defining the way how records should be reformatted. | |
Transform source charset | Encoding of external file defining the transformation. The default encoding depends on DEFAULT_SOURCE_CODE_CHARSET in defaultProperties. | E.g. UTF-8 | |
Deprecated | |||
Error actions | The definition of an action that should be performed when the specified transformation returns an Error code. See Return Values of Transformations. | ||
Error log | The URL of the file to which error messages for specified Error actions should be written. If not set, they are written to Console. | ||
[1]
One of these must be specified. Any of these transformation
attributes uses a CTL template for Reformat or
implements a For more information, see CTL Scripting Specifics or Java Interfaces for Reformat. For detailed information about transformations, see also Defining Transformations. |
Details
Reformat receives potentially unsorted data through the single input port, transforms each of them in a user-specified way and sends the resulting record to the port(s) specified by the user. Return values of the transformation are numbers of output port(s) to which data record will be sent.
A transformation must be defined.
The transformation uses a CTL template for Reformat,
implements a RecordTransform
interface or inherits from a
DataRecordTransform
superclass.
The interface methods are listed below.
CTL Scripting Specifics
When you define any of the three transformation attributes, specify a transformation that assigns a number of output port to each input record.
For detailed information about CloverDX Transformation Language, see Part X, CTL2 - CloverDX 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 a custom transformation using the simple CTL scripting language.
CTL Templates for Reformat
Reformat uses the same transformation template as DataIntersection and Joiners. For more information, see CTL Templates for Joiners.
Java Interfaces for Reformat
Reformat implements the same interface as DataIntersection and Joiners. For more information, see Java Interfaces for Joiners and Public CloverDX API.
Examples
Using reformat to drop field(s) |
Splitting the records |
Filtering records |
Using reformat to drop field(s)
This example shows a way to use Reformat to drop unnecessary metadata fields.
Input metadata contains the firstname, surname and address fields. Output metadata contains the firstname and surname fields. Drop the address field.
Solution
In Reformat, specify the Transform attribute.
Attribute | Value |
---|---|
Transform | //#CTL2 function integer transform() { $out.0.firstname = $in.0.firstname; $out.0.surname = $in.0.surname; return ALL; } |
You can use $out.0.* = $in.0.*;
instead of specifying the mapping of particular fields.
Splitting the records
This example shows a way to use Reformat to split one record to multiple parts and send each part to a different output port.
Input metadata contains the ID, firstname, surname and address fields. Send ID, firstname and surname to the first output port and ID and address to the second output port.
Solution
In Reformat, set the Transform attribute.
Attribute | Value |
---|---|
Transform | //#CTL2 function integer transform() { $out.0.ID = $in.0.ID; $out.0.firstname = $in.0.firstname; $out.0.surname = $in.0.surname; $out.1.ID = $in.0.ID; $out.1.address = $in.0.address; return ALL; } |
Filtering records
Reformat can be used as a filter.
Input metadata contains the ID and color fields. Valid colors are red, green, or blue. Send red items to the first output port; green items to the second output port; and blue items to the third output port. Items without correct color should be send to the fourth output port.
Solution
Attribute | Value |
---|---|
Transform | //#CTL2 function integer transform() { if ( $in.0.color == "red" ) { $out.0.* = $in.0.*; return 0; } if ( $in.0.color == "green" ) { $out.1.* = $in.0.*; return 1; } if ( $in.0.color == "blue") { $out.2.* = $in.0.*; return 2; } $out.3.* = $in.0.*; return 3; } |
There are components specialized on filtering of records: Filter and Validator.
Best Practices
Use Reformat To
Drop unwanted fields
Validate fields using functions or regular expressions
Calculate new or modify existing fields
Convert data types
If the transformation is specified in an external file (with Transform URL), we recommend users to explicitly specify Transform source charset.