crossprod almost done

This commit is contained in:
Rebecca Schofield 2015-09-28 15:46:42 -05:00
parent 6247ac10ca
commit 4809a518ad
6 changed files with 28 additions and 84 deletions

View file

@ -185,8 +185,10 @@ Relation DBEngine::setDiff(Relation r1, Relation r2){
Relation DBEngine::crossProduct(Relation r1, Relation r2){ Relation DBEngine::crossProduct(Relation r1, Relation r2){
vector<Attribute> new_atts = r1.getAttributes(); vector<Attribute> new_atts = r1.getAttributes();
int r1_attsize = r1.getAttributes()[0].getSize();
int r2_attsize = r2.getAttributes()[0].getSize();
for (int i = 0; i < r2.getAttributes().size(); ++i) { for (int i = 0; i < r2_attsize; ++i) {
new_atts.push_back(r2.getAttributes()[i]); new_atts.push_back(r2.getAttributes()[i]);
} }
@ -194,6 +196,29 @@ Relation DBEngine::crossProduct(Relation r1, Relation r2){
new_atts[i].clearAllValues(); new_atts[i].clearAllValues();
} }
vector<string> r1_tuple;
vector<string> r2_tuple;
for (int i = 0; i < r1_attsize; ++i) {
r1_tuple = r1.getTuple(i);
for (int a = 0; a < r1_tuple.size(); ++a) {
cout << r1_tuple[a] << " ";
}
for (int j = 0; j < r2_attsize; ++j) {
r2_tuple = r2.getTuple(j);
for (int b = 0; b < r2_tuple.size(); ++b){
cout << r2_tuple[b] << " ";
}
cout << "\n";
}
cout << "\n\n";
}
//currently all returned relations are called TEMP //currently all returned relations are called TEMP
Relation new_r("TEMP", new_atts); Relation new_r("TEMP", new_atts);

Binary file not shown.

View file

@ -1,82 +0,0 @@
---------------
Queries
---------------
Selection:
correct: select ( age == 12 ) people ;
incorrect: select ( age ))))) people ;
Projection:
correct: project ( age ) people ;
incorrect: project age people ;
Renaming:
correct: rename ( age, years old ) ;
incorrect: rename age years ;
Set Union:
correct: union ( people + animals ) ;
incorrect: union people animals ;
Set Difference:
correct: difference ( people - animals ) ;
incorrect: difference people animals ;
Cross Product:
correct: product ( people * animals ) ;
incorrect: product people animals ;
-------------------
Commands
-------------------
Open:
correct: OPEN people ;
incorrect: OPEN ;
Close:
correct: CLOSE people ;
incorrect: CLOSE ;
Save:
correct: SAVE people ;
incorrect: SAVE ;
Exit:
correct: EXIT ;
incorrect: EXIT people ;
Show:
correct: SHOW people ;
incorrect: SHOW ;
Create:
correct: CREATE TABLE people ( age INTEGER, name VARCHAR ( 20 ) ) PRIMARY KEY ( name ) ;
incorrect: CREATE TABLE people age name ;
Update:
correct: UPDATE people SET ( age = 10 ) WHERE ( name == "Bob" ) ;
incorrect: UPDATE ( age = 10 ) WHERE people ;
Insert:
correct: INSERT INTO people VALUES FROM ( 12, "Benny" ) ;
incorrect: INSERT INTO people 12 "Benny" ;
Delete:
correct: DELETE FROM people WHERE ( name == "John" ) ;
incorrect: DELETE IN people WHEN (name=John) ;

BIN
a.out

Binary file not shown.

BIN
test

Binary file not shown.

View file

@ -43,5 +43,6 @@ int main() {
engine.createTable("MoarFood", v2); engine.createTable("MoarFood", v2);
engine.crossProduct(engine.getTableFromName("Food"), engine.getTableFromName("MoarFood")).display(); engine.crossProduct(engine.getTableFromName("Food"), engine.getTableFromName("MoarFood"));
//engine.crossProduct(engine.getTableFromName("Food"), engine.getTableFromName("MoarFood")).display();
} }