Short Description |
Ports |
Metadata |
Reformat Attributes |
Details |
Examples |
Best Practices |
See also |
Reformat manipulates record’s structure or content.
Component | Same input metadata | Sorted inputs | Inputs | Outputs | Java | CTL | Auto-propagated metadata |
---|---|---|---|---|---|---|---|
Reformat | - | 1 | 1-N |
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.
Reformat propagates metadata from input port to output port (from left to right), but it does not propagate metadata from output port to input port (from right to left).
Metadata propagation through reformat has low priority.
Attribute | Req | Description | Possible values |
---|---|---|---|
Basic | |||
Transform | [1] | Definition of how records should be reformatted. Written in the graph source either in CTL or in Java. | |
Transform URL | [1] | Name of external file, including path, containing the definition of the way how records should be reformatted; written in CTL or Java. | |
Transform class | [1] | Name of 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 | Definition of the action that should be performed when the specified transformation returns some Error code. See Return Values of Transformations. | ||
Error log | 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 See CTL Scripting Specifics or Java Interfaces for Reformat for more information. See also Defining Transformations for detailed information about transformations. |
Reformat receives potentially unsorted data through single input port, transforms each of them in a user-specified way and sends the resulting record to the port(s) specified by 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.
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 Clover Transformation Language see Part X, CTL2 - CloverETL 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.
Reformat uses the same transformation template as DataIntersection and Joiners. See CTL Templates for Joiners for more information.
Reformat implements the same interface as DataIntersection and Joiners. See Java Interfaces for Joiners and Public Clover API for more information.
Using reformat to drop field(s) |
Splitting the records |
Filtering records |
This example shows way to use Reformat to drop unnecessary metadata fields.
Input metadata contains firstname, surname, and address fields. Output metadata contains firstname and surname fields. Drop address field.
In Reformat, specify 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.
This example shows way to use Reformat to split one record to multiple parts and send each part to different output port.
Input metadata contains 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.
In Reformat, set 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; } |
Reformat can be used as a filter.
Input metadata contains 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.
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.
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.