Monday, 22 June 2015

SWITCH Stage in Datastage

Switch Stage in Datastage:
  • Switch stage is a Processing Stage. It has one Input Link and number of output links depending upon the ‘cases’ mentioned. Maximum it can have 128 numbers of output links and one reject link.
  • Function of Switch stage in Datastage is analogues to the Switch Statement in ‘C’ Language. For specific output required, there is specific ‘Case’ situation. As it has one Reject Link, those records which are not matched with any of the case will move to the reject link.

Let’s try to configure this Switch stage.
Consider following table
ID
First Name
Last Name
Location
Network ID
EmailID
1
Jach
Simmons
LA
JS524
Letsc@gmail.com
2
Shumas
Jane
Las
Sj145
Jaene@ymail.com
3
Jonty
Waughn
Syd
JW927
JontyW@sdbh.com
3
Suhana
Safar
Mexico
SS99
Sas@gmail.com
8
Abc
Cde
Mex
ab254
lmn@gmail.com
4
Shumas
Jane
Las
Sj145
Jaene@ymail.com
Step 1: Design your job Structure like below.
1
Configure input Sequential file sf_emp_det with above table.
Step 2:Now, to configure Switch stage, double click on it. Following window will pop up.
2
There are three categories under ‘Properties’ tab.
  1. Input
  2. User-defined Mapping
  3. Options
Let’s study one by one.
Step 3:
  1. Input: ‘Selector’ is field through which we have to select a column according to which ‘cases’ are going to be decide. Here, ‘Selector’ = ID.
In ‘Selector Mode’ as we are going to decide cases for this stage, it should be selected as ‘User-
defined Mappings’.
  1. User-defined Mappings:  Here we are going to actually decide the case statements. As shown above, for case 1, 2, 3 and 8 are all ‘ID’ values and 0, 1, 2 are all link labels which we are getting from ‘Link Ordering’ tab.
Refer following window where in right pane ‘link label’ for corresponding ‘Link name’ is given.These ‘link label’s’ are used to define cases as follows.

ID
Link Label
Link Name
Case
1
0
lnk_ID_1
Case
2
1
lnk_ID_2
Case
3
2
lnk_id_3
Case
8
5(Discard Value)

For record ID=8 will get discarded. For discarded value, ‘Link Label’ could be anything. Here is 5. Those records which are not matched with case’s get rejected and stored it in ‘Reject link’, here ‘rjct_id_4’.
3
3. Options:
Discard value: This is like giving the ‘link label’ to discarded link. Consider our case, ‘case=8=5’. For record ID=8 will get   routed to the link 5 which is mentioned here as ‘Discarded value’.
If not found: It decides action to be taken on the records which are failed to match with case statement.
  1. Drop: It will drop the entire row
  2. Fail: It will cause the job to fail.
  3. Output: It will route that particular row to the reject link.
Note: Reject link is not allowed with the ‘Drop’ and ’Fail’ condition. It will throw error during compilation.
Step 4: Let’s see what will happen to the output!!
Compile and run the job. We will see output link by link.
  1. Link lnk_ID_1 for which ‘Case=1=0’.
4
  1. Link lnk_ID_2 for which ‘Case=2=1’.
5
  1. Link lnk_id_3 for which ‘Case=3=2’.
6
  1. For Reject link lnk_rjct_id_4 :As we didn’t mention any case statement for ID=4, it will get route to the reject link.
7
  1. For ‘Case=8=5’: Record for ID=8 get discarded.

No comments:

Post a Comment