dummyRelation = caf.getEmptyRelation();
//sort the first input
SortingAscendingOperator sortAscOper1before = new SortingAscendingOperator(caf, inputRelation1, index1);
formulas.putAll(sortAscOper1before.getFormulas());
Relation sortedInput1 = sortAscOper1before.getResultRelation();
dummyRelation = extend(dummyRelation, sortAscOper1before.getDummyRelation());
dummyRelation = extend(dummyRelation, sortedInput1);
labels.putAll(sortAscOper1before.getLabels());
//sort the second input
SortingAscendingOperator sortAscOper2before = new SortingAscendingOperator(caf, inputRelation2, index2);
formulas.putAll(sortAscOper2before.getFormulas());
Relation sortedInput2 = sortAscOper2before.getResultRelation();
dummyRelation = extend(dummyRelation, sortAscOper2before.getDummyRelation());
dummyRelation = extend(dummyRelation, sortedInput2);
labels.putAll(sortAscOper2before.getLabels());
//semijoin to filter the first input
SemiJoinOperator semiJoinOper1 = new SemiJoinOperator(caf, sortedInput1, index1, sortedInput2, index2);
formulas.putAll(semiJoinOper1.getFormulas());
Relation semiJoinResult1 = semiJoinOper1.getResultRelation();
dummyRelation = extend(dummyRelation, semiJoinOper1.getDummyRelation());
dummyRelation = extend(dummyRelation, semiJoinResult1);
labels.putAll(semiJoinOper1.getLabels());
//semijoin to filter the second input
SemiJoinOperator semiJoinOper2 = new SemiJoinOperator(caf, sortedInput2, index2, sortedInput1, index1);
formulas.putAll(semiJoinOper2.getFormulas());
Relation semiJoinResult2 = semiJoinOper2.getResultRelation();
dummyRelation = extend(dummyRelation, semiJoinOper2.getDummyRelation());
dummyRelation = extend(dummyRelation, semiJoinResult2);
labels.putAll(semiJoinOper2.getLabels());
//select (C,count(D)) from (C,D) group by D for the first relation
int[] indexesWithoutThefirst1 = new int[semiJoinResult1.getCardinality() - 1];
int dummy = 0;
for (int c = 2; c <= semiJoinResult1.getCardinality(); c++) {
indexesWithoutThefirst1[dummy++] = c;
}
AggregationOperator agregOper1 = new AggregationOperator(caf, semiJoinResult1, new int[]{1}, new CountExtender(caf, new int[][]{indexesWithoutThefirst1}));
formulas.putAll(agregOper1.getFormulas());
Relation groupBy1 = agregOper1.getResultRelation();
dummyRelation = extend(dummyRelation, agregOper1.getDummyRelation());
dummyRelation = extend(dummyRelation, groupBy1);
labels.putAll(agregOper1.getLabels());
//select (C,count(D)) from (C,D) group by D for the second relation
int[] indexesWithoutTheFirst2 = new int[semiJoinResult2.getCardinality() - 1];
dummy = 0;
for (int c = 2; c <= semiJoinResult2.getCardinality(); c++) {
indexesWithoutTheFirst2[dummy++] = c;
}
AggregationOperator agregOper2 = new AggregationOperator(caf, semiJoinResult2, new int[]{1}, new CountExtender(caf, new int[][]{indexesWithoutTheFirst2}));
formulas.putAll(agregOper2.getFormulas());
Relation groupBy2 = agregOper2.getResultRelation();
dummyRelation = extend(dummyRelation, agregOper2.getDummyRelation());
dummyRelation = extend(dummyRelation, groupBy2);
labels.putAll(agregOper2.getLabels());
//standarization after groupBy1
StandarizationOperator standOper1 = new StandarizationOperator(caf, groupBy1);
formulas.putAll(standOper1.getFormulas());
Relation standarizationResult1 = standOper1.getResultRelation();
dummyRelation = extend(dummyRelation, standOper1.getDummyRelation());
dummyRelation = extend(dummyRelation, standarizationResult1);
labels.putAll(standOper1.getLabels());
//standarization after groupBy2
StandarizationOperator standOper2 = new StandarizationOperator(caf, groupBy2);
formulas.putAll(standOper2.getFormulas());
Relation standarizationResult2 = standOper2.getResultRelation();
dummyRelation = extend(dummyRelation, standOper2.getDummyRelation());
dummyRelation = extend(dummyRelation, standarizationResult2);
labels.putAll(standOper2.getLabels());
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));
}