Relation furtherDummyRelation = caf.getSpaceForNewRelation(7);
dummyRelation = extend(dummyRelation, furtherDummyRelation);
//finding row numbers in the input relation that correspond to the group by keys
Column h = furtherDummyRelation.getFirstCol();
Column a = sortedInput1.getCol(index1);
Column e = standarizationResult1.getFirstCol();
for (int row = 1; row <= 2; row++) {
formulas.put(h.getCell(row), fillMatch(e.getCell(row), a));
}
Column o = h.getNext();
Column i = sortedInput2.getCol(index2);
Column m = standarizationResult2.getFirstCol();
for (int row = 1; row <= 2; row++) {
formulas.put(o.getCell(row), fillMatch(m.getCell(row), i));
}
//multiplying the group bys so we know how many results there are for a given key
Column p = o.getNext();
Column noInSortedGroupBy1 = standarizationResult1.getLastCol();
Column noInSortedGroupBy2 = standarizationResult2.getLastCol();
for (int row = 1; row <= 2; row++) {
formulas.put(p.getCell(row), fillIfErrorTimes(noInSortedGroupBy1.getCell(row), noInSortedGroupBy2.getCell(row)));
}
//filling Q
Column q = p.getNext();
formulas.put(q.getCell(1), "0");
formulas.put(q.getCell(2), fillIfErrorPlus(p.getCell(1), q.getCell(1)));
//filling R
Column r = q.getNext();
formulas.put(r.getCell(1), fillSum(p));
//filling S
Column s = r.getNext();
for (int row = 1; row <= 2; row++) {
formulas.put(s.getCell(row), fillIfMatch(r, q));
}
//filling T
Column t = s.getNext();
formulas.put(t.getCell(1), fillIfIsNa1(s.getCell(1)));
formulas.put(t.getCell(2), fillIfIsNa2(s.getCell(1), s.getCell(2), t.getCell(1)));
//dummy constructed with extend
labelDummy(dummyRelation, "Equality Join of " + inputRelation1.toString(caf) + " and " + inputRelation2.toString(caf));
resultRelation = caf.getSpaceForNewRelation(inputRelation1.getCardinality() + inputRelation2.getCardinality() - 1);
labelResult(resultRelation, "Equality Join of " + inputRelation1.toString(caf) + " and " + inputRelation2.toString(caf));
//producing the common index
Column u = resultRelation.getFirstCol();
for (int row = 1; row <= 2; row++) {
formulas.put(u.getCell(row), fillIndex(e, s.getCell(row)));
}
//copying the reminder of the first relation
int[] indexesWithouTheKey1 = new int[sortedInput1.getCardinality() - 1];
dummy = 0;
for (int c = 1; c <= sortedInput1.getCardinality(); c++) {
if (c != index1) {
indexesWithouTheKey1[dummy++] = c;
}
}
Column v = u.getNext();
for (int colInd : indexesWithouTheKey1) {
for (int row = 1; row <= 2; row++) {
formulas.put(v.getCell(row), fillIndexIndex1(sortedInput1.getCol(colInd), h, noInSortedGroupBy1, s.getCell(row), t.getCell(row)));
}
v = v.getNext();
}
//copying the reminder of the second relation
int[] indexesWithouTheKey2 = new int[sortedInput2.getCardinality() - 1];
dummy = 0;
for (int c = 1; c <= sortedInput2.getCardinality(); c++) {
if (c != index2) {
indexesWithouTheKey2[dummy++] = c;
}
}
Column w = v;
for (int colInd : indexesWithouTheKey2) {
for (int row = 1; row <= 2; row++) {
formulas.put(w.getCell(row), fillIndexIndex2(sortedInput2.getCol(colInd), o, noInSortedGroupBy1, s.getCell(row), t.getCell(row)));
}
w = w.getNext();
}
}