Académique Documents
Professionnel Documents
Culture Documents
developer.
10. How do you promote a non-reusable
transformation to reusable transformation?
Edit the transformation and check the Make
Reusable option
11. How to create a non-reusable instance of
reusable transformations?
In the navigator, select an existing
transformation and drag the transformation into
the mapping workspace. Hold down the Ctrl key
before you release the transformation.
12. Which transformation can be created only as
reusable transformation but not as non-reusable
transformation?
External procedure transformation.
INFORMATICA INTERVIEW QUESTIONS ON
AGGREGATOR TRANSFORMATION
1. What is aggregator transformation?
Aggregator transformation performs aggregate
calculations like sum, average, count etc. It is an
active transformation, changes the number of
rows in the pipeline. Unlike expression
transformation (performs calculations on a rowby-row basis), an aggregator transformation
performs calculations on group of rows.
2. What is aggregate cache?
The integration service creates index and data
cache in memory to process the aggregator
transformation and stores the data group in
index cache, row data in data cache. If the
integration service requires more space, it stores
the overflow values in cache files.
3. How can we improve performance of
aggregate transformation?
Salary
1000
2000
3000
5000
Employee_list
A
A,B
A,B,C
A,B,C,D
A,B,C,D,P
A,B,C,D,P,Q
A,B,C,D,P,Q,R
A,B,C,D,P,Q,R,S
Employee_list
A
A,B
A,B,C
A,B,C,D
P
P,Q
P,Q,R
P,Q,R,S
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
Solution:
Step1: Use a sorter transformation and sort the
data using the sort key as department_no and
then pass the output to the expression
transformation. In the expression transformation,
the ports will be
department_no
employee_name
V_employee_list =
IIF(ISNULL(V_employee_list),employee_name,
V_employee_list||','||employee_name)
O_employee_list = V_employee_list
Type of join
Join condition
Get a related value: Retrieve a value
from the lookup table based on a value in the
source.
Pipeline lookup
Insert Else Update option applies to
rows entering the lookup transformation with the
row type of insert. When this option is enabled
the integration service inserts new rows in the
cache and updates existing rows when disabled,
the Integration Service does not update existing
rows.
Persistent cache
Static cache
Dynamic cache
Shared Cache
first
Input
Output
User-defined group
Default group
5. Where you specify the filter conditions in the
router transformation?
You can creat the group filter conditions in the
groups tab using the expression editor.
6. Can you connect ports of two output groups
from router transformation to a single target?
No. You cannot connect more than one output
group to one target or a single input group
transformation.
Start Value
Increment By
End Value
Current Value
Cycle
Select Distinct
Pre-SQL
Post-SQL
SQL Query
User-Defined Join
Source Filter
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_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.
INFORMATICA INTERVIEW QUESTIONS ON
UNION TRANSFORMATION
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 ouput of joiner
transformation to filter transformation and
specify the filter condition as O_total_records
(port from aggregator)-O_count(port from
expression) <=2
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 aggreagtor, 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
c
d
e
f
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.
product_id
product_type
O_count (sort key)
id, value
10, a
10, b
10, c
20, d
20, e
20, f
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.
id
value
V_curr_id=id
V_count= IIF(v_curr_id=V_prev_id,V_count+1,1)
V_prev_id=id
Col
a
b
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.
INFORMATICA SCENARIO BASED
QUESTIONS - PART 4
Take a look at the following tree structure
diagram. From the tree structure, you can easily
derive the parent-child relationship between the
elements. For example, B is parent of D and E.
c2,
B,
B,
B,
C,
C,
c3,
D,
D,
E,
F,
G,
c4
H
I
NULL
NULL
NULL
INNER JOIN
T2 C
ON
(T3.CHILD = C.PARENT)
LEFT OUTER JOIN
T2 P
ON (T3.PARENT = P.PARENT)
ORDER BY C.SEQ;
Note: The unpivot function works in oracle 11g.
val
a,b,c
pq,m,n
asz,ro,liqt
val
a
b
c
pq
m
n
asz
ro
liqt
Solution:
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, Click Here. The oracle sql
query provides a dynamic solution where the
"val" column can have varying number of fields
in each row.
16
25
0
15
10
0
18
20
0
Solution:
LG is the only product which does not have
sales at all. This can be achieved in three ways.
Method1: Using left outer join.
SELECT P.PRODUCT_NAME
FROM
PRODUCTS P
LEFT OUTER JOIN
SALES S
ON
(P.PRODUCT_ID =
S.PRODUCT_ID);
WHERE S.QUANTITY IS NULL
PRODUCT_NAME
LG
Method2: Using the NOT IN operator.
SELECT P.PRODUCT_NAME
FROM
PRODUCTS P
WHERE P.PRODUCT_ID NOT IN
(SELECT DISTINCT PRODUCT_ID
FROM SALES);
PRODUCT_NAME
LG
Method3: Using the NOT EXISTS operator.
SELECT P.PRODUCT_NAME
FROM
PRODUCTS P
WHERE NOT EXISTS
(SELECT 1 FROM SALES S WHERE
S.PRODUCT_ID = P.PRODUCT_ID);
PRODUCT_NAME
LG
SALES S_2011
WHERE P.PRODUCT_ID =
S_2012.PRODUCT_ID
AND
S_2012.YEAR = 2012
AND
S_2011.YEAR = 2011
AND
S_2012.PRODUCT_ID =
S_2011.PRODUCT_ID
AND
S_2012.QUANTITY <
S_2011.QUANTITY;
PRODUCT_NAME
Nokia
4. Write a query to select the top product sold in
each year?
PRODUCT_NAME TOTAL_SALES
LG
0
IPhone
405000
Samsung
406000
Nokia
245000
SQL QUERIES INTERVIEW QUESTIONS ORACLE PART 2
Solution:
Nokia is the top product sold in the year 2010.
Similarly, Samsung in 2011 and IPhone,
Samsung in 2012. The query for this is
SELECT PRODUCT_NAME,
YEAR
FROM
(
SELECT P.PRODUCT_NAME,
S.YEAR,
RANK() OVER (
PARTITION BY S.YEAR
ORDER BY S.QUANTITY
DESC
) RNK
FROM
PRODUCTS P,
SALES S
WHERE P.PRODUCT_ID = S.PRODUCT_ID
) A
WHERE RNK = 1;
PRODUCT_NAME
Nokia
Samsung
IPhone
Samsung
YEAR
2010
2011
2012
2012
YEAR QUANTITY
2010
25
2012
20
2012
20
Samsung
2010
20
WHERE (P.PRODUCT_ID =
S.PRODUCT_ID);
9000
9000
9000
Solution:
By using self-join SQL query we can get the
required result. The required SQL query is
SELECT S_I.YEAR,
S_I.QUANTITY IPHONE_QUANT,
S_S.QUANTITY SAM_QUANT,
S_I.PRICE
IPHONE_PRICE,
S_S.PRICE
SAM_PRICE
FROM
PRODUCTS P_I,
SALES S_I,
PRODUCTS P_S,
SALES S_S
WHERE P_I.PRODUCT_ID =
S_I.PRODUCT_ID
AND
P_S.PRODUCT_ID =
S_S.PRODUCT_ID
AND
P_I.PRODUCT_NAME = 'IPhone'
AND
P_S.PRODUCT_NAME = 'Samsung'
AND
S_I.YEAR = S_S.YEAR
3. Write a query to find the ratios of the sales of
a product?
Solution:
The ratio of a product is calculated as the total
sales price in a particular year divide by the total
sales price across all years. Oracle provides
RATIO_TO_REPORT analytical function for
finding the ratios. The SQL query is
SELECT P.PRODUCT_NAME,
S.YEAR,
RATIO_TO_REPORT(S.QUANTITY*S.PRICE)
OVER(PARTITION BY
P.PRODUCT_NAME ) SALES_RATIO
FROM
PRODUCTS P,
SALES S
PRODUCT_NAME
IPhone
IPhone
IPhone
Nokia
Nokia
Nokia
Samsung
Samsung
Samsung
YEAR
2011
2012
2010
2012
2011
2010
2010
2012
2011
RATIO
0.333333333
0.444444444
0.222222222
0.163265306
0.326530612
0.510204082
0.344827586
0.344827586
0.310344828
QUAN_2010 QUAN_2011
10
20
25
15
18
16
20
20
8
Solution:
Oracle 11g provides a pivot function to
transpose the row data into column data. The
SQL query for this is
SELECT * FROM
(
SELECT P.PRODUCT_NAME,
S.QUANTITY,
S.YEAR
FROM
PRODUCTS P,
SALES S
WHERE (P.PRODUCT_ID = S.PRODUCT_ID)
)A
PIVOT ( MAX(QUANTITY) AS QUAN FOR
(YEAR) IN (2010,2011,2012));
If you are not running oracle 11g database, then
use the below query for transposing the row
data into column data.
SELECT P.PRODUCT_NAME,
MAX(DECODE(S.YEAR,2010,
S.QUANTITY)) QUAN_2010,
MAX(DECODE(S.YEAR,2011,
S.QUANTITY)) QUAN_2011,
MAX(DECODE(S.YEAR,2012,
S.QUANTITY)) QUAN_2012
FROM
PRODUCTS P,
SALES S
WHERE (P.PRODUCT_ID = S.PRODUCT_ID)
GROUP BY P.PRODUCT_NAME;
5. Write a query to find the number of products
sold in each year?
Solution:
To get this result we have to group by on year
and the find the count. The SQL query for this
question is
SELECT YEAR,
COUNT(1) NUM_PRODUCTS
FROM
SALES
GROUP BY YEAR;
YEAR
2010
2011
2012
NUM_PRODUCTS
3
3
3
)
WHERE TO_CHAR(C_DATE,'DY') = 'FRI';
3. Write a query to duplicate each row based on
the value in the repeat column? The input table
data looks like as below
Products, Repeat
A,
3
B,
5
C,
2
Now in the output data, the product A should be
repeated 3 times, B should be repeated 5 times
and C should be repeated 2 times. The output
will look like as below
Products,
A,
A,
A,
B,
B,
B,
B,
B,
C,
C,
Repeat
3
3
3
5
5
5
5
5
2
2
Solution:
1. Write a query to generate sequence numbers
from 1 to the specified number N?
Solution:
SELECT LEVEL FROM DUAL CONNECT BY
LEVEL<=&N;
2. Write a query to display only friday dates from
Jan, 2000 to till now?
Solution:
SELECT
C_DATE,
TO_CHAR(C_DATE,'DY')
FROM
(
SELECT TO_DATE('01-JAN-2000','DDMON-YYYY')+LEVEL-1 C_DATE
FROM
DUAL
CONNECT BY LEVEL <=
(SYSDATE - TO_DATE('01-JAN2000','DD-MON-YYYY')+1)
SELECT PRODUCTS,
REPEAT FROM
T,
( SELECT LEVEL L FROM DUAL
CONNECT BY LEVEL <= (SELECT
MAX(REPEAT) FROM T)
) A
WHERE T.REPEAT >= A.L
ORDER BY T.PRODUCTS;
4. Write a query to display each letter of the
word "SMILE" in a separate row?
S
M
I
L
E
Solution:
SELECT SUBSTR('SMILE',LEVEL,1) A
FROM
DUAL
CONNECT BY LEVEL <=LENGTH('SMILE');
Name, Friend_of_Firend
sam,
ram
sam,
jhon
Solution1:
SELECT
SELECT SUBSTR(DUMP('SMILE'),15)
FROM DUAL;
Solution2:
SELECT WM_CONCAT(A)
FROM
(
SELECT
ASCII(SUBSTR('SMILE',LEVEL,1)) A
sam,
f1.name,
f2.friend_name as
friend_of_friend
FROM
friends f1,
friends f2
WHERE
f1.name = 'sam'
AND
f1.friend_name = f2.name;
2. This is an extension to the problem 1. In the
output, you can see ram is displayed as friends
of friends. This is because, ram is mutual friend
of sam and vamsi. Now extend the above query
to exclude mutual friends. The outuput should
look as
Name, Friend_of_Friend
sam,
jhon
sam,
vijay
sam,
anand
Solution:
);
SELECT
anand
Solution:
FROM
DUAL CONNECT BY LEVEL
<=LENGTH('SMILE')
vijaysam,
f1.name,
f2.friend_name as
friend_of_friend
FROM
friends f1,
friends f2
WHERE
f1.name = 'sam'
AND
f1.friend_name = f2.name
AND
NOT EXISTS
(SELECT 1 FROM friends f3
WHERE f3.name = f1.name
AND
f3.friend_name =
f2.friend_name);
3. Write a query to get the top 5 products based
on the quantity sold without using the
row_number analytical function? The source
data looks as
Products, quantity_sold, year
A,
200,
2009
B,
155,
2009
C,
455,
2009
D,
620,
2009
E,
F,
G,
H,
I,
J,
L,
M,
135,
390,
999,
810,
910,
109,
260,
580,
2009
2009
2010
2010
2010
2010
2010
2010
Solution:
SELECT
products,
quantity_sold,
year
FROM
(
SELECT
products,
quantity_sold,
year,
rownum r
from
t
ORDER BY quantity_sold DESC
)A
WHERE r <= 5;
4. This is an extension to the problem 3. Write a
query to produce the same output using
row_number analytical function?
Solution:
SELECT
products,
quantity_sold,
year
FROM
(
SELECT products,
quantity_sold,
year,
row_number() OVER(
ORDER BY quantity_sold
DESC) r
from
t
)A
WHERE r <= 5;
5. This is an extension to the problem 3. write a
query to get the top 5 products in each year
based on the quantity sold?
Solution:
SELECT
products,
quantity_sold,
year
FROM
(
SELECT products,
quantity_sold,
year,
row_number() OVER(
PARTITION BY year
ORDER BY
quantity_sold DESC) r
from
t
)A
WHERE r <= 5;
SQL QUERY INTERVIEW QUESTIONS - PART
5
Write SQL queries for the below interview
questions:
1. Load the below products table into the target
table.
CREATE TABLE PRODUCTS
(
PRODUCT_ID
INTEGER,
PRODUCT_NAME
VARCHAR2(30)
);
INSERT INTO PRODUCTS VALUES ( 100,
'Nokia');
INSERT INTO PRODUCTS VALUES ( 200,
'IPhone');
INSERT INTO PRODUCTS VALUES ( 300,
'Samsung');
INSERT INTO PRODUCTS VALUES ( 400,
'LG');
INSERT INTO PRODUCTS VALUES ( 500,
'BlackBerry');
INSERT INTO PRODUCTS VALUES ( 600,
'Motorola');
COMMIT;
SELECT * FROM PRODUCTS;
PRODUCT_ID PRODUCT_NAME
100
Nokia
200
IPhone
300
Samsung
400
LG
500
BlackBerry
600
Motorola
The requirements for loading the target table
are:
Target table should always contain the
products loaded in 30 days. It should not contain
the products which are loaded prior to 30 days.
Solution:
First we will create a target table. The target
table will have an additional column
INSERT_DATE to know when a product is
loaded into the target table. The target
table structure is
CREATE TABLE TGT_PRODUCTS
(
PRODUCT_ID
INTEGER,
PRODUCT_NAME
VARCHAR2(30),
INSERT_DATE
DATE
);
The next step is to pick 5 products randomly and
then load into target table. While selecting check
whether the products are there in the
INSERT INTO TGT_PRODUCTS
SELECT PRODUCT_ID,
PRODUCT_NAME,
SYSDATE INSERT_DATE
FROM
(
SELECT PRODUCT_ID,
PRODUCT_NAME
FROM PRODUCTS S
WHERE
NOT EXISTS (
SELECT 1
FROM
TGT_PRODUCTS T
WHERE T.PRODUCT_ID =
S.PRODUCT_ID
)
ORDER BY DBMS_RANDOM.VALUE --Random
number generator in oracle.
)A
WHERE ROWNUM <= 2;
The last step is to delete the products from the
table which are loaded 30 days back.
DELETE FROM TGT_PRODUCTS
WHERE INSERT_DATE < SYSDATE - 30;
CONTENT_TYPE VARCHAR2(30)
);
INSERT INTO CONTENTS VALUES
(1,'MOVIE');
INSERT INTO CONTENTS VALUES
(2,'MOVIE');
INSERT INTO CONTENTS VALUES
(3,'AUDIO');
INSERT INTO CONTENTS VALUES
(4,'AUDIO');
INSERT INTO CONTENTS VALUES
(5,'MAGAZINE');
INSERT INTO CONTENTS VALUES
(6,'MAGAZINE');
COMMIT;
SELECT * FROM CONTENTS;
CONTENT_ID CONTENT_TYPE
1
MOVIE
2
MOVIE
3
AUDIO
4
AUDIO
5
MAGAZINE
6
MAGAZINE
The requirements to load the target table are:
MOVIE
1
1
AUDIO
2
0
MAGAZINE
3
0
Here if LOAD_FLAG is 1, then it indicates which
content type needs to be loaded into the target
table. Only one content type will have
LOAD_FLAG as 1. The other content types will
have LOAD_FLAG as 0. The target table
structure is same as the source table structure.
The second step is to truncate the target table
before loading the data
TRUNCATE TABLE TGT_CONTENTS;