Csc 1302, Honors Principles of Computer Science II (Fall 2023)
Project Operator
During this week you will write the following methods:- (Tuple.py):
## This method takes as input a list of column names, each of which ## belonging to self.attributes, and returns a new tuple with only those ## components that correspond to the column names in cnames. def project(self,cnames): Create a list, doms, with domains values for column names in cnames Create a new Tuple object, tup for each column name in cnames: add corresponding component of self.tuple to tup return tup
- (Relation.py) Project Operator:
## This methods takes as input a list of column names, each of which ## belonging to self.attributes, and returns a relation whose tuples are ## formed by projecting the columns from cnames. ## Example: R(A:INTEGER, B:INTEGER, C:DECIMAL) with tuples ## {(10,20,3.5),(11,22,7.8),(10,25,3.5)} ## Then, with cnames = ["A","C"], the output relation should ## have schema (A:INTEGER, C:DECIMAL) and tuples ## {(10,3.5),(11,7.8)} ## Note that after projection one may get duplicate tuples, which should ## be removed. def project(self,cnames): Create new attrs and doms from cnames and self.domains Create a new Relation object, rel for each tuple in self.table: call the project() method of Tuple class and get a new tuple add the new tuple to rel Remove duplicates from rel return rel
Download the Driver Program and implement all the methods in this assignment. Compile and run the driver programs. You should see the following output when you run Driver.py:
CSs-MBP-2:week6 raj$ python3 Driver.py STUDENT(SID:INTEGER,SNAME:VARCHAR,PHONE:INTEGER,MAJOR:VARCHAR,GPA:DECIMAL) Number of tuples:4 1111:Robert Adams:1234:Computer Science:4.0: 1112:Charles Bailey:5656:Computer Science:3.5: 1113:David Beatle:1212:Mathematics:3.5: 1114:Graham Gooch:5678:Computer Science:3.5: PROJECT_SID_GPA_STUDENT(SID:INTEGER,GPA:DECIMAL) Number of tuples:4 1111:4.0: 1112:3.5: 1113:3.5: 1114:3.5: PROJECT_MAJOR_GPA_STUDENT(MAJOR:VARCHAR,GPA:DECIMAL) Number of tuples:3 Computer Science:4.0: Computer Science:3.5: Mathematics:3.5: PROJECT_MAJOR_STUDENT(MAJOR:VARCHAR) Number of tuples:2 Computer Science: Mathematics: CSs-MBP-2:week6 raj$