Scenario Questions
Scenario Questions
Scenario Questions
The SQL Minus set operator returns the distinct rows from the first select statement which are not in second select
statement. Lets consider the employees table as an example:
emp_id, name
------------
1, Scott
1, Scott
2, Matt
2, Matt
3, Chris
emp_id, name
------------
2, Matt
2, Matt
3, Chris
Retrieve the previous row value when processing the current row.
Skip Last N rows from the source and load the reamining rows
One of my blog readers asked this question. The source data is shown below:
-----------------------
10, 2004, NY
Name
----
G
After excluding the last 5 records, i want to load A,B into the target. How to implement a mapping logic for this in
informatica?
I have employees table as a source. The data in the employees table is shown below:
---------------------
20 302, 50000
Read more
To solve these examples create the employees and departments tables in your database. The "create table" statements
are provided below.
MANAGER_ID NUMBER(6)
NAME VARCHAR2(10),
LAST_NAME VARCHAR2(10),
SALARY NUMBER(10,2),
MANAGER_ID NUMBER(6),
DEPARTMENT_ID NUMBER(4)
alter table EMPLOYEES add foreign key (DEPARTMENT_ID) references DEPARTMENTS (DEPARTMENT_ID);
-------------------------------------------------
-----------------------------------------
10 Account 201
20 HR 501
1. Create a mapping to join employees and departments table on " DEPARTMENT_ID " column using source
qualifier transformation?
Solution:
1. Source qualifier transformation can be used to join sources only from the same database.
2. Connect the source definitions of departments and employees to the same qualifier transformation.
3. As there is a primary-key, foreign-key relationship between the source tables, the source qualifier
transformation by default joins the two sources on the DEPARTMENT_ID column.
2. Create a mapping to join employees and departments table on "MANAGER_ID" column using source qualifier
transformation?
Solution:
1. Connect the source definitions of departments and employees to the same qualifier transformation.
2. Go to the properties tab of source qualifier ->User Defined Join and then open the editor. Enter the
join condition as DEPARTMENTS.MANAGER_ID = EMPLOYEES.MANAGER_ID. Click Ok.
3. Now connect the required ports from the source qualifier transformation to the target.
3. Create a mapping to get only the employees who have manager?
Solution:
This is very simple. Go to the properties tab of source qualifier-> Source Filter. Open the editor and enter
EMPLOYEES.MANAGER_ID IS NOT NULL
Solution:
Make sure the ports order in the source qualifier transformation as shown below
DEPARTMENT_ID
SALARY
EMPLOYEE_ID
NAME
LAST_NAME
MANAGER_ID
The first two ports should be DEPARTMENT_ID, SALARY and the rest of the ports can be in any order.
Now go to the properties tab of source qualifier-> Number Of Sorted Ports. Make the Number Of Sorted Ports value
as 2.
Solution:
1. The source qualifier transformation should only contain the DEPARTMENT_ID port from
EMPLOYEES source definition.
2. Now go to the properties tab of source qualifier-> Select Distinct. Check the check box of Select
Distinct option.
Informatica Problems With Solutions - Part 1
1. In this problem we will see how to implement the not equal operator, greater than, greater than or equal to, less than
and less than or equal to operators when joining two tables in informatica.
Now the problem is to identify the products whose sales is less than in the current year (In this example: 2011) when
compared to the last year.
Here in this example, Product A sold less in 2011 when compared with the sales in 2010.
This problem can be easily implemented with the help of SQL query as shown below
SELECT cy.*
FROM SALES cy,
SALES py
WHERE cy.product = py.product
AND cy.year=2011
AND py.year=2010
AND cy.prod_quantity < py.prod_quantity;
In informatica, you can specify only equal to condition in joiner. Now we will see how to implement this problem
using informatica.
Solution:
STEP1: Connect two source qualifier transformations to the source definition. Call the first source qualifier
transformation as sq_cy (cy means current year) and the other as sq_py (py means previous year).
STEP2: In the sq_cy source qualifier transformation, specify the source filter as price=2011. In the sq_py, specify the
source filter as price=2010
STEP3: Now connect these two source qualifier transformations to joiner transformation and make sq_cy as master,
sq_py as detail. In the join condition, select the product port from master and detail.
STEP4: Now connect all the master ports and only the prod_quantity port from detail to the filter transformation. In
the filter transformation specify the filter condition as prod_quantity < prod_quantity1. Here pord_quantity port is
from master port and prod_quantity1 is from detail port.
STEP4: Connect all the ports except the prod_quantity1 of filter transformation to the target definition.
2. How to implement the not exists operator in informatica which is available in database?
Solution:
Implementing the Not Exists operator is very easy in informatica. For example, we want to get only the records which
are available in table A and not in table B. For this use a joiner transformation with A as master and B as detail.
Specify the join condition and in the join type, select detail outer join. This will get all the records from A table and
only the matching records from B table.
Connect the joiner to a filter transformation and specify the filter condition as B_port is NULL. This will give the
records which are in A and not in B. Then connect the filter to the target definition.
Id
1
2
3
4
5
6
7
8
....
1000
Create a workflow to load only the Fibonacci numbers in the target table. The target table data should look like as
Id
1
2
3
5
8
13
.....
In Fibonacci series each subsequent number is the sum of previous two numbers. Here assume that the first two
numbers of the fibonacci series are 1 and 2.
Solution:
STEP1: Drag the source to the mapping designer and then in the Source Qualifier Transformation properties, set the
number of sorted ports to one. This will sort the source data in ascending order. So that we will get the numbers in
sequence as 1, 2, 3, ....1000
STEP2: Connect the Source Qualifier Transformation to the Expression Transformation. In the Expression
Transformation, create three variable ports and one output port. Assign the expressions to the ports as shown below.
STEP3: Now connect the Expression Transformation to the Filter Transformation and specify the Filter Condition as
o_flag=1
Q2. The source table contains two columns "id" and "val". The source data looks like as below
id val
1 a,b,c
2 pq,m,n
3 asz,ro,liqt
Here the "val" column contains comma delimited data and has three fields in that column.
Create a workflow to split the fields in val column to separate rows. The output should look like as below.
id val
1 a
1 b
1 c
2 pq
2 m
2 n
3 asz
3 ro
3 liqt
Solution:
STEP2: Now connect all the three Source Qualifier transformations to the Union Transformation. Then connect the
Union Transformation to the Sorter Transformation. In the sorter transformation sort the data based on Id port in
ascending order.
STEP3: Pass the output of Sorter Transformation to the Expression Transformation. The ports in Expression
Transformation are:
id (input/output port)
val (input port)
v_currend_id (variable port) = id
v_count (variable port) = IIF(v_current_id!=v_previous_id,1,v_count+1)
v_previous_id (variable port) = id
o_val (output port) = DECODE(v_count, 1,
SUBSTR(val, 1, INSTR(val,',',1,1)-1 ),
2,
SUBSTR(val, INSTR(val,',',1,1)+1, INSTR(val,',',1,2)-INSTR(val,',',1,1)-1),
3,
SUBSTR(val, INSTR(val,',',1,2)+1),
NULL
)
STEP4: Now pass the output of Expression Transformation to the Target definition. Connect id, o_val ports of
Expression Transformation to the id, val ports of Target Definition.
For those who are interested to solve this problem in oracle sql, oracle sql query provides a dynamic solution where
the "val" column can have varying number of fields in each row.
12. What are the basic requirements to join two sources in a source qualifier transformation using default join?
The two sources should have primary key and foreign key relationship.
The two sources should have matching data types.
Informatica Interview Questions - Part 2
1. What are the differences between joiner transformation and source qualifier transformation?
A joiner transformation can join heterogeneous data sources where as a source qualifier can join only homogeneous
sources. Source qualifier transformation can join data from only relational sources but cannot join flat files.
Lookup transformation is used to lookup data in a relational table, view and synonym. Informatica server queries the
look up table based on the lookup ports in the transformation. It compares the lookup transformation port values to
lookup table column values based on the look up condition.
Persistent cache: You can save the lookup cache files and reuse them the next time the informatica server
processes a lookup transformation configured to use the cache.
Re-cache from database: If the persistent cache is not synchronized with the lookup table, you can configure
the lookup transformation to rebuild the lookup cache.
Static cache: you can configure a static or read only cache for only lookup table. By default informatica server
creates a static cache. It caches the lookup table and lookup values in the cache for each row that comes into the
transformation. When the lookup condition is true, the informatica server does not update the cache while it processes
the lookup transformation.
Dynamic cache: If you want to cache the target table and insert new rows into cache and the target, you can
create a look up transformation to use dynamic cache. The informatica server dynamically inserts data to the target
table.
Shared cache: You can share the lookup cache between multiple transactions. You can share unnamed cache
between transformations in the same mapping.
11. Which transformation should we use to normalize the COBOL and relational sources?
Normalizer Transformation is used to normalize the data.
13. How the informatica server sorts the string values in Rank transformation?
When the informatica server runs in the ASCII data movement mode it sorts session data using Binary sort order. If
you configure the session to use a binary sort order, the informatica server calculates the binary value of each string
and returns the specified number of rows with the highest binary values for the string.
Input group
Output group
The output group contains two types. They are
User defined groups
Default group
18. What are the types of data that passes between informatica server and stored procedure?
Three types of data passes between the informatica server and stored procedure.
Input/Output parameters
Return Values
Status code.
Source name
Database location
Column names
Data types
Key constraints
2. How many ways a relational source definition can be updated and what are they?
There are two ways to update the relational source definition:
4. To provide support for Mainframes source data, which files are used as a source definitions?
COBOL files
5. Which transformation is needed while using the cobol sources as source definitions?
As cobol sources consists of denormalized data, normalizer transformation is required to normalize the data.
7. What is a mapplet?
A mapplet is a set of transformations that you build in the mapplet designer and can be used in multiple mappings.
8. What is a transformation?
It is a repository object that generates, modifies or passes data.
Two methods:
18. Can we use the mapping parameters or variables created in one mapping into any other reusable transformation?
Yes. As an instance of the reusable transformation created in the mapping belongs to that mapping only.
Here in this table, column C1 is parent of column C2, column C2 is parent of column C3, column C3 is parent of
column C4.
Q1. Design a mapping to load the target table with the below data. Here you need to generate sequence numbers for
each element and then you have to get the parent id. As the element "A" is at root, it does not have any parent and its
parent_id is NULL.
Q2. This is an extension to the problem Q1. Let say column C2 has null for all the rows, then C1 becomes the parent
of C3 and c3 is parent of C4. Let say both columns c2 and c3 has null for all the rows. Then c1 becomes the parent of
c4. Design a mapping to accommodate these type of null conditions.
Aggregator Active/Connected
Expression Passive/Connected
Filter Active/Connected
Joiner Active/Connected
Normalizer Active/Connected
Rank Active/Connected
Router Active/Connected
Sorter Active/Connected
Union Active/Connected
1. What is a transformation?
12. Which transformation can be created only as reusable transformation but not as non-reusable transformation?
External procedure transformation.
Informatica Interview Questions on Union Transformation
1. What is a union transformation?
A union transformation is used merge data from multiple sources similar to the UNION ALL SQL statement to
combine the results from two or more SQL statements.
2. As union transformation gives UNION ALL output, how you will get the UNION output?
Pass the output of union transformation to a sorter transformation. In the properties of sorter transformation check the
option select distinct. Alternatively you can pass the output of union transformation to aggregator transformation and
in the aggregator transformation specify all ports as group by ports.
The following rules and guidelines need to be taken care while working with union transformation:
You can create multiple input groups, but only one output group.
All input groups and the output group must have matching ports. The precision, datatype, and scale must be
identical across all groups.
The Union transformation does not remove duplicate rows. To remove duplicate rows, you must add another
transformation such as a Router or Filter transformation.
You cannot use a Sequence Generator or Update Strategy transformation upstream from a Union
transformation.
The Union transformation does not generate transactions.
4. Why union transformation is an active transformation?
Union is an active transformation because it combines two or more data streams into one. Though the total number of
rows passing into the Union is the same as the total number of rows passing out of it, and the sequence of rows from
any given input stream is preserved in the output, the positions of the rows are not preserved, i.e. row number 1 from
input stream 1 might not be row number 1 in the output stream. Union does not even guarantee that the output is
repeatable
A transaction is a set of rows bound by a commit or rollback of rows. The transaction control transformation is used to
commit or rollback a group of rows.
2. What is the commit type if you have a transaction control transformation in the mapping?
3. What are the different transaction levels available in transaction control transformation?
The following are the transaction levels or built-in variables:
TC_CONTINUE_TRANSACTION: The Integration Service does not perform any transaction change for this
row. This is the default value of the expression.
TC_COMMIT_BEFORE: The Integration Service commits the transaction, begins a new transaction, and
writes the current row to the target. The current row is in the new transaction.
TC_COMMIT_AFTER: The Integration Service writes the current row to the target, commits the transaction,
and begins a new transaction. The current row is in the committed transaction.
TC_ROLLBACK_BEFORE: The Integration Service rolls back the current transaction, begins a new
transaction, and writes the current row to the target. The current row is in the new transaction.
TC_ROLLBACK_AFTER: The Integration Service writes the current row to the target, rolls back the
transaction, and begins a new transaction. The current row is in the rolled back transaction.
Recommended Posts:
Sorter transformation is used to sort the data. You can sort the data either in ascending or descending order according
to a specified sort key.
As sorter transformation can suppress the duplicate records in the source, it is called an active transformation.
Sort the data using sorter transformation before passing in to aggregator or joiner transformation. As the data is sorted,
the integration service uses the memory to do aggregate and join operations and does not use cache files to process the
data.
Employee_id, Salary
-------------------
10, 1000
20, 2000
30, 3000
40, 5000
Q1. Design a mapping to load the cumulative sum of salaries of employees into target table?
The target table data should look like as
-----------------------------------
Q2. Design a mapping to get the pervious row salary for the current row. If there is no pervious row exists for the
current row, then the pervious row salary should be displayed as null.
The output should look like as
Department_no, Employee_name
----------------------------
20, R
10, A
10, D
20, P
10, B
10, C
20, Q
20, S
Q1. Design a mapping to load a target table with the following values from the above source?
Department_no, Employee_list
----------------------------
10, A
10, A,B
10, A,B,C
10, A,B,C,D
20, A,B,C,D,P
20, A,B,C,D,P,Q
20, A,B,C,D,P,Q,R
20, A,B,C,D,P,Q,R,S
Q2. Design a mapping to load a target table with the following values from the above source?
Department_no, Employee_list
----------------------------
10, A
10, A,B
10, A,B,C
10, A,B,C,D
20, P
20, P,Q
20, P,Q,R
20, P,Q,R,S
Product_id, product_type
10, video
10, Audio
20, Audio
30, Audio
40, Audio
50, Audio
10, Movie
20, Movie
30, Movie
40, Movie
50, Movie
60, Movie
Assume that there are only 3 product types are available in the source. The source contains 12 records and you dont
know how many products are available in each product type.
Q1. Design a mapping to select 9 products in such a way that 3 products should be selected from video, 3 products
should be selected from Audio and the remaining 3 products should be selected from Movie.
Solution:
Step1: Use sorter transformation and sort the data using the key as product_type.
Step2: Connect the sorter transformation to an expression transformation. In the expression transformation, the ports
will be
product_id
product_type
V_curr_prod_type=product_type
V_count = IIF(V_curr_prod_type = V_prev_prod_type,V_count+1,1)
V_prev_prod_type=product_type
O_count=V_count
Step3: Now connect the expression transformaion to a filter transformation and specify the filter condition as
O_count<=3. Pass the output of filter to a target table.
Q2. In the above problem Q1, if the number of products in a particular product type are less than 3, then you wont get
the total 9 records in the target table. For example, see the videos type in the source data. Now design a mapping in
such way that even if the number of products in a particular product type are less than 3, then you have to get those
less number of records from another porduc types. For example: If the number of products in videos are 1, then the
reamaining 2 records should come from audios or movies. So, the total number of records in the target table should
always be 9.
Solution:
Step3: Connect the expression transformation to a sorter transformation and sort the data using the key as O_count.
The ports in soter transformation will be
product_id
product_type
O_count (sort key)
Step3: Discard O_count port and connect the sorter transformation to an expression transformation. The ports in
expression transformation will be
product_id
product_type
V_count=V_count+1
O_prod_count=V_count
Step4: Connect the expression to a filter transformation and specify the filter condition as O_prod_count<=9. Connect
the filter transformation to a target table.
2. Design a mapping to convert column data into row data without using the normalizer transformation.
The source data looks like
Solution:
Create three expression transformations with one port each. Connect col1 from Source Qualifier to port in first
expression transformation. Connect col2 from Source Qualifier to port in second expression transformation. Connect
col3 from source qualifier to port in third expression transformation. Create a union transformation with three input
groups and each input group should have one port. Now connect the expression transformations to the input groups
and connect the union transformation to the target table.
id, value
10, a
10, b
10, c
20, d
20, e
20, f
Solution:
Step1: Use sorter transformation and sort the data using id port as the key. Then connect the sorter transformation to
the expression transformation.
Step2: In the expression transformation, create the ports and assign the expressions as mentioned below.
id
value
V_curr_id=id
V_count= IIF(v_curr_id=V_prev_id,V_count+1,1)
V_prev_id=id
O_col1= IIF(V_count=1,value,NULL)
O_col2= IIF(V_count=2,value,NULL)
O_col3= IIF(V_count=3,value,NULL)
Step3: Connect the expression transformation to aggregator transformation. In the aggregator transforamtion, create
the ports and assign the expressions as mentioned below.
id (specify group by on this port)
O_col1
O_col2
O_col3
col1=MAX(O_col1)
col2=MAX(O_col2)
col3=MAX(O_col3)
Stpe4: Now connect the ports id, col1, col2, col3 from aggregator transformation to the target table.