Stage 9

int BlockAccess::project(int relId, Attribute* record);
int Algebra::select(char* srcRel, char* targetRel, char* attribute, int op, int strVal) {
    // instead of printing the values we are createing a new relation
    1. Create a 2D array for the names of the attributes 
    2. Create an Integer array for the attribute types
    3. Create a new relation with the target relation Schema::createRel(targetRel, numAttributes, attr_types, attr_names);
    4. Open the relation
    5. Use BlockAccess::search for the matching records and BlockAccess::insert(relId, record);
    6. if failed close the relation and Schema::deleteRel(relName)
    7. finally Schema::closeRel(relName)
}

int Algebra::project(char* srcRel, char* targetRel, int tar_attrs, char tar_Attrs[][ATTR_SIZE]) {
    int srcRelId = OpenRelTable::getRelId(srcRel);
    if(srcRelId == E_RELNOTOPEN) {
        return E_RELNOTOPEN; 
    }
    int attr_offset[tar_nAttrs];
    int attr_types[tar_nAttrs];
    for(int i = 0; i < tar_nAttrs; i++) {
        AttrCatEntry attrCatEntry;
        int ret  = AttrCacheTable::getAttrCatEntry(srcRelId, tar_attrs[i], &attrCatEntry);
        if(ret != SUCCESS){
            return E_ATTRNOTEXIST;
        }
        attr_offset[i] = attrCatEntry.offset;
        attr_types[i] = attrCatEntry.attrType;
    }
    Schema::createRel(targetRel, tar_nAttrs, tar_attrs, attr_types);

    OpenRelTable::getRelId(targetRelId);

    Attribute record[src_nAttrs];
    while(BlockAccess::project(srcReId,record) == SUCCESS) {
        Attribute proj_record[tar_nAttrs];
        for(int i = 0; i < tar_nAttrs; i++) {
            proj_record[i] = record[attr_offset[i]]
        }
        ret = BlockAccess::insert(tarRelId, proj_record);
    }
    Schema::closeRel(targetRel);
    return SUCCESS;
}