use of org.apache.jena.sparql.algebra.op.OpOrder in project jena by apache.
the class TransformOrderByDistinctApplication method transform.
@Override
public Op transform(OpReduced opReduced, 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());
Op newReduced = OpReduced.create(newProject);
return new OpOrder(newReduced, order.getConditions());
}
}
}
// If we reach here then this transform is not applicable
return super.transform(opReduced, subOp);
}
use of org.apache.jena.sparql.algebra.op.OpOrder in project jena by apache.
the class TransformDistinctToReduced method transform1.
// Best is this is after TransformTopN but they are order independent
// TopN of "reduced or distinct of order" is handled.
//@Override
public Op transform1(OpDistinct opDistinct, Op subOp) {
if (subOp instanceof OpProject) {
OpProject opProject = (OpProject) subOp;
if (opProject.getSubOp() instanceof OpOrder) {
OpOrder opOrder = (OpOrder) opProject.getSubOp();
Set<Var> projectVars = new HashSet<>(opProject.getVars());
if (isSafe(projectVars, opOrder)) {
return OpReduced.create(subOp);
}
}
}
return super.transform(opDistinct, subOp);
}
use of org.apache.jena.sparql.algebra.op.OpOrder in project jena by apache.
the class TransformDistinctToReduced method transform.
@Override
public Op transform(OpDistinct opDistinct, Op subOp) {
OpOrder opOrder = null;
Set<Var> projectVars = null;
/* SELECT DISTINCT * {} ORDER BY
* giving an alegbra expression of the form:
* (distinct
* (order
*/
if (subOp instanceof OpOrder) {
opOrder = (OpOrder) subOp;
projectVars = OpVars.visibleVars(subOp);
} else if (subOp instanceof OpProject) {
OpProject opProject = (OpProject) subOp;
if (opProject.getSubOp() instanceof OpOrder) {
projectVars = new HashSet<>(opProject.getVars());
opOrder = (OpOrder) opProject.getSubOp();
}
}
if (projectVars == null)
return super.transform(opDistinct, subOp);
if (isSafe(projectVars, opOrder))
return OpReduced.create(subOp);
return super.transform(opDistinct, subOp);
}
use of org.apache.jena.sparql.algebra.op.OpOrder 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