dummyRelation = caf.getSpaceForNewRelation(2);
labelDummy(dummyRelation, "Duplicate Removal of "+inputRelation.toString(caf));
resultRelation = caf.getSpaceForNewRelation(inputRelation.getCardinality());
labelResult(resultRelation, "Duplicate Removal of "+inputRelation.toString(caf));
Cell a1 = caf.getLeftTopCellInRelation(inputRelation);
Cell c1 = caf.getLeftTopCellInRelation(dummyRelation);
Cell d1 = c1.nextInRow();
Column c = dummyRelation.getFirstCol();
String strC = c.toString(caf);
String strMATCH = String.format(MATCH, strC, strC);
String strD1 = d1.toString(caf);
formulas.put(c1, String.format(FR_IF, a1.toString(caf)));
formulas.put(d1, strMATCH);
Cell ef1 = d1.nextInRow();
for (Column ab : inputRelation) {
String strAb = ab.toString(caf);
formulas.put(ef1, String.format(INDEX, strAb, strAb, strD1));
ef1 = ef1.nextInRow();
}
Cell a2 = a1.nextInColumn();
Cell c2 = c1.nextInColumn();
Cell d2 = d1.nextInColumn();
String strC1 = c1.toString(caf);
StringBuilder sb = new StringBuilder(String.format(SR_TO_REPEAT, a1.getColumnO().toString(caf), a1.getRowO().toString(caf), a2.toString(caf), a2.toString(caf)));
boolean skipFirst = true;
for (Column ab : inputRelation) {
if (skipFirst) {
skipFirst = false;
continue;
}
Cell cell1 = new Cell(ab, new Row(1));
Cell cell2 = cell1.nextInColumn();
sb.append(",");
sb.append(String.format(SR_TO_REPEAT, cell1.getColumnO().toString(caf), cell1.getRowO().toString(caf), cell2.toString(caf), cell2.toString(caf)));
}
formulas.put(c2, String.format(SR_IF, a2.toString(caf), sb.toString(), strC1, strC1));
formulas.put(d2, strMATCH);
Cell ef2 = d1.nextInRow().nextInColumn();
String strD2 = d1.nextInColumn().toString(caf);
for (Column ab : inputRelation) {
String strAb = ab.toString(caf);
formulas.put(ef2, String.format(INDEX, strAb, strAb, strD2));
ef2 = ef2.nextInRow();
}
}