Home | Table of Contents | Transform Editor | CloverETL 4.6.1
--- | --- | ---
Prev | Transformations | Next

## Transform Editor

Transformations Tab
Source Tab
Regex Tester

Transform editor is an editor in which you can define 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.

Figure 40.2. Transformations Tab of the Transform Editor

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 pleasant way.

### Transformations Tab

Defining the Transformation
Creating Mapping vs. Adding Field
Mapping Visualization
Expression Editor
Wildcard Mapping

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 right side of transformation assignment. Each line of the dialog corresponds to one field of 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 variable and its value and subsequently use it in the 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 the 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 dialog is filled in automatically to the expression like: `$in.portnumber.fieldname`.

If your need is to map input record fields to output record fields with same name, drag and drop the whole record. The middle part of 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.

E.g. 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 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:

Figure 40.3. Copying the Input Field to the Output

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 more simple 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.

| Note
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:

Figure 40.4. Mapping of Inputs to Outputs (Connecting Lines)

#### 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:

Figure 40.5. Editor with Fields and Functions

#### 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 no 0 are mapped to all input fields of record no 1". In Transformations, wildcard mapping looks like this:

Figure 40.6. Input Record Mapped to Output Record Using Wildcards

### Source Tab

Java Transform Wizard
Open Tab
Content Assist
Convert to Java

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 Clover Transformation Language (CTL2).

Next figure displays Source tab with the transformation defined in text above.

Figure 40.7. Transformation Definition in CTL (Source Tab)

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:

Figure 40.8. Java Transform Wizard Dialog

Having used the Finish button, you are informed about the transform result.

Figure 40.9. Info after Java Transform Wizard Dialog

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. User is notified of it by the following message:

Figure 40.10. Confirmation Message

The new tab is opened at the same level as Graph and Source.

Figure 40.11. Transformation Definition in CTL (Transform Tab of the Graph Editor)

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.

Figure 40.12. Content Assist (Record and Field Names)

If you press these two keys outside any of the expressions, the help gives a list of functions that can be used to define the transformation.

Figure 40.13. Content Assist (List of CTL Functions)

If you have some error in your definition, the line will be highlighted by red circle with a white cross in it and at the lower left corner there will be a more detailed information about it.

Figure 40.14. Error in Transformation

#### Convert to Java

If you want to convert the transformation code into the Java language, click the Convert to Java button.

Figure 40.15. Transformation Definition in Java

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.

| Important
Remember that the `getMessage()` function is only called from within functions that return `integer` data type. To allow calling this function, you must add `return` statement(s) with values less than or equal to -2 to the functions that return `integer`. For example, if any of the functions like `transform()`, `append()`, or `count()`, etc. returns -2, `getMessage()` is called and the message is written to Console.

### Regex Tester

This is the last tab of the Transform Editor and it is described here: Tabs Pane.

Prev | Up | Next
Error Actions and Error Log (deprecated since 3.0) | Home | Table of Contents | Common Java Interfaces