We assume that you have already learned what is described in:
If you want to find the right Joiner for your purposes, see Joiners Comparison.
General purpose joiner, merges sorted data from two or more data sources on a common key.
Component | Same input metadata | Sorted inputs | Slave inputs | Outputs | Output for drivers without slave | Output for slaves without driver | Joining based on equality |
---|---|---|---|---|---|---|---|
ExtMergeJoin | no | yes | 1-n | 1 | no | no | yes |
This is a general purpose joiner used in most common situations. It requires the input be sorted and is very fast as there is no caching (unlike ExtHashJoin).
The data attached to the first input port is called the master (as usual in other Joiners). All remaining connected input ports are called slaves. Each master record is matched to all slave records on one or more fields known as the join key. For a closer look on how data is merged, see Data Merging.
Tip | |
---|---|
If you want to join different slaves with the master on a key with various key fields, use ExtHashJoin instead. But remember slave data sources have to be sufficiently small. |
ExtMergeJoin receives data through two or more input ports, each of which may have a distinct metadata structure.
The joined data is then sent to the single output port.
Port type | Number | Required | Description | Metadata |
---|---|---|---|---|
Input | 0 | yes | Master input port | Any |
1 | yes | Slave input port | Any | |
2-n | no | Optional slave input ports | Any | |
Output | 0 | yes | Output port for the joined data | Any |
Attribute | Req | Description | Possible values |
---|---|---|---|
Basic | |||
Join key | yes | Key according to which the incoming data flows are joined. See Join key. | |
Join type | Type of the join. See Join Types. | Inner (default) | Left outer | Full outer | |
Transform | 1) | Transformation in CTL or Java defined in the graph. | |
Transform URL | 1) | External file defining the transformation in CTL or Java. | |
Transform class | 1) | External transformation class. | |
Allow slave duplicates | If set to true , records with
duplicate key values are allowed. If it is
false , only the first record is used for join. | false (default) | true | |
Advanced | |||
Transform source charset | Encoding of external file defining the transformation. | ISO-8859-1 (default) | |
Ascending ordering of inputs | If set to true , incoming records are
supposed to be sorted in ascending order. If it is set to
false , they are descending. | true (default) | false | |
Deprecated | |||
Locale | Locale to be used when internationalization is used. | ||
Case sensitive | If set to true , upper and lower
cases of characters are considered different. By default, they
are processed as if they were equal to each other. | false (default) | true | |
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. | ||
Left outer | If set to true , left
outer join is performed. By default it is
false . However, this attribute has lower
priority than Join type. If you set both,
only Join type will be applied. | false (default) | true | |
Full outer | If set to true , full
outer join is performed. By default it is
false . However, this attribute has lower
priority than Join type. If you set both,
only Join type will be applied. | false (default) | true |
Legend:
1) One of these must be set. These transformation attributes
must be specified. Any of these transformation attributes must use a
common CTL template for Joiners or implement a
RecordTransform
interface.
See CTL Scripting Specifics or Java Interfaces for more information.
See also Defining Transformations for detailed information about transformations.
You must define the key that should be used to join the records (Join key). The records on the input ports must be sorted according to the corresponding parts of the Join key attribute. You can define the Join key in the Join key wizard.
The Join key attribute is a sequence of individual key expressions for the master and all of the slaves separated from each other by hash. Order of these expressions must correspond to the order of the input ports starting with master and continuing with slaves. Driver (master) key is a sequence of driver (master) field names (each of them should be preceded by dollar sign) separated by colon, semicolon or pipe. Each slave key is a sequence of slave field names (each of them should be preceded by dollar sign) separated by colon, semicolon or pipe.
You can use this Join key wizard. When you click the Join key attribute row, a button appears there. By clicking this button you can open the mentioned wizard.
In it, you can see the tab for the driver (Master key tab) and the tabs for all of the slave input ports (Slave key tabs).
In the driver tab there are two panes. The Fields pane on the left and the Master key pane on the right. You need to select the driver expression by selecting the fields in the Fields pane on the left and moving them to the Master key pane on the right with the help of the Right arrow button. To the selected Master key fields, the same number of fields should be mapped within each slave. Thus, the number of key fields is the same for all input ports (both the master and each slave). In addition to it, driver (Master) key must be common for all slaves.
In each of the slave tab(s) there are two panes. The Fields pane on the left and the Key mapping pane on the right. In the left pane you can see the list of the slave field names. In the right pane you can see two columns: Master key field and Slave key field. The left column contains the selected field names of the driver input port. If you want to map some driver field to some slave field, you must select the slave field in the left pane by clicking its item, and by pushing the left mouse button, dragging to the Slave key field column in the right pane and releasing the button you can transfer the slave field to this column. The same must be done for each slave. Note that you can also use the Auto mapping button or other buttons in each tab.
Example 56.6. Join Key for ExtMergeJoin
$first_name;$last_name#$fname;$lname#$f_name;$l_name
Following is the part of Join key for the master data source (input port 0):
$first_name;$last_name
Thus, these fields are joined with the two fields from the first slave data source (input port 1):
$fname
and $lname
,
respectively.
And, these fields are also joined with the two fields from the second slave data source (input port 2):
$f_name
and
$l_name
, respectively.
Joining data in ExtMergeJoin works the following way. First of all, let us stress again that data on both the master and the slave have to be sorted.
The component takes the first record from the master and compares it to the first one from the slave (with respect to Join key). There are three possible comparison results:
master equals slave - records are joined
"slave.key < master.key" - the component looks onto the next slave record, i.e. a one-step shift is performed trying to get a matching slave to the current master
"slave.key > master.key" - the component looks onto the next master record, i.e. a regular one-step shift is performed on the master
Some input data contain sequences of same values. Then they are treated as
one unit on the slave (a slave record knows the value of the following record),
This happens only if
Allow slave duplicates has been set to true
.
Moreover, the same-values unit gets stored in the memory.
On the master, merging goes all the same by comparing one master record after
another to the slave.
Note | |
---|---|
In case there are is a large number of duplicate values on the slave, they are stored on your disk. |
When you define your join attributes you must specify a transformation that maps fields from input data sources to the output. This can be done using the Transformations tab of the Transform Editor. However, you may find that you are unable to specify more advanced transformations using this easist approach. This is when you need to use CTL scripting.
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 field mapping using the simple CTL scripting language.
All Joiners share the same transformation template which can be found in CTL Templates for Joiners.
If you define your transformation in Java, it must implement the following interface that is common for all Joiners: