Abinitio Interview Scenarios
Abinitio Interview Scenarios
rownum n rowid
view n materialized view
delete drop n truncate
hld
project
Interview Scenarios:
i/p
city1 city2 dist
hyd bng 400
bng hyd 400
chn hyd 200
hyd chn 200
ind dewas 400
dewas ind 400
bng hyd
bng hyd
chn hyd
chn hyd
dewas ind
dewas ind
string_compare("aaaa","bbb")-->-1
string_compare("ddddd","bbb")-->1
in this file
bng hyd
bng hyd
chn hyd
chn hyd
dewas ind
dewas ind
5 to 8
5, 7
=============================
i/p
depid gender
IT M
IT F
IT F
CS M
CS F
o/p
deptid male_count female_count
IT 1 2
CS 1 1
sel dept_id,(sel count(*) from emp e group by gender having gender='M' and
e.dept_id=em.dept_id) as male_count,
(sel count(*) from emp e group by gender having gender='F' and e.dept_id=em.dept_id
) as male_count,
from emp em
group by dept_id
=========================================
scan
int (4) rank=0;
scan=
if(tmp.sal==in.sal) rank else rank+1;
rank=rank+1;
============================
city_distance:
//Insert the two cities in to a vector example first set hyd bng and sort
city_vec = (ity_vec , in.city1);
city_vec = vector_append(city_vec , in.city2);
sorted_city_vec = vector_sort(city_vec);
out.* :: in.* ;
out.city1 :: sorted_city_vec[0];
out.city2 :: sorted_city_vec[1];
===============
city_distance:
sorted_city_vec = vector_sort(city_vec);
out.* :: in.* ;
out.city1 :: sorted_city_vec[0];
out.city2 :: sorted_city_vec[1];
================
string_rev:
out::reverse_opt(f_str)=
begin
let string(1)[] str_vec = reinterpret(f_str);
let int len = length_of(str_vec);
let string(1)[] rev_str_vec = allocate();
while(len > 0)
begin
len=len-1;
rev_str_vec = vector_append(rev_str_vec,str_vec[len]);
end
out :: string_join(rev_str_vec,"");
end;
==================
ROLLUP
---
//As long as the key_change function returns 0 all records are considered in same
group. When the key change function returns 1 a new group starts.
out :: key_change(in1,in2)=
begin
out :: if (in2.balls % 6 == 1) 1 else 0;
end;
temporary variables
---
decimal("x01") total_runs_over;
Initialize
---
temp.total_runs_over :: 0;
Rollup
---
==============
I/p
+---+------------+------+
| V | Balls | Run |
+---+------------+------+
| a | 1 | 1 |
| a | 2 | 2 |
| a | 3 | 6 |
| b | 4 | 4 |
| c | 5 | 5 |
| c | 6 | 5 |
| d | 7 | 7 |
| e | 8 | 4 |
+---+------------+------+
o/p
+----+---+
|Over|Run|
+----+---+
| 1 | 23|
| 2 | 11|
==================
temp.total_runs_over :: temp.total_runs_over + in.runs;
Finalize
---
over= over + 1;
out.* :: in.* ;
out.over_count :: over;
==============
+---+------------+------+------------+
| V | ROW_NUMBER | RANK | DENSE_RANK |
+---+------------+------+------------+
| a | 1 | 1 | 1 |
| a | 2 | 1 | 1 |
| a | 3 | 1 | 1 |
| b | 4 | 4 | 2 |
| c | 5 | 5 | 3 |
| c | 6 | 5 | 3 |
| d | 7 | 7 | 4 |
| e | 8 | 8 | 5 |
+---+------------+------+------------+
============
Employees working in single department.
i/p:
employee dept
ganga cmp
rama phy
siva che
ganga phy
siva bio
o/p:
employee dept
rama phy
i want o/p:
AB
CD
ABCDEF
A
AB
ABCD
ABCDE
ABCDEF
================
hyd dyh
john nh0j
rohan nah0r
=====================
employee
empid did sal
101 1 2000
102 1 3000
103 2 4000
104 2 5000
105 2 6000
106 1 7000
==============
Select eldest male and female:
I/P
ID gender age
101 M 20
201 F 60
301 F 30
401 M 40
501 F 50
601 F 20
701 F 80
O/p
701 F 80
401 M 40
=====================
==========================
Reformate :
count: 2
sel:
transform0
transform1
output_index-> return int
output_index-> vector
out :: output_index(in)=
begin
out :: if(in.country=='IND') 0 else 1;
end;
count 2
out :: output_indexs(in)=
begin
out :: if(in.country=='IND') [vector 0,1] else [vector 1];
end;
===============
search for emp whose sal is less then avg
empid, ename, sal,dept_id
5000 1
6000 1
2000 1
============================
state|gender|population
A|M|1
A|M|1
A|M|3
A|F|4
D|M|3
D|F|7
D|F|2
state|population
A|Male count is 5 and female count is 4
D|Male count is 3 and female count is 9
=======================================
code|state
1,India
2,MAHA
3,AP
4,MP
1,Russia
2,moscow
3,siberia
1,China
2,beijing
o/p
4,India MAHA AP MP
3, Russia Moscow siberia
2,China beijing
==================================
i/p
101, Rini jaiswal, 3000
o/p
101, Rini, Jaiswal, 3000
or
first_name=string_split(full_name," ")[0];
last_name=string_split(full_name," ")[1];
===================================