D64 Programming Assignment #2

Due Friday, March 10 at 5p.m.


Your second programming lab is to implement some of the relational operators on top of the the simple relation manager that you build in the first assignment. The goal is to access the functionality you built in the last assignment only through the interface defined in db.h. Unfortunately, I think you'll need a few more functions in db.h to make this assignment possible, so you need to add the following functions to your db.c file from last assignment. I've updated
db.h online to account for these new functions.

  1. int GetNumColumns(char *table_name, int *num_cols)

    This function gets the number of columns defined in a given table.

  2. int GetColumnNames(char *table_name,char *names[])

    This function gets the names of the columns of a table in order. The names array must be large enough to handle all of the names and the memory for each name should have been allocated by the caller.

  3. int GetColumnTypes(char *table_name,colType_t types[])

    This function gets the types of the columns of a table in order. The types array must be large enough to handle all of the types.

  4. int GetColumnLength(char *table_name,int col_num, int *col_length)

    This function gets the defined length of a CHAR column of a table given its column number.

  5. int GetColumnNum(char *table_name,char *col_name, int *col_num)

    This function gets the number of a given column within its table. The number will be between 0 and # cols - 1 and will be based on the order returned in GetColumnNames.

  6. int GetString2(struct scanDesc_t *scan, int col_num, char **val)

    This function get the value of a string column from the current row in the scan. The number of the desired column will be in col_num and on successful completion, the val pointer will be set to the string value. If the column is NULL, the function should return the error NULL_VALUE. If the column is an integer column, it should return the error BAD_COL_TYPE.

  7. int GetInteger2(struct scanDesc_t *scan, int col_num, int *val)

    This function get the value of an integer column from the current row in the scan. The number of the desired column will be in col_num and on successful completion, the val pointer will be set to the integer value. If the column is NULL, the function should return the error NULL_VALUE. If the column is a string column, it should return the error BAD_COL_TYPE.

You also need to implement the functions below. I've provided the header file already that includes the prototypes.

  1. int EquijoinBegin(char *table_name1, char *table_name2, char *col_name1, char* col_name2, struct scanDesc_t **op)


    This function begins an equijoin between two tables with the condition table_name1.col_name1 = table_name2.col_name2. Upon successful completion, the operator descriptor pointer that was passed in will be properly set. The scan for the equijoin will be positioned before the first row in the result. See the header file and the sample test program for more details.

  2. int EquijoinNext(struct scanDesc_t *op, valRec_t *vals)


    This function gets the values in the next row in the join. The values are filled into the vals array which is allocated by the caller and which must be large enough to hold the results.  The order of the values should be the same for each call to NextEquijoin within a scan.
     

  3. int EquijoinEnd(struct scanDesc_t *op)


    This function is used to end a natural join scan. Every call to EquijoinBegin should have a matching call to EquijoinEnd.

  4. int GroupingBegin(char *table_name1, char *group_col, char *aggregated_col_name, struct scanDesc_t **op)


    This function begins a grouping operator on a table. The group_col parameter specifies which column to group on and the aggregated_col_name specifies the column that MIN, MAX, AVG, COUNT, SUM should be computed for.  Upon successful completion, the operator descriptor pointer that was passed in will be properly set. The scan for the grouping will be positioned before the first row in the result. See the header file and the sample test program for more details.

  5. int GroupingNext(struct scanDesc_t *op, valRec_t *val)


    This function gets the unaggregated column value in the next group.

  6. int getAggregate(struct scanDesc_t *op, funcType_t function, void *value)


    This function gets the value of an aggregate function on the current group. The function parameter specifies which function and value points to where the value should be stored.  If the function is MAX or MIN on a CHAR column, value will point to a buffer to store the result in.  Otherwise it will point to an int.  If the aggregate value is NULL the function will return the error NULL_VALUE.
     

  7. int GroupingEnd(struct scanDesc_t *op)


    This function is used to end a grouping scan. Every call to GroupingBegin should have a matching call to GroupingEnd.


Notes:

Documentation

You must include comments in the code.

Grading

The grade of your program will be based on three aspects:

Testing and Submission

Submission of the assignment will take place electronically. Please tar your source code, makefile, and your op.doc documentation file. Then, send me an email with the subject Program 2 and attach the tar file.

Collaboration Policy

Students must work alone on this assignment, both on the design, coding, and testing stages. Every line of code should have been written by you or provided by me. YOU MAY NOT SHARE CODE, EVEN TEST CODE. Please do not turn in work that is similar enough to a fellow student's that we have to involve the academic police.