union comp done

This commit is contained in:
Rebecca Schofield 2015-09-15 22:36:44 -05:00
parent 6681cc556b
commit fc0f899568
4 changed files with 43 additions and 11 deletions

View file

@ -43,9 +43,7 @@ public:
void product() { /*Brandon*/ }
bool unionComp(Relation r1, Relation r2) {
//Two relations are union-compatible if they have the same # of attributes and each attribute must be
//from the same domain
//return (() && ());
return ((r1.getSize() == r2.getSize()) && (r1.getDomains() == r2.getDomains()));
}

View file

@ -88,4 +88,16 @@ public:
}
}
//make this better
vector<string> getDomains() {
vector<string> ds;
for (int i = 0; i < size; ++i)
{
ds.push_back(att[i].getType());
}
return ds;
}
};

BIN
a.out

Binary file not shown.

View file

@ -25,16 +25,16 @@ int main() {
vec.push_back(att2);
Attribute att3("name", "VARCHAR(20)", true);
att1.addRow("Fry");
att1.addRow("Bender");
att1.addRow("Leela");
att1.addRow("Zoidberg");
att3.addRow("Fry");
att3.addRow("Bender");
att3.addRow("Leela");
att3.addRow("Zoidberg");
Attribute att4("age", "INTEGER", false);
att2.addRow("22");
att2.addRow("5");
att2.addRow("22");
att2.addRow("50");
att4.addRow("22");
att4.addRow("5");
att4.addRow("22");
att4.addRow("50");
vector<Attribute> vec2;
vec2.push_back(att3);
@ -45,4 +45,26 @@ int main() {
engine.createTable("table2", vec2);
engine.showTables(engine.getTableFromName("table1"));
Attribute att5("name", "VARCHAR(20)", true);
att5.addRow("Yrf");
att5.addRow("Redneb");
att5.addRow("Aleel");
att5.addRow("Grebdoiz");
Attribute att6("age", "INTEGER", false);
att6.addRow("44");
att6.addRow("10");
att6.addRow("44");
att6.addRow("100");
vector<Attribute> vec3;
vec3.push_back(att5);
vec3.push_back(att6);
engine.createTable("table3", vec3);
cout << "a";
cout << engine.unionComp(engine.getTableFromName("table1"), engine.getTableFromName("table2"));
cout << engine.unionComp(engine.getTableFromName("table2"), engine.getTableFromName("table3"));
}