Tuesday 8 August 2017

More Informatica Scenarios


Q 1. How to generate sequence / incremental numbers in Informatica?

Solution 1: In the expression transformation, create a variable port and increment it by 1. Then assign the variable port to an output port.

In the expression transformation, the ports are:
V_COUNT=V_COUNT+1
O_COUNT=V_COUNT

Solution 2: Insert a sequence generator transformation drag NEXTVAL port from sequence generator to expression.This port will give you the incremental numbers.
Use Start Value property to 1 and Increment By property to 1 for a series like 1,2,3,4,5,6,7,8.....


Q 2. Design a Informatica mapping to load the First Half rows from a Relational table into a target?

Solution: In case of relational table you can go to source qualifier  go to property and write the SQL query like

SELECT * from EMP
    WHERE ROWNUM <= (SELECT Count(*)/2  FROM EMP)

No additional filter required connect all ports to other transformation and finally to target, then run the mapping.

Q 3. Design a Informatica mapping to load the Second Half rows from a Relational table into a target?

Solution: In case of relational table you can go to source qualifier  go to property and write the SQL query like

SELECT * from EMP
MINUS
SELECT * from EMP
    WHERE ROWNUM <= (SELECT Count(*)/2  FROM EMP)

No additional filter required connect all ports to other transformation and finally to target, then run the mapping.

Q 4. Design a Informatica mapping to load the first 4 rows from a flat file into a target?

Solution: Now that the above query wont work for a flat file source then you have to assign row numbers to each record. Generate the row numbers either using the expression transformation as mentioned above or use sequence generator transformation.Then pass the output to filter transformation and specify the filter condition as ROW_NUMBER <=4


IDCOL1COL2ROW_NUMBER
1A101
2B202
3C303
4D104
5E305
6F106

Q 5. Design a Informatica mapping to load the last 3 rows from a flat file into a target?

Solution: Consider the source has the following data.

COLUMN
A
B
C
D
E

Step1: You have to assign row numbers to each record. Generate the row numbers using the expression transformation as mentioned above and call the row number generated port as O_COUNT. Create a DUMMY output port in the same expression transformation and assign 1 to that port. So that, the DUMMY output port always return 1 for each row.

In the expression transformation, the ports are
V_COUNT=V_COUNT+1
O_COUNT=V_COUNT
O_DUMMY=1

The output of expression transformation will be

COLO_COUNTO_DUMMY
A11
B21
C31
D41
E51

Step2: Pass the output of expression transformation to aggregator and do not specify any group by condition. Create an output port O_TOTAL_RECORDS in the aggregator and assign O_COUNT port to it. The aggregator will return the last row by default. The output of aggregator contains the DUMMY port which has value 1 and O_TOTAL_RECORDS port which has the value of total number of records in the source.

In the aggregator transformation, the ports are
O_DUMMY
O_COUNT
O_TOTAL_RECORDS=O_COUNT

The output of aggregator transformation will be


O_TOTAL_RECORDS O_DUMMY
51

Step3: Pass the output of expression transformation, aggregator transformation to joiner transformation and join on the DUMMY port. In the joiner transformation check the property sorted input, then only you can connect both expression and aggregator to joiner transformation.

In the joiner transformation, the join condition will be
O_DUMMY (port from aggregator transformation) = O_DUMMY (port from expression transformation)

The output of joiner transformation will be


COLO_COUNTO_TOTAL_RECORDS
A15
B25
C35
D45
E55

Step4: Now pass the output of joiner transformation to filter transformation and specify the filter condition as O_TOTAL_RECORDS (port from aggregator)-O_COUNT(port from expression) <=2

In the filter transformation, the filter condition will be
O_TOTAL_RECORDS - O_COUNT <=2

The output of filter transformation will be

COLO_COUNTO_TOTAL_RECORDS
C35
D45
E55

Q 6. Design a Informatica mapping to load record from a flat file, first record into one table A, the last record from the flat file into table B and the remaining records into table C?

Solution: This is similar to the above problem; the first three steps are same. In the last step instead of using the filter transformation, you have to use router transformation. In the router transformation you have to create two output groups.

In the first group, the condition should be O_COUNT=1 and connect the corresponding output group to table A. In the second group, the condition should be O_COUNT=O_TOTAL_RECORDS and connect the corresponding output group to table B. The output of default group should be connected to table C.

Q 7. Consider the following source Data.

A
B
C
C
B
D
B

Q 7.1 Design a mapping to load all unique products in one table and the duplicate rows in another table.
The first table should contain the following output
A
D

The second target should contain the following output
B
B
B
C
C

Solution: Use sorter transformation and sort the products data. Pass the output to an expression transformation and create a dummy port O_dummy and assign 1 to that port. So that, the DUMMY output port always return 1 for each row.

The output of expression transformation will be


ProductO_dummy
A1
B1
B1
B1
C1
C1
D1

Pass the output of expression transformation to an aggregator transformation. Check the group by on product port. In the aggregator, create an output port O_count_of_each_product and write an expression count(product).

The output of aggregator will be


ProductO_count_of_each_product
A1
B3
C2
D1

Now pass the output of expression transformation, aggregator transformation to joiner transformation and join on the products port. In the joiner transformation check the property sorted input, then only you can connect both expression and aggregator to joiner transformation.

The output of joiner will be


ProductO_dummyO_count_of_each_product
A11
B13
B13
B13
C12
C12
C11

Now pass the output of joiner to a router transformation, create one group and specify the group condition as O_dummy=O_count_of_each_product. Then connect this group to one table. Connect the output of default group to another table.

Q 7.2 Design a Informatica mapping to load original and duplicate records in two different tables / Separating duplicate and non-duplicate rows.
The first table should contain the following output
A
B
C
D

The second table should contain the following output
B
B
C

Solution1: Use sorter transformation and sort the products data. Pass the output to an expression transformation and create a variable port,V_Current_product, and assign product port to it. Then create a V_Count port and in the expression editor write V_Count=IIF(V_Current_product=V_Previous_product,V_Count+1,1). Create one more variable port V_Previous_product and assign product port to it. Now create an output port O_Count port and assign V_Count port to it.

In the expression transformation, the ports are

Product
V_Current_product=product
V_Count=IIF(V_Current_product=V_Previous_product,V_Count+1,1)
V_Previous_product=product
O_Count=V_Count

The output of expression transformation will be

ProductO_Count
A1
B1
B2
B3
C1
C2
D1

Now Pass the output of expression transformation to a router transformation, create one group and specify the condition as O_count=1. Then connect this group to one table. Connect the output of default group to another table.

Solution2: Next approach to do this is use aggregator, First sort the data using sorter then connect it to aggregator transformation group by product with an additional port COUNT_RECORD in expression put COUNT(Product).
Now with a router transformation create two groups namely DUPLICATE & ORIGINAL and give the group condition COUNT_RECORD > 1 & COUNT_RECORD =1 respectively.

In the Aggregator transformation ports are
Product
COUNT_RECORD=COUNT(Product)

In the Router Transformation group Conditions are
DUPLICATE group (COUNT_RECORD>1)
ORIGINAL group (COUNT_RECORD=1)

Connect Table 1 to DUPLICATE group and Table 2 to Original Group. There you go you have duplicate and original data separated.



Q 8. Let us assume the following Sales Data

     
IDPERSONAL_SALES
1040000
2080000
3040000
4060000
50NULL
6050000

Q 8.1. Design a Informatica mapping to calculate the cumulative sum of PERSONAL_SALES and load that into target table?

The Expected Output in target should be


IDPERSONAL_SALESO_RETURN_VALUE
104000040000
2080000120000
3040000160000
4060000220000
50NULL220000
6050000270000

Solution:

Connect the source Qualifier to expression transformation.In the expression transformation create a variable port named V_RETURN_VALUE and write the expression CUME(PERSONAL_SALES), again create a output port O_RETURN_VALUE and assign the expression V_RETURN_VALUE to it. Connect all the output ports to target and run the mapping.
In the expression transformation,the ports are

ID                                        
PERSONAL_SALES                            
V_RETURN_VALUE = CUME(PERSONAL_SALES)
O_RETURN_VALUE =  V_RETURN_VALUE            
// Input/Output Port
// Input/Output Port
// Variable Port
// Output Port

Connect the output port from the expression transformation to the target and see the results.

Q 8.2. Design a Informatica mapping to calculate the Moving sum of PERSONAL_SALES for two rows and load that into target table?

The Expected Output in target should be

IDPERSONAL_SALESO_RETURN_VALUE
1040000NULL
2080000120000
3040000120000
4060000100000
50NULL60000
605000050000


Solution:

Connect the source Qualifier to expression transformation.In the expression transformation create a variable port named V_RETURN_VALUE and write the expression MOVINGSUM(PERSONAL_SALES,2) again create a output port O_RETURN_VALUE and assign the expression V_RETURN_VALUE to it. Connect all the output ports to target and run the mapping.
In the expression transformation,the ports are
ID                                        
PERSONAL_SALES                            
V_RETURN_VALUE = MOVINGSUM(PERSONAL_SALES,2)
O_RETURN_VALUE =  V_RETURN_VALUE            
// Input/Output Port
// Input/Output Port
// Variable Port
// Output Port

Connect the output port to the target and see the results 


Q 8.3. Design a Informatica mapping to get the previous row value for the current row. If there is no previous row then load NULL as in case of first row there is no previous row

The Expected Output in target should be

IDPERSONAL_SALESO_RETURN_VALUE
1040000NULL
208000040000
304000080000
406000040000
50NULL60000
6050000NULL


Solution:

Connect the source Qualifier to expression transformation. In the expression transformation, create a variable port V_COUNT and start incrementing it by one for each row entering the expression transformation. Also create V_SALES variable port and assign the expression IIF(V_COUNT=1,NULL,V_PREV_SALES) to it . Then Create one more variable port V_PREV_SALES and assign PERSONAL_SALES to it. Now create output port O_RETURN_VALUE and assign V_SALES to it. Connect the expression transformation to the target ports and run the mapping after creation of precedding session and workflow.

In the expression transformation, the ports will be

ID                                   
PERSONAL_SALES                       
V_COUNT=V_COUNT+1                    
V_SALES=IIF(V_COUNT=1,NULL,V_PREV_SALES)
V_PREV_SALES=PERSONAL_SALES          
O_RETURN_VALUE=V_SALES               
          
// Input/Output Port
// Input/Output Port
// Variable Port
// Variable Port
// Variable Port
// Output Port


Q 8.4. Design a mapping to get the next row Sales for the current row. If there is no next row for the current row, then the next row salary should be displayed as null.
The output should look like as

IDPERSONAL_SALESO_RETURN_VALUE
104000080000
208000040000
304000060000
4060000NULL
50NULL50000


Solution:

1. Create a source qualifier transformation and connect it to two separate expression transformation. In each of the expression transformation create a variable port V_COUNT and increment it by 1 using expression V_COUNT+1. Then create an output port O_COUNT in each expression transformation. Assign the value V_COUNT in 1st expression and V_COUNT-1 in the 2nd expression as shown below.

In the 1st expression transformation, the ports will be

ID                                        
PERSONAL_SALES                            
V_COUNT=V_COUNT+1 
O_COUNT=V_COUNT            
// Input/Output Port
// Input/Output Port
// Variable Port
// Output Port


1st Expression Data will look like
IDPERSONAL_SALESO_COUNT
10400001
20800002
30400003
40600004
50NULL5


In the 2nd expression transformation, the ports will be

ID                                        
PERSONAL_SALES                            
V_COUNT=V_COUNT+1  
O_COUNT=V_COUNT-1           
// Input/Output Port
// Input/Output Port
// Variable Port
// Output Port


2nd Expression Data will look like
IDPERSONAL_SALESO_COUNT
10400000
20800001
30400002
40600003
50NULL4

2. Connect both the expression transformations ports to joiner transformation and join them on the port O_count. Consider the 1st expression transformation as Master and 2nd one as Detail Source. Specify the join type in Joiner transformation as Detail Outer Join. In the joiner transformation check the property sorted input this will allow you to connect both expression transformations to joiner transformation. 

3. Pass the output of joiner transformation to a target table. In the Joiner transformation, connect the ID and PERSONAL_SALES from the 1st expression transformation to the ID and PERSONAL_SALES in target table. Connect the PERSONAL_SALES which is coming from the 2nd expression transformation to the next row sales port in the target table.


Q 8.5. Design a Informatica Mapping to find the sum of all sales of an employee id and this sum should come in another column for all rows.
The output should look like as
IDPERSONAL_SALESO_RETURN_VALUE
1040000270000
2080000270000
3040000270000
4060000270000
50NULL270000
6050000270000



Solution:

Create a source qualifier transformation and connect it to the Aggregator transformation.In aggregator transformation create a Output port O_RETURN_VALUE and assign expression SUM(PERSONAL_SALES). Don not specify and group by for any filed and then connect all the other output ports to target and runt the mapping.

In the Aggregator transformation, the ports will be
ID                                        
PERSONAL_SALES                            
O_RETURN_VALUE=SUM(PERSONAL_SALES)          
// Input/Output Port
// Input/Output Port
// Output Port