Docsity

Relational Algebra Assignment: Implementing Operators on DBFile Class, Assignments of Computer Science

Toggle sidebar
bg1
Assignments 3 and 4
As was stated in class, your group can choose to complete either assignment. I believe
that Assignment #4 is easier, and will be less work, if you are reasonably confident your
implementation of Assignment #2 is working. The downside is that Assignment #4 builds
on everything else that we’ve done, so it will result in a much more complicated piece of
software, which equates to more opportunities for untraceable bugs. If you decide to
work on Assignment #3, there is the added incentive that if you complete the Insert
function, then you can get 20% extra credit (if it works correctly).
Assignment 4
The goal of this (rather straightforward, but not necessarily easy!) assignment is to
implement a set of relational algebra operators on top of the DBFile class. These
operators will be encapsulated within the RelAlg class. Here is the prototype.
extern LRU myBuffer; // this is the buffer manager
extern Catalog dbCatalog; // this is the catalog file
Class RelAlg {
Private:
/* whatever you need in here! */
Public:
RelAlg ();
~RelAlg ();
void SJ (DBFile &R, DBFile &S, int whichRAtt, int whichSAtt,
char *outName, DBFile &RSFile, Schema &RSschema);
void Multiply (DBFile &R, DBFile &S, char *outName,
DBFile &RSFile, Schema &RSschema);
void RemDups (DBFile &R, char *outName, DBFile &output);
void Kill (DBFile &R);
void Project (DBFile &R, int numAtts, int *atts,
char *outName, DBFile &output, Schema &outSchema);
void SelectNeq (DBFile &R, Value &val, char *outName,
DBFile &output);
void SelectEq (DBFile &R, Value &val, char *outName,
DBFile &output);
void SelectLT (DBFile &R, Value &val, char *outName,
DBFile &output);
void SelectGT (DBFile &R, Value &val, char *outName,
DBFile &output);
double Avg (DBFile &R, int whichAtt);
double Sum (DBFile &R, int whichAtt);
int Count (DBFile &R);
};
pf2

Partial preview of the text

Download Relational Algebra Assignment: Implementing Operators on DBFile Class and more Assignments Computer Science in PDF only on Docsity!

Assignments 3 and 4

As was stated in class, your group can choose to complete either assignment. I believe

that Assignment #4 is easier, and will be less work , if you are reasonably confident your

implementation of Assignment #2 is working. The downside is that Assignment #4 builds

on everything else that we’ve done, so it will result in a much more complicated piece of

software, which equates to more opportunities for untraceable bugs. If you decide to

work on Assignment #3, there is the added incentive that if you complete the Insert

function, then you can get 20% extra credit (if it works correctly).

Assignment 4

The goal of this (rather straightforward, but not necessarily easy!) assignment is to

implement a set of relational algebra operators on top of the DBFile class. These

operators will be encapsulated within the RelAlg class. Here is the prototype.

extern LRU myBuffer; // this is the buffer manager

extern Catalog dbCatalog; // this is the catalog file

Class RelAlg {

Private:

/* whatever you need in here! */

Public:

RelAlg (); ~RelAlg (); void SJ (DBFile &R, DBFile &S, int whichRAtt, int whichSAtt, char *outName, DBFile &RSFile, Schema &RSschema); void Multiply (DBFile &R, DBFile &S, char *outName, DBFile &RSFile, Schema &RSschema); void RemDups (DBFile &R, char *outName, DBFile &output); void Kill (DBFile &R); void Project (DBFile &R, int numAtts, int *atts, char *outName, DBFile &output, Schema &outSchema); void SelectNeq (DBFile &R, Value &val, char *outName, DBFile &output); void SelectEq (DBFile &R, Value &val, char *outName, DBFile &output); void SelectLT (DBFile &R, Value &val, char *outName, DBFile &output); void SelectGT (DBFile &R, Value &val, char *outName, DBFile &output); double Avg (DBFile &R, int whichAtt); double Sum (DBFile &R, int whichAtt); int Count (DBFile &R);

The routines that you need to implement have the following functionality.

*void SJ (DBFile &R, DBFile &S, int whichRAtt, int whichSAtt, char outName, DBFile &RSFile, Schema &RSschema);

This routine performs a sort join on the two relations R and S, on the specified attribute.

The DBFile object that is passed in, RSFile, will hold the eventual output. RSFile should

not have been opened at the time that it is passed in. The SJ routine opens and creates the

output file, storing the result into the file name that is specified. The schema for the

newly-created relation is also returned to the caller.

*void Multiply (DBFile &R, DBFile &S, char outName, DBFile &RSFile, Schema &RSschema);

This routine performs a cross product of the two relations. This is exactly the same as

above, except that we don’t need to check for equality of the two attributes, w simply

accept every combination of tuples from R and S.

*void RemDups (DBFile &R, char outName, DBFile &output);

This routine removes all duplicate tuples from the specified relation (first it sorts the

relation to order the tuples, and then it kills all duplicates).

void Kill (DBFile &R);

Here we simply remove the specified file from disk.

**void Project (DBFile &R, int numAtts, int atts, char outName, DBFile &output, Schema &outSchema);

This projects the specified attributes out, removing all others.

**void SelectNeq (DBFile &R, Value &val, char *outName, DBFile &output); void SelectEq (DBFile &R, Value &val, char *outName, DBFile &output); void SelectLT (DBFile &R, Value &val, char outName, DBFile &output); void SelectGT (DBFile &R, Value &val, char outName, DBFile &output);

These four routines perform a relational selection on the specified attribute, with the

specified value.

double Avg (DBFile &R, int whichAtt); double Sum (DBFile &R, int whichAtt); int Count (DBFile &R);

These three routines compute an aggregate function over the relation.

That’s it!