use of org.apache.jena.sparql.algebra.op.OpProject 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.OpProject in project jena by apache.
the class TransformSliceProject method transform.
@Override
public Op transform(OpSlice opSlice, Op subOp) {
// (slice (project...)) ==> (project (slice ...))
if (subOp instanceof OpProject) {
OpProject p = (OpProject) subOp;
Op sub = p.getSubOp();
Op x = new OpSlice(sub, opSlice.getStart(), opSlice.getLength());
x = new OpProject(x, p.getVars());
return x;
}
return super.transform(opSlice, subOp);
}
use of org.apache.jena.sparql.algebra.op.OpProject 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.OpProject in project jena by apache.
the class QueryExecUtils method execute.
public static void execute(Op op, DatasetGraph dsg, ResultsFormat outputFormat) {
QueryIterator qIter = Algebra.exec(op, dsg);
List<String> vars = null;
if (op instanceof OpProject)
vars = Var.varNames(((OpProject) op).getVars());
else
// The variables defined in patterns (not Filters, nor NOT EXISTS,
// nor ORDER BY)
vars = Var.varNames(OpVars.visibleVars(op));
ResultSet results = ResultSetFactory.create(qIter, vars);
outputResultSet(results, null, outputFormat);
}
use of org.apache.jena.sparql.algebra.op.OpProject 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);
}
Aggregations