DBMS Requirements: AggTable

Class AggTable {

bool connect(const char* aUserName, const char* aPassword);

bool disconnect();

bool openTable(const char* aTableName);

bool group();

void setAggType(AggType aType);

void* fetch();

int getAggValue();

bool closeTable();

}

enum AggType {

MIN,

MAX,

SUM,

AVG,

COUNT

}

AggTable Guidelines

AggTable Usage

int main() {

AggTable sTable;

sTable.connect("root", "manager");

sTable.openTable("T1");

sTable.setAggType(SUM);

sTable.group();

void* record;

printf("Grouped Records\n");

while (true) {

record = sTable.fetch();

if (record == NULL) break;

printf("Group Value %d AggValue %d\n", *(int*) record, sTable.getAggValue());

}

sTable.closeTable();

sTable.disconnect();

return 0;

}

Assumption: Table T1 with field f1 and f2, both of type integer already exists in database

  1. Assume table has only two fields, both of type integer.
  2. Use DBAPI classes to implement the above methods.
  3. group() method should retrieve all the record pointers using table->fetch() and group it based on the first field, compute appropriate aggregation set using setAggType() for second field.
  4. fetch() should return pointer to the grouped record.
  5. getAggValue() should return the respective aggregated value for second field of the current grouped record.

%%