Transform Editor
Transform editor is an editor in which you can define a transformation. The Transform Editor is accessible from Component Editor of components having transformation.
When you open the Transform editor, you can see the following tabs: Transformations, Source and Regex tester.
To use the transform editor you should have both input and output metadata defined and assigned. Only with metadata you define the desired mapping in comfortable way.
Transformations Tab
Transformation tab consists of four parts:
Left pane contains input fields of all input ports and their data types.
Right pane displays output fields of all output ports and their data types.
The middle part of dialog serves for construction of the right side of transformation assignment. Each line of the dialog corresponds to one field of the output record.
There are five tabs in the middle bottom area: Functions,Variables, Sequences, Parameters and Dictionary. They let you use available build-in functions, sequences, parameters or dictionary in the transformation. Variable tab lets you define a variable and its value and subsequently use it in a transformation.
There are filters in the bottom of the panes. You can use the filters to find field or function to use.
Defining the Transformation
In the Transformations tab, you can define a transformation by simple drag and drop.
You can map fields between multiple input and output ports. In all components both input and output ports are numbered starting from 0.
You can easily recognize which fields are mapped. The mapped fields become bold.
To design a simple one-to-one mapping, drag fields from the left hand pane to the right hand pane.
If you drop the field onto an output field, you create a mapping.
The middle part of the dialog is filled in automatically to the expression like: $in.portnumber.fieldname
.
If you need to map input record fields to output record fields with a same name, drag and drop the whole record.
The middle part of the dialog will contain:$in.portnumber.*
.
To map more input fields to one output field or to apply a CTL function on the field value you need the middle pane. Drag and drop input field(s) to a field in the middle pane, use function(s), sequences or dictionary values and drag and drop the middle pane field onto right pane field.
For example, if you want to concatenate values of various fields you drag and drop all fields to be concatenated the same row in the Transformations pane.
Expression similar to $in.portnumber1.fieldnameA+$in.portnumber1.fieldnameB
appears.
The input fields can come from different input ports (in the case of Joiners and the DataIntersection component).
Whenever the mapping is correct, the corresponding circle is filled in with blue.
Creating Mapping vs. Adding Field
If you drop input field into a blank space of the right hand pane (between two fields), you will just copy input metadata to the output. Metadata copying is a feature which works only within a single port.
You can also copy any input field to the output by right-clicking the input field item in the left pane and selecting Copy fields to… and the name of the output metadata:
Remember that if you have not defined the output metadata before defining the transformation, you can define them even here by copying and renaming the output fields using right-click. However, it is much simpler to define new metadata prior to defining the transformation.
If you defined the output metadata using this Transform editor, you would be informed that output records are not known and you would have to confirm the transformation with this error and (after that) specify the delimiters in metadata editor.
Fields of output metadata can be rearranged by a simple drag and drop with the left mouse button. |
Mapping Visualization
If you select any item in the left, middle or right pane, corresponding items will be connected by lines. See example below:
Expression Editor
You can write the desired transformation:
-
Into individual rows of the Transformations pane - optionally, drag any function you need from the bottom Functions tab (the same counts for Variables, Sequences or Parameters) and drop them into the pane. Use Filter to quickly jump to the function you are looking for.
-
By clicking the '…' button which appears after selecting a row inside the Transformations pane. This opens an editor for defining the transformation. It contains a list of fields, functions and operators and also provides hints. See below:
Wildcard Mapping
Transform editor supports wildcards in mapping.
If you right click a record or one of its fields, click Map record to and select a record, you will produce a transformation like this (as observed in the Source tab): $out.0.* = $in.1.*;
, meaning "all output fields of record number 0 are mapped to all input fields of record number 1". In Transformations, wildcard mapping looks like this:
Source Tab
Some of your transformations may be too complex to be defined in the Transformations tab. You can use the Source tab instead. The transformation is written in CloverDX Transformation Language (CTL2).
Next figure displays Source tab with the transformation defined in text above.
There are some useful keyboard shortcuts available while editing transformation in Source tab:
-
Ctrl+/ - toggle comment on selected text.
-
Tab - indent selected text.
-
Shift+Tab - unindent selected text.
-
Ctrl+D - delete line.
In the upper right corner of either tab, there are three buttons: for launching a wizard to create a new Java transform class (Java Transform Wizard button), for creating a new tab in Graph Editor (Open tab button), and for converting the defined transformation to Java (Convert to Java button).
Java Transform Wizard
If you want to create a new Java transform class, press the Java Transform Wizard button. The following dialog will open:
After you click the Finish button, information about the transform result appears.
The Source folder field will be mapped to the project ${TRANS_DIR}
, for example SimpleExamples/trans
. A new transform class can be created by entering the Name of the class and, optionally, the containing Package and pressing the Finish button.
The newly created class will be located in the Source folder.
Open Tab
If you click the Open tab, the second button in the upper right corner of the Transform editor, a new tab with the CTL source code of the transformation will be opened in the Graph Editor with a notification as shown below:
The new tab is opened at the same level as Graph and Source.
If you switch to this tab, you can view the declared variables and functions in the Outline pane.
Functions and variables are displayed in the Outline.
The tab can be closed by clicking the red cross in the upper right corner of the tab.
Content Assist
Content Assist helps you choosing the proper field, variable or function.
Content assist is made active by pressing Ctrl+Space.
If you press these two keys inside any of the expressions, the help advises what should be written to define the transformation.
If you press these two keys outside any of the expressions, the help offers a list of functions that can be used to define the transformation.
If you have an error in your definition, a red circle with a white cross appears on the corresponding line followed by a more detailed information at the lower left corner.
Convert to Java
If you want to convert the transformation code into the Java language, click the Convert to Java button.
Remember also that you can define your own error messages by defining the last function: getMessage()
.
It returns strings that are written to console.
More details about transformations in each component can be found in the sections in which these components are described.
Remember that the To allow calling this function, you must add |
Regex Tester
This is the last tab of the Transform Editor and it is described here: Tabs Pane.