if (!(constraint instanceof ASTAggregation)) {
onlyAggregations = false;
}
final Variable var2 = new Variable(variable.getName());
p.addProjectionElement(var2);
final AddComputedBinding acb = group ? new GroupByAddComputedBinding()
: new AddComputedBinding();
acb.addProjectionElement(var2, constraint);
listOfAddComputedBindings.add(acb);
}
}
// deleting of values if there is only an aggregation statement
if (onlyAggregations || group) {
connection.connectAndSetAsNewOperatorConnection(new Distinct());
}
listOACB = this.topologicalSorting(listOfAddComputedBindings);
connection.connectAndSetAsNewOperatorConnection(p);
}
// insert sort operator
for (int i = 0; i < numberChildren; i++) {
if (node.jjtGetChild(i) instanceof ASTOrderConditions) {
node.jjtGetChild(i).accept(this, connection);
}
}
for (final AddComputedBinding acb : listOACB) {
connection.connectAndSetAsNewOperatorConnection(acb);
}
// Dealing with the HAVING clause
for (int i = 0; i < numberChildren; i++) {
final Node childi = node.jjtGetChild(i);
if (childi instanceof ASTHaving) {
for (int k = 0; k < childi.jjtGetNumChildren(); k++) {
if (childi.jjtGetChild(k) instanceof ASTFilterConstraint) {
final Having filter = new Having((ASTFilterConstraint) childi
.jjtGetChild(k));
this.processExistChildren(node, graphConstraint, filter);
filter.setEvaluator(this.evaluator);
connection.connectAndSetAsNewOperatorConnection(filter);
}
}
}
}
// Dealing with the GROUP clause
for (int j = 0; j < numberChildren; j++) {
final Projection p = new Projection();
final LinkedList<AddComputedBinding> listOfAddComputedBindings = new LinkedList<AddComputedBinding>();
ASTVar variable = null;
final Node childi = node.jjtGetChild(j);
onlyAggregations = true;
if (childi instanceof ASTGroup) {
for (int i = 0; i < childi.jjtGetNumChildren(); i++) {
if (childi.jjtGetChild(i) instanceof ASTAdditionNode
|| childi.jjtGetChild(i) instanceof ASTSubtractionNode
|| childi.jjtGetChild(i) instanceof ASTMultiplicationNode
|| childi.jjtGetChild(i) instanceof ASTDivisionNode) {
throw new Error(
"Error in GROUP BY statement: AS not found");
} else if (childi.jjtGetChild(i) instanceof ASTAs) {
variable = (ASTVar) childi.jjtGetChild(i).jjtGetChild(1);
final lupos.sparql1_1.Node constraint = childi.jjtGetChild(i).jjtGetChild(0);
/*
* Detecting Errors in SelectQuery if aggregations are
* used and additional variables are not bound by a
* GROUP BY statement
*/
this.prooveBoundedGroup(constraint);
if (!(constraint instanceof ASTAggregation)) {
onlyAggregations = false;
}
final Variable var2 = new Variable(variable.getName());
p.addProjectionElement(var2);
final AddComputedBinding acb = new GroupByAddComputedBinding();
acb.addProjectionElement(var2, constraint);
listOfAddComputedBindings.add(acb);
// deleting of values if there is only an aggregation
// statement
if (onlyAggregations) {