0% found this document useful (0 votes)
52 views8 pages

Abinitio Interview Scenarios

Uploaded by

Pavan Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views8 pages

Abinitio Interview Scenarios

Uploaded by

Pavan Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

diff bet

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

o/p bng hyd 400


chn hyd 200
dewas ind 400

city1 city2 dist


hyd bng 400
bng hyd 400
chn hyd 200
hyd chn 200
dewas ind 400

bng hyd
bng hyd
chn hyd
chn hyd
dewas ind
dewas ind

sed -n 5,7p emp


awk -f ',' '{print $5,$7}' emp

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;

============================

how to print top 10 min sal

city_distance:

let string("x01")[integer(4)] city_vec = allocate();


let string("x01")[integer(4)] sorted_city_vec = allocate();

//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];

o/p-> bng hyd


then second value set go bng hyd and sort bng hyd
o/p bng hyd
chn hyd
chn hyd

now do dedup on this key

===============
city_distance:

let string("x01")[integer(4)] city_vec = allocate();


let string("x01")[integer(4)] sorted_city_vec = allocate();

//Insert the two cities in to a vector


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];
================
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
---

Key change function


---

//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.

let decimal("x01") over = 0;

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

dedup with unique;


rollup with count==1;
i/p--> -->o/p
==========
i/p:
a/c no, transactions ,datetime
1001 50000, 2023-04-03 12:30:12
1002 50000, 2023-01-03 12:30:12
1001 50000, 2023-04-03 12:30:12
1002 50000, 2023-01-03 12:30:12
1003 50000, 2023-02-03 12:30:12
1001 50000, 2023-03-03 12:30:12

i want o/p:

heighst transactions made on jan.


===================
A
B
C
D

AB
CD

ABCDEF

A
AB
ABCD
ABCDE
ABCDEF

================
hyd dyh
john nh0j
rohan nah0r
=====================

did dname sal


1
1
2
2
2
2

employee
empid did sal
101 1 2000
102 1 3000
103 2 4000
104 2 5000
105 2 6000
106 1 7000

i need second highest sal dept wise

==============
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

i/p--> ROLLUP -->o/p


key-gender max(age)
=======================

=====================

eid sal rank dense_rank


1 60000 1 1
2 60000 1 1
3 50000 3 2
4 40000 4 3
5 40000 4 3
6 40000 4 3
7 30000 7 4

dense_rank()(over sal desc) as drank

Abinit: dept wise second highest sal


did sal
1 80000
1 60000
1 50000
1 40000
2 30000
2 20000
2 10000

==========================

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

empid, ename, sal,dept_id sal_status


5000 1 equals than avg
6000 1 greater than avg
4000 1 less than avg
======================================================
col
A
AB
ABC
ABCD

city opposite names


BNG GNB
HYD DYH

============================
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

split fullname to first name and last name


full_name= Rini Jaiswal
first_name=string_substring(full_name,1,string_index(full_name," ")-1)
last_name=string_substring(full_name,string_index(full_name," ")
+1,string_length(full_name))

or
first_name=string_split(full_name," ")[0];
last_name=string_split(full_name," ")[1];
===================================

You might also like