Merge Stage:
The Merge stage is a processing stage. It can have any number of input links, a single output link, and the same number of reject links as there are update input links.(according to DS documentation)
Merge stage combines a mster dataset with one or more update datasets based on the key columns.the output record contains all the columns from master record plus any additional columns from each update record that are required.
A master record and update record will be merged only if both have same key column values.
The data sets input to the Merge stage must be key partitioned and sorted. This ensures that rows with the same key column values are located in the same partition and will be processed by the same node. It also minimizes memory requirements because fewer rows need to be in memory at any one time.
As part of preprocessing your data for the Merge stage, you should also remove duplicate records from the master data set. If you have more than one update data set, you must remove duplicate records from the update data sets as well.
Unlike Join stages and Lookup stages, the Merge stage allows you to specify several reject links. You can route update link rows that fail to match a master row down a reject link that is specific for that link. You must have the same number of reject links as you have update links. The Link Ordering tab on the Stage page lets you specify which update links send rejected rows to which reject links. You can also specify whether to drop unmatched master rows, or output them on the output data link.
Example :
Master dataset: | |
CUSTOMER_ID | CUSTOMER_NAME |
1 | UMA |
2 | POOJITHA |
Update dataset1 | |||
CUSTOMER_ID | CITY | ZIP_CODE | SEX |
1 | CYPRESS | 90630 | M |
2 | CYPRESS | 90630 | F |
Output: | ||||
CUSTOMER_ID | CUSTOMER_NAME | CITY | ZIP_CODE | SEX |
1 | UMA | CYPRESS | 90630 | M |
2 | POOJITHA | CYPRESS | 90630 | F |
Merge stage configuration steps:
Unmatched Masters Mode:Keep means that unmatched rows (those without any updates) from the master link are output; Drop means that unmatched rows are dropped instead.
Warn On Reject Updates:True to generate a warning when bad records from any update links are rejected.
Warn On Unmatched Masters:True to generate a warning when there are unmatched rows from the master link.
Remove a record from the updateds1 and check the output:
Check for the datastage warning in the job log as we have selected Warn on unmatched masters = TRUE
stg_merge,0: Master record (0) has no updates.
stg_merge,1: Update record (1) of data set 1 is dropped; no masters are left.
Scenarios 3:Drop unmatched master record and capture reject records from updateds1
Update Dataset2 | |
CUSTOMER_ID | CITIZENSHIP |
1 | INDIAN |
2 | AMERICAN |
Still we have duplicate row in the master dataset.if you compile the job with above design you will get compilation error like below.
No change the results and merge stage automatically dropped the duplicate row.
Scenario 6:modify a duplicate row for customer_id=1 in updateds1 dataset with zipcode as 90630 instead of 90620.
This post covered most of the merge scenarios.
No comments:
Post a Comment