Informatica Scenario Based Interview Problems with Answers
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 Realtional table into a target?
Solution: In case of relational table you can go to source qualifier go to propert 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 Secong Half rows from a Realtional table into a target?
Solution: In case of relational table you can go to source qualifier go to propert 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 he 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
ID COL1 COL2 ROW_NUMBER
1 A 10 1
2 B 20 2
3 C 30 3
4 D 10 4
5 E 30 5
6 F 10 6
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
COL, O_COUNT, O_DUMMY
A , 1 , 1
B , 2 , 1
C , 3 , 1
D , 4 , 1
E , 5 , 1
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
5 , 1
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
COL, O_COUNT, O_TOTAL_RECORDS
A , 1 , 5
B , 2 , 5
C , 3 , 5
D , 4 , 5
E , 5 , 5
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
COL,O_COUNT, O_TOTAL_RECORDS
C , 3 , 5
D , 4 , 5
E , 5 , 5
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
Product, O_dummy
A, 1
B, 1
B, 1
B, 1
C, 1
C, 1
D, 1
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
Product, O_count_of_each_product
A, 1
B, 3
C, 2
D, 1
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
product, O_dummy, O_count_of_each_product
A, 1, 1
B, 1, 3
B, 1, 3
B, 1, 3
C, 1, 2
C, 1, 2
D, 1, 1
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
Product, O_Count
A, 1
B, 1
B, 2
B, 3
C, 1
C, 2
D, 1
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.
For more Questions Continue to Part 2
No comments:
Post a Comment