use of org.apache.jena.query.SortCondition in project jena by apache.
the class ApplyTransformVisitor method transform.
protected List<SortCondition> transform(List<SortCondition> conditions) {
List<SortCondition> conditions2 = new ArrayList<>();
boolean changed = false;
for (SortCondition sc : conditions) {
Expr e = sc.getExpression();
Expr e2 = transform(e);
conditions2.add(new SortCondition(e2, sc.getDirection()));
if (e != e2)
changed = true;
}
if (changed)
return conditions2;
else
return conditions;
}
use of org.apache.jena.query.SortCondition 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.query.SortCondition in project jena by apache.
the class VariableUsageVisitor method visit.
@Override
public void visit(OpTopN opTop) {
Collection<Var> vars = new ArrayList<>();
for (SortCondition condition : opTop.getConditions()) {
ExprVars.varsMentioned(vars, condition);
}
action(vars);
}
use of org.apache.jena.query.SortCondition in project jena by apache.
the class VariableUsageVisitor method visit.
@Override
public void visit(OpOrder opOrder) {
Collection<Var> vars = new ArrayList<>();
for (SortCondition condition : opOrder.getConditions()) {
ExprVars.varsMentioned(vars, condition);
}
action(vars);
}
use of org.apache.jena.query.SortCondition in project jena by apache.
the class TransformEliminateAssignments method transform.
@Override
public Op transform(OpTopN opTop, Op subOp) {
if (!this.isApplicable())
return super.transform(opTop, subOp);
// See what vars are used in the sort conditions
Collection<Var> vars = new ArrayList<>();
for (SortCondition cond : opTop.getConditions()) {
ExprVars.varsMentioned(vars, cond.getExpression());
}
// Are any of these vars single usage?
List<SortCondition> conditions = null;
for (Var var : vars) {
// Usage count will be 2 if we can eliminate the assignment
// First usage is when it is introduced by the assignment and the
// second is when it is used now in this filter
Expr e = getAssignExpr(var);
if (this.tracker.getUsageCount(var) == 2 && hasAssignment(var) && canInline(e) && shouldInline(e)) {
// Can go back and eliminate that assignment
subOp = eliminateAssignment(subOp, var);
// Replace the variable usage with the expression within the
// sort conditions
conditions = processConditions(opTop.getConditions(), conditions, var);
this.tracker.getAssignments().remove(var);
}
}
// Create a new order if we've substituted any expressions
if (conditions != null) {
return new OpTopN(subOp, opTop.getLimit(), conditions);
}
return super.transform(opTop, subOp);
}
Aggregations