class sortMerge { public: sortMerge( char *filename1, // Name of heapfile for relation R. int len_in1, // # of columns in R. AttrType in1[], // Array containing field types of R. short t1_str_sizes[], // Array containing size of columns in R. int join_col_in1, // The join column number of R. char *filename2, // Name of heapfile for relation S int len_in2, // # of columns in S. AttrType in2[], // Array containing field types of S. short t2_str_sizes[], // Array containing size of columns in S. int join_col_in2, // The join column number of S. char* filename3, // Name of heapfile for merged results int amt_of_mem, // Number of pages available for sorting TupleOrder order, // Sorting order: Ascending or Descending Status& s // Status of constructor );
~sortMerge(); };The sortMerge constructor joins two relations R and S, represented by the heapfiles filename1 and filename2, respectively, using the sort-merge join algorithm. Note that the columns for relation R (S) are numbered from 0 to len_in1 - 1 (len_in2 - 1). You are to concatenate each matching pair of (r, s) records and write it into the heapfile filename3. Remember that the join column of relation S should not be repeated in the result. For example, if R's schema is {rnum:int, rstr:string} and S's schema is {snum:int, sstr:string} and S and R are joined on column 0 (the int attributes), then the join result schema will be {rnum:int, rstr:string, sstr:string}. If R and S are joined on column 1 (the string attributes), then the result schema is {rnum:int, rstr:string, snum:int}. The error layer for the sortMerge class is JOINS.
You will need to use the following classes which are given: Sort, HeapFile, and Scan. You will call the Sort constructor to sort the input heapfiles (which means your primary responsibility will be to implement the merging phase of the algorithm). Once a scan is opened on a heapfile, the scan cursor can be positioned to any record within the heapfile calling the Scan method position with an RID argument. The next call to the Scan method getNext will proceed from the new cursor position.
// set JOIN_COL to 1 to test joining relations on 2nd column (string field) // set JOIN_COL to 0 to test joinging relations on 1st column (int field) #define JOIN_COL 0Output from the test runs will help you to determine if your join algorithm is correct. Here is an example of the result of doing a sort-merge join of the listed R and S on the string attribute:
R: --- 2 bbb 2 eee 2 fff 13 sss 77 aaa 5 rrr 11 ccc 2 bbb S: --- 99 ooo 13 www 10 fff 12 rrr 8 xxx 10 sss 11 jjj 13 yyy 20 bbb 13 lll 66 ddd R join S: ---------- 2 bbb 20 2 bbb 20 2 fff 10 5 rrr 12 13 sss 10