Ticker

6/recent/ticker-posts

Header Ads Widget

Responsive Advertisement

QUERY ENGINE


Implement operations similar to database operations in your favourite language. Think of these operations as operations that we use in SQL (Structured Query Language) that we run on databases. These operations will be implemented on files which can be treated as database tables. These files will consist of comma-separated values which can be considered as different columns in the table. A newline character in the file can be treated as a record delimiter.

Given the above background, write a program to implement the following operations viz. Join on two tables, Sort by, limit and result printing. Consider the following database schema to understand the problem better. Consider 2 tables 

CollegeMaster - 

UserMaster -

Constraints:

1.     collegeid is the primary key of CollegeMaster table

2.     userid is the primary key of UserMaster table

3.     collegeid in UserMaster is the foreign key to collegeid in CollegeMaster

4.     ctreference,email and username satisfies unique key constraint on UserMaster table

5.     Query on search attribute in UserMaster will always have Select clause comprising of columns in CollegeMaster and vice-versa.

6.     CollegeId need not be printed in either case since that is the only column on which 2 tables can be joined.

Your program should implement a SQL query, say for example like

Select userid, username, email, ctreference from usermaster, collegemaster where usermaster.collegeid = collegemaster.collegeid and usermaster.collegeid=1 sort by userid limit 0, 5;
OR
Select collegename, cityid, stateid from collegemaster, usermaster where collegemaster.collegeid =usermaster.collegeid and usermaster.userid=1;

Input Format:

Input will consists 5 items as described below.

Line 1

Absolute path to CollegeMaster file

Line 2

Absolute path to UserMaster file

Line 3

Either C or U, where C represents, search field is in CollegeMaster and 
U represents, search field is in UserMaster.

Line 4

Name of the search attribute

Line 5

Value of the search attribute

File Format
CollegeMaster File Master
Column 1 – CollegeId
Column 2 – CollegeName
Column 3 – CityId
Column 4 – StateId

Columns are separated by “,” 
UserMaster File Format
Column 1 – UserId
Column 2 – UserName
Column 3 – Email
Column 4 – CTReference
Column 5 – CollegeId

Columns are separated by “,”

Output:

Output of the program will be the filtered records that are returned as a result of a query. Records should be sorted by userid when printing query results where applicable. Maximum number of records to be printed is 5.

Example Output with query on Collegename:

1,Sachin Tendulkar,user1@gmail.com,CT20120000001
2,M S Dhoni,user2@gmail.com,CT20120000002
3,Virender Sehwag,user3@gmail.com,CT20120000003
6,Zaheer Khan,user4@gmail.com,CT20120000004
31,Ishant Sharma,user5@yahoo.com,CT20120000005

Example Output with query on CTReference: 

Kirti College, 1, 1

Note:
This is a sample data file only. Actual data file may contain more / less data, but is guaranteed to adhere to this format.


Sample Input and Output:

SNo

Input

Output

1

Collegemaster.csv
Usermaster.csv
C
CollegeName
Kirti College

1,Sachin Tendulkar,user1@gmail.com,CT20120000001
2,M S Dhoni,user2@gmail.com,CT20120000002
3,Virender Sehwag,user3@gmail.com,CT20120000003
6,Zaheer Khan,user4@gmail.com,CT20120000004
31,Ishant Sharma,user5@yahoo.com,CT20120000005

2

Collegemaster.csv
Usermaster.csv
U
CTReference
CT20120000001

Kirti College, 1, 1

3

Collegemaster.csv
Usermaster.csv
@
4

Invalid Input

4

Collegemaster.csv
Usermaster.csv
U
CTReference
CT20120000007

Data unavailable

 


Post a Comment

0 Comments