use of org.apache.jena.sparql.algebra.op.OpDistinct in project jena by apache.
the class TransformOrderByDistinctApplication method transform.
@Override
public Op transform(OpDistinct opDistinct, Op subOp) {
if (subOp instanceof OpProject) {
OpProject project = (OpProject) subOp;
// Inner operation must be an ORDER BY
if (project.getSubOp() instanceof OpOrder) {
List<Var> projectVars = project.getVars();
OpOrder order = (OpOrder) project.getSubOp();
// Everything we wish to order by must only use variables that
// appear in the project list
boolean ok = true;
for (SortCondition condition : order.getConditions()) {
if (!isValidSortCondition(condition, projectVars)) {
ok = false;
break;
}
}
// Everything checks out so we can make the change
if (ok) {
OpProject newProject = new OpProject(order.getSubOp(), project.getVars());
OpDistinct newDistinct = new OpDistinct(newProject);
return new OpOrder(newDistinct, order.getConditions());
}
}
}
// If we reach here then this transform is not applicable
return super.transform(opDistinct, subOp);
}
Aggregations