Search in sources :

Example 1 with OpDistinct

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);
}
Also used : SortCondition(org.apache.jena.query.SortCondition) OpProject(org.apache.jena.sparql.algebra.op.OpProject) OpOrder(org.apache.jena.sparql.algebra.op.OpOrder) Var(org.apache.jena.sparql.core.Var) OpDistinct(org.apache.jena.sparql.algebra.op.OpDistinct)

Aggregations

SortCondition (org.apache.jena.query.SortCondition)1 OpDistinct (org.apache.jena.sparql.algebra.op.OpDistinct)1 OpOrder (org.apache.jena.sparql.algebra.op.OpOrder)1 OpProject (org.apache.jena.sparql.algebra.op.OpProject)1 Var (org.apache.jena.sparql.core.Var)1