Hello Connections,
🔍 Exploring Ab Initio's Vector Concepts: Join me for a dive into key interview questions! Perfect for data enthusiasts and professionals alike.
Let's decode together! #AbInitio #DataEngineering #InterviewPrep"
Interview Question 3 :
You have Two cities given with their distances.Your task is to remove the duplicates cities with same distances .
I have used below vector approach to solve the problem.
Input File
City1 City2 Distance
Pune Mumbai 200
Bangalore Pune 800
Mumbai Pune 200
Pune Bangalore 800
Pune Hyderabad 560
Hyderabad Pune 560
Output:
Mumbai Pune 200
Bangalore Pune 800
Hyderabad Pune 560
Solution:
InputFile(use proper DML) --> Reformat(Refer Below code) --> Sort(Key:{City1,City2}) --> DedupSort(Key:{City1,City2}) --> OutputFile
out :: reformat(in) = begin
let string("")[big endian integer(4)]vec1= allocate_with_defaults();
let string("")[big endian integer(4)]vec2= allocate_with_defaults();
let string("")[big endian integer(4)]vec3= allocate_with_defaults();
vec1=[ vector in.City1 ];
vec2=[vector in.City2 ];
vec3=vector_sort_dedup_first(vector_sort(vector_append(vec1,string_join(vec2,""))));
out.City1::vec3[0];
out.City2::vec3[1];
out.Distance :: in.Distance;
end;
Please comment for any inputs/suggestions