Projection linked.
This commit is contained in:
parent
1f6fa55754
commit
fa50473ad4
5 changed files with 61 additions and 18 deletions
|
@ -32,7 +32,6 @@ void Attribute::addCell(string v){
|
||||||
}
|
}
|
||||||
|
|
||||||
void Attribute::removeCell(int index){
|
void Attribute::removeCell(int index){
|
||||||
cout << values[index] << " " << index << endl;
|
|
||||||
values.erase(values.begin() + index);
|
values.erase(values.begin() + index);
|
||||||
size--;
|
size--;
|
||||||
}
|
}
|
||||||
|
|
27
DBEngine.cpp
27
DBEngine.cpp
|
@ -135,13 +135,16 @@ Relation DBEngine::projection(vector<string> input, Relation r){
|
||||||
vector<Attribute> v;
|
vector<Attribute> v;
|
||||||
string new_name = r.getTableName() + " Projection";
|
string new_name = r.getTableName() + " Projection";
|
||||||
|
|
||||||
for(int i = 0; i < input.size(); ++i) {
|
for(int i = 0; i < input.size(); ++i)
|
||||||
|
{
|
||||||
for(int j = 0; j < r.getSize(); ++j) {
|
for(int j = 0; j < r.getSize(); ++j)
|
||||||
|
{
|
||||||
if((r.getAttributes())[j].getName() == input[i])
|
if((r.getAttributes())[j].getName() == input[i])
|
||||||
|
{
|
||||||
v.push_back((r.getAttributes())[j]);
|
v.push_back((r.getAttributes())[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Relation temp(new_name, v);
|
Relation temp(new_name, v);
|
||||||
return temp;
|
return temp;
|
||||||
|
@ -221,37 +224,37 @@ Relation DBEngine::setDiff(Relation r1, Relation r2){
|
||||||
*/
|
*/
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
cout << "test1" << endl;
|
//cout << "test1" << endl;
|
||||||
|
|
||||||
for(int x = 0; x < r2.getAttributes().size(); ++x)
|
for(int x = 0; x < r2.getAttributes().size(); ++x)
|
||||||
{
|
{
|
||||||
|
|
||||||
cout << "test2" << endl;
|
//cout << "test2" << endl;
|
||||||
for (int i = 0; i < r2.getAttributes()[x].getSize(); ++i)
|
for (int i = 0; i < r2.getAttributes()[x].getSize(); ++i)
|
||||||
{
|
{
|
||||||
|
|
||||||
cout << "test3" << endl;
|
//cout << "test3" << endl;
|
||||||
temp = r2.getTuple(i);
|
temp = r2.getTuple(i);
|
||||||
|
|
||||||
for(int y = 0; y < new_r.getAttributes().size(); ++y)
|
for(int y = 0; y < new_r.getAttributes().size(); ++y)
|
||||||
{
|
{
|
||||||
size = new_r.getAttributes()[y].getSize();
|
size = new_r.getAttributes()[y].getSize();
|
||||||
cout << "test4" << endl;
|
//cout << "test4" << endl;
|
||||||
new_r.getAttributes()[y].getSize();
|
new_r.getAttributes()[y].getSize();
|
||||||
for (int j = 0; j < size; ++j)
|
for (int j = 0; j < size; ++j)
|
||||||
{
|
{
|
||||||
cout << "test5" << endl;
|
//cout << "test5" << endl;
|
||||||
for(int a = 0; a < temp.size(); ++a)
|
for(int a = 0; a < temp.size(); ++a)
|
||||||
{
|
{
|
||||||
cout << "test6" << endl;
|
//cout << "test6" << endl;
|
||||||
for(int b = 0; b < new_r.getTuple(j).size(); ++b)
|
for(int b = 0; b < new_r.getTuple(j).size(); ++b)
|
||||||
{
|
{
|
||||||
cout << "test7" << endl;
|
//cout << "test7" << endl;
|
||||||
cout << temp[a] << " " << new_r.getTuple(j)[b] << " " << b << endl;
|
//cout << temp[a] << " " << new_r.getTuple(j)[b] << " " << b << endl;
|
||||||
if (temp[a] == new_r.getTuple(j)[b])
|
if (temp[a] == new_r.getTuple(j)[b])
|
||||||
{
|
{
|
||||||
new_r.removeFromTuple(b, j);
|
new_r.removeFromTuple(b, j);
|
||||||
cout << "test" << endl;
|
//cout << "test" << endl;
|
||||||
//duplicate = true;
|
//duplicate = true;
|
||||||
//break;
|
//break;
|
||||||
}
|
}
|
||||||
|
|
50
Parser.cpp
50
Parser.cpp
|
@ -53,7 +53,40 @@ tuple<vector<string>, Relation> expression(vector<string> input, DBEngine &engin
|
||||||
|
|
||||||
else if(input[0] == "project")
|
else if(input[0] == "project")
|
||||||
{
|
{
|
||||||
|
input.erase(input.begin());
|
||||||
|
if(input[0] == "(")
|
||||||
|
{
|
||||||
|
input.erase(input.begin());
|
||||||
|
vector<string> temp;
|
||||||
|
while(input[0] != ")")
|
||||||
|
{
|
||||||
|
temp.push_back(input[0]);
|
||||||
|
input.erase(input.begin());
|
||||||
|
}
|
||||||
|
input.erase(input.begin());
|
||||||
|
Relation rfinal("TEMP");
|
||||||
|
if(engine.isRelation(input[0]))
|
||||||
|
{
|
||||||
|
rfinal = engine.projection(temp, engine.getTableFromName(input[0]));
|
||||||
|
input.erase(input.begin());
|
||||||
|
get<0>(t) = input;
|
||||||
|
get<1>(t) = rfinal;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
else if(input[0] == "(")
|
||||||
|
{
|
||||||
|
t = expression(input, engine);
|
||||||
|
rfinal = engine.projection(temp, get<1>(t));
|
||||||
|
//get<0>(t) = input;
|
||||||
|
get<1>(t) = rfinal;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "Projection syntax incorrect." << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(input[0] == "rename")
|
else if(input[0] == "rename")
|
||||||
|
@ -214,15 +247,24 @@ tuple<vector<string>, Relation> expression(vector<string> input, DBEngine &engin
|
||||||
|
|
||||||
vector<string> showCMD(vector<string> input, DBEngine &engine)
|
vector<string> showCMD(vector<string> input, DBEngine &engine)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
if (input.size() > 3)
|
if (input.size() > 3)
|
||||||
{
|
{
|
||||||
cout<<"Syntax error!"<<endl;
|
cout<<"Syntax error!"<<endl;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
PRelation r(input[0]);
|
if(engine.isRelation(input[0]))
|
||||||
|
{
|
||||||
|
engine.getTableFromName(input[0]).display();
|
||||||
|
input.erase(input.begin());
|
||||||
|
}
|
||||||
|
|
||||||
// send show command to DBEngine
|
else
|
||||||
engine.getTableFromName(r.getName()).display();
|
{
|
||||||
|
tuple<vector<string>, Relation> t = expression(input, engine);
|
||||||
|
get<1>(t).display();
|
||||||
|
}
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,6 @@ void Relation::removeFromTuple(int rindex, int aindex)
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout << aindex << endl;
|
|
||||||
att[rindex].removeCell(aindex);
|
att[rindex].removeCell(aindex);
|
||||||
}
|
}
|
||||||
}
|
}
|
BIN
test
BIN
test
Binary file not shown.
Reference in a new issue