Upload
deepti-gupta
View
218
Download
0
Embed Size (px)
Citation preview
8/6/2019 Case Transform
1/22
Case transform - This transform allows you to specify multiple conditions and route the
data to multiple targets depending upon the condition.
If you observe the case transform icon, it says it will accept one source and will producemultiple targets. Only one of multiple branches is executed per row.
Will see what all the options available,
Label: This is nothing but the Name of Condition, if case condition is true the data will
route to that particular target.
Expression: This defines cases and labels for output paths
Default: Only available if Produce default option when all expression are falseoption is enabled.
True: For one case only option is enabled, the row is passed to 1st
case whose expressionreturns true else passed to all cases whose expression returns true.
Data O/P: Connection between case transform & obj used for a particular case must belabeled. Each O/P label must be used at least once
Design Steps:
Design a DF that extract records from EMP table
Now place a case transform on to the workspace from local object library
Connect source to case transform, give a dbl. click on case transform, Case editor
window will be opened Now you can add the case conditions according to your requirement.
Here my requirement is, based on the DEPTNO i want to route the records and load them
in correspoding tables respectivelyIf DEPTNO = 10 then load in TGT_10
DEPTNO = 20 then load in TGT_20
DEPTNO = 30 then load in TGT_30DEPTNO = 40 as default
8/6/2019 Case Transform
2/22
After defining the case condtions, comeout from the editor and link theappropriate targets.
8/6/2019 Case Transform
3/22
8/6/2019 Case Transform
4/22
the job after designing your time dimension without validating the DF/Job.
However, this has been overwhelmed in later versions. And one can pass
variables inspite of selecting values.
End date : The date range ends with 9999.12.31. Instead of selecting values we
can pass variables also.
Increment : We can specify date intervasl between the sequence. We canincrement daily, weekly and monthly.
Join rank : While constructing the join, sources will be joined based on their
ranks.
Cache : The dataset will be cahced in memory to be used in later transforms.
Design Steps:
Drag the date_generation transform from the object library on to the workspace,
and in the next step connect a query transform and next step is your target object.
Your design would be like this
Now open the date_generation transform and mention values, check the image for
reference
http://dwhnotes.com/wp-content/uploads/2009/02/date_gen.jpg8/6/2019 Case Transform
5/22
Now in the query transform i had applied some funtions like month(), year(),
quarter(), day_in_month(), week_in_year() etc. Check the image how i mapped.
http://dwhnotes.com/wp-content/uploads/2009/02/date_gen1.jpg8/6/2019 Case Transform
6/22
Now youre done with the design part, save it and execute it. View the data
http://dwhnotes.com/wp-content/uploads/2009/02/date_gen3.jpghttp://dwhnotes.com/wp-content/uploads/2009/02/date_gen2.jpg8/6/2019 Case Transform
7/22
Merge Transform
Mege Transform: Combines two or more scehmas as a single schema, it is equivalent to
UNION ALL operator in Oracle
Input datasets must have same structure(same number of columns, same names),
dataypes and their datasizes
Design Steps:
Place your source tables on the work area
Drag the Merge transform from the object library and connect each source tomerge
Click on the merge transform, nothing to do here just validate the window,
comeout from the merge transform
Now connect it to the TGT table, give a click on validate all and save the job andexecute the job
8/6/2019 Case Transform
8/22
http://dwhnotes.com/wp-content/uploads/2009/02/merge1.jpg8/6/2019 Case Transform
9/22
Key_Generation Transform
When creating a dimension table in a data warehouse, we generally create the tables witha system generated key to unqiuely identify a row in the dimension. This key is also
known as a surrogate key.
Note on Key_Generation: To generate artificial keys in DI we can useeitherKey_Generation Transform or Key_Generation Funtion. It looks into the table
and fetches max. existing key value and that will be used as a starting value. Based on
this starting value, transform/function increments the value for each row.
http://dwhnotes.com/wp-content/uploads/2009/02/merge2.jpghttp://dwhnotes.com/files/2009/02/merge2.jpg8/6/2019 Case Transform
10/22
Options: We have three options
Table Name : You should provide table name along with the Datastore and
Owner (DATASTORE.OWNER.TABLE)
Generated Key Column : The new artificial keys are inserted into this column.
Remember your key column should be in any number datatype (REAL, FLOAT,DOUBLE, INTEGER, DECIMAL), if it is any other data type, then DI will throw
an error. Increment value : Specify your interval for system generated key values.
Surrogate key will be incremented based on this interval value. From 11.7 version
onwards, we can pass variables also.
Design Steps: Here Im populating customer information, Ive a primary calledCustomer_ID in the both source & target tables, but I want to maintain a
SURROGATE_KEY.
http://dwhnotes.com/wp-content/uploads/2009/02/key_gen2.jpghttp://dwhnotes.com/wp-content/uploads/2009/02/key_gen1.jpg8/6/2019 Case Transform
11/22
Have a glance on soruce data, here it is
key_gen transform always expects a SURROGATE_KEY column in SCHEMA IN
http://dwhnotes.com/wp-content/uploads/2009/02/key_gen3.jpg8/6/2019 Case Transform
12/22
After completion of your job execution, here is the target customers_dim target data with
surrogate key values.
http://dwhnotes.com/wp-content/uploads/2009/02/key_gen4.jpg8/6/2019 Case Transform
13/22
Map_Operation Transform
Map_Operation: It allows you to change the opcodes on your data. Before
discussing this we should know about opcodes precisely
In DI we have 5 opcodes, Normal, Insert, Update, Delete and Discard(youll see thisoption in Map_Operaion only)
Normal: Indeed, it creates a new row in the target. The data which is coming from the
source, is usually flagged as normal opcode
Insert: It does the same thing, it creates a new row in the target and the rows will be
flagged as I Insert
Update: If the rows are flagged as U , it overwrites an existing row in the target.
Delete: If the rows are flagged as D, those rows will be deleted from the target
http://dwhnotes.com/wp-content/uploads/2009/02/key_gen5.jpg8/6/2019 Case Transform
14/22
Discard: If you select this option, those rows will not be loaded into the target.
Understanding Opcodes: Here is an example, in the below figure Im using (normal to
normal, normal to insert, normal to update, normal to delete) opcodes. Here i have takennormal opcode mainly because, query transform always takes normal rows as input and
produces normal rows as output. However, will share the remaining opcodes in Tablecomparison and History Preserving transforms.
In the first flow, i.e., MO_Normal-> i have selected Normal as Normal anddiscarded rest all opcodes.
http://dwhnotes.com/wp-content/uploads/2009/02/map_op_opcodes.jpg8/6/2019 Case Transform
15/22
This flow inserts all records in to the target which are coming from the source
In the second flow, MO_Insert-> i have selected normal as insert and discardedrest all opcodes.
It does the same thing, inserts all records in to target.
Have a glance on both the data sets before loading in to the target. You will see no
opcode for Normal as Normal rows(1st flow), but you can see Insert opcodeindicated as I for Normal as Insert (2nd flow).
In the third flow, i want to update few records in the target .
o Lets say i want to update all the records whose deptno = 20.
http://dwhnotes.com/wp-content/uploads/2009/02/normal_insert.jpghttp://dwhnotes.com/wp-content/uploads/2009/02/normal_insert1.jpghttp://dwhnotes.com/wp-content/uploads/2009/02/mo_normal.jpg8/6/2019 Case Transform
16/22
o Now, I have selectednormal as update in the map_operation and
discarded rest all.
Check the data, you can see the updated rows flagged as U
In the fourth flow, I want to delete some records from the target.
o Lets say i want to delete rows whose deptno = 30, in the map_operation
transform i have selected normal as delete and discarded rest allo In the qry transform i have filtered out few records, where i want to delete
those from the target.
and you can see the data after the map_operation dataset along with delete opcodeD.
http://dwhnotes.com/wp-content/uploads/2009/02/mo_delete.jpghttp://dwhnotes.com/wp-content/uploads/2009/02/normal_update.jpghttp://dwhnotes.com/wp-content/uploads/2009/02/mo_update.jpg8/6/2019 Case Transform
17/22
In the target data set, the above records will be deleted. Check the target data
Now here in the sub-flow, i have inserted these deleted records in to another table.
For this i have added one more Map_Operation and selected row type delete as
insert.
http://dwhnotes.com/wp-content/uploads/2009/02/mo_del_ins.jpghttp://dwhnotes.com/wp-content/uploads/2009/02/deleted_data.jpghttp://dwhnotes.com/wp-content/uploads/2009/02/normal_delete.jpg8/6/2019 Case Transform
18/22
Now in the last and final flow, i have discarded all the opcodes. I do not want to
load the data in to the target.
Check the data
http://dwhnotes.com/wp-content/uploads/2009/02/mo_discad.jpghttp://dwhnotes.com/wp-content/uploads/2009/02/del_ins.jpg8/6/2019 Case Transform
19/22
Pivot Transform
Pivot: This creates a new row for every value that you specified as a pivot column.
Observe the icon, it says that will convert column to rows.
Options:
Pivot_Sequence : It creates a sequence for each row created from a pivoted
column
Non Pivot : List of columns specified here by you, those will be displayed as it
is in the target.
Pivot Sets : For each n every pivot set, you can define a set of columns. For
each set you will be having a Header column and a Data column. Header
column consists all the pivoted columns, and Data column contains the actual
data in the pivoted columns.
Pivot Columns : Set of columns swivelled to rows.
Design Steps: Having 5 columns in the source table(Sno, Sname, Jan_sal, Feb_sal,
Mar_sal). I want to convert salary column values in to rows
http://dwhnotes.com/wp-content/uploads/2009/02/normal_discard.jpg8/6/2019 Case Transform
20/22
Drag the source table and target table from Datastore object library on to the
workspace, drag the Pivot transform and place in between your source and target.
Now, connect each object as shown in the below figure.
Have a glance on source data
http://dwhnotes.com/wp-content/uploads/2009/02/pivot_source.jpghttp://dwhnotes.com/wp-content/uploads/2009/02/pivot1.jpg8/6/2019 Case Transform
21/22
Give a dbl. click on the Pivot Transform. Check the Pivot sequence name, by
default PIVOT_SEQ will be there. If you want you can change or leave as it is.
Now I want to load Sno, Sname as it is. So i have dragged these two columns onto the Non-pivotal list.
Now drag all SAL Columns on to the Pivotal list. Default PIVOT_DATA,PIVOT_HDR names will be ge generated.
Save the definition, now you can see, (SNO, SNAME, PIVOT_SEQ,PIVOT_HDR, PIVOT_DATA) columns in Schema Out.
http://dwhnotes.com/wp-content/uploads/2009/02/pivot_trns.jpg8/6/2019 Case Transform
22/22
Come out from the Pivot tranform by pressing BACKbutton on the standard tool
bar.
Save the Dataflow, validate it and execute the job.
Check out the resultant data.
http://dwhnotes.com/wp-content/uploads/2009/02/pivot_target.jpg