CS 631 Assignment 1


Due Date: Sunday 3 Sep 2006, 10 PM
Note 1: Assignment to be done in groups of 2.
Note 2: Submission online via moodle (more on moodle later)

Write the following functions in C/C++:

Assume records are stored in a file, one record per line, with each record consisting of 3 strings, each 10 characters in length.
Note: The attribute values in each record are separated by space. This also implies, no attribute can have two words separated by space. Find sample input files here. Please note that we would use 'diff' command to test the output. So, please be careful about the spaces.

Note: Declare the types Iterator and Record, used below as appropriate. You can assume that a record has at most 10 fields, and each field is a string of 10 characters. The structure Record should have an attribute numFields, containing the number of fields in the record, in addition to the actual fields.

1) Implement a file-scan iterator, with the functions:

      Iterator *openScan(char *filename, Record *rec) 
             /* rec is a Record structure where returned tuple is to be stored.  
                Returns null on error */
      Record *next() 
             /* returns null on end of file, else  stores data in record passed
		earlier to openScan, and returns its address */
      void     close()
   
   
   Write a program that uses the above iterator to print out all records
   in a file.



2) Implement a merge-join iterator, with the functions:

      Iterator *openMergeJoin(Iterator *R, Iterator *S, Record *rec);
             /* rec is a Record structure where returned tuple is to be stored.  
                Returns null on error */
      Record *next() 
             /* returns null on end of file, else  stores data in record passed
		earlier to openScan, and returns its address */
      void close()

    Assume that the join attribute is the first attribute of each join input, and 
    the output of the two iterators passed to openMergeJoin are sorted already.

    Write a program to open two iterators (on two files, assumed to be sorted already)
    open a merge-join iterator on these two iterators, and print out the merge-join
    output.     


Note: If you are implementing in C, the signatures of the above
      methods, for both Sequential scan and merge join would be:
		Record *next(Iterator *);
		void close(Iterator *);