Csc 1302, Honors Principles of Computer Science II (Fall 2023)

Select Operator

During this week you will write the following methods:
  1. (Tuple.py):
    # This method takes a comparison condition in the 5 parameters and
    # returns True if the tuple satisfies the condition and False otherwise.
    #
    # The comparison condition is coded in the 5 parameters as follows:
    #
    # lopType/ropType can take one of three values: "col", "num", "str"
    # indicating that the operand is either a name of a column, or a number,
    # or a string respectively.
    #
    # lopValue/ropValue will contain the name of the column if the lopType/ropType
    # is "col" and will contain a numeric value if lopType/ropType is "num" and
    # will contain a string value if lopType/ropType is "str".
    #
    # comparison will have one of six values: "<", "<=","=",">",">=", or "<>"
    #
    # As an example, if we want to express the comparison, SNAME = "Jones", the 5 parameters will be:
    # lopType="col", lopValue="SNAME", comparison="=", ropType="str", ropValue="Jones"
    #
    # As another example, if we want to express the condition GPA > 3.0, the 5 parameters will be:
    # lopType="col", lopValue="GPA", comparison=">", ropType="num", ropValue="3.0"
    #
    def select(self,lopType,lopValue,comparison,ropType,ropValue):
      # Top level cases to consider:
      #
      # lopType="num" and ropType="num"
      # lopType="str" and ropType="str"
      # lopType="col" and ropType="num"
      # lopType="col" and ropType="str"
      # lopType="num" and ropType="col"
      # lopType="str" and ropType="col"
      # lopType="col" and ropType="col"
    	pass
    
  2. (Relation.py) Select Operator:
    # This method takes as input a comparison condition as explained earlier and returns
    # a new relation that contains only those tuples that satisfies the comparison condition.
    def select(self,lopType,lopValue,comparison,ropType,ropValue):
    	pass
    

Download the Driver Programs 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:

Mac-mini:week7-select 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:

SELECT_SID_=_1114(SID:INTEGER,SNAME:VARCHAR,PHONE:INTEGER,MAJOR:VARCHAR,GPA:DECIMAL)
Number of tuples:1

1114:Graham Gooch:5678:Computer Science:3.5:

SELECT_GPA_>_3.5(SID:INTEGER,SNAME:VARCHAR,PHONE:INTEGER,MAJOR:VARCHAR,GPA:DECIMAL)
Number of tuples:1

1111:Robert Adams:1234:Computer Science:4.0:

SELECT_MAJOR_=_Computer Science(SID:INTEGER,SNAME:VARCHAR,PHONE:INTEGER,MAJOR:VARCHAR,GPA:DECIMAL)
Number of tuples:3

1111:Robert Adams:1234:Computer Science:4.0:
1112:Charles Bailey:5656:Computer Science:3.5:
1114:Graham Gooch:5678:Computer Science:3.5:

Mac-mini:week7-select raj$