private TupleExpr buildTuple(final List<QueryModelNode> nodes, final List<Filter> filters, final Projection projection) { final Projection proj = projection.clone(); Join join = null; join = new Join((TupleExpr) nodes.get(0).clone(), (TupleExpr) nodes.get(1).clone()); for (int i = 2; i < nodes.size(); i++) { join = new Join(join, (TupleExpr) nodes.get(i).clone()); } if (filters.size() == 0) { proj.setArg(join); return proj; } else { TupleExpr queryPlan = join; for (final Filter f : filters) { final Filter filt = f.clone(); filt.setArg(queryPlan); queryPlan = filt; } proj.setArg(queryPlan); return proj; } }
private UnaryTupleOperator projection() { if (!mProjectionPatterns.isEmpty()) { return multiProjection(); } else { Extension aExt = null; ProjectionElemList aList = new ProjectionElemList(); for (String aVar : mProjectionVars) { aList.addElement(new ProjectionElem(aVar)); } Projection aProjection = new Projection(); aProjection.setProjectionElemList(aList); if (aExt != null) { aProjection.setArg(aExt); } return aProjection; } }
/** * * This method moves the Filters of a specified {@link TupleExpr} to the top * of the TupleExpr. * * @param query * - query whose filters will be relocated * @return - TupleExpr with filters relocated to top */ public static TupleExpr moveFiltersToTop(TupleExpr query) { ProjectionAndFilterGatherer fg = new ProjectionAndFilterGatherer(); query.visit(fg); List<ValueExpr> filterCond = new ArrayList<>(fg.filterCond); Projection projection = fg.projection; if (filterCond.size() == 0) { return query; } Filter first = new Filter(); first.setCondition(filterCond.remove(0)); Filter current = first; for (ValueExpr cond : filterCond) { Filter filter = new Filter(null, cond); current.setArg(filter); current = filter; } TupleExpr te = projection.getArg(); projection.setArg(first); current.setArg(te); return query; }
projection.setArg(join);
private Projection visitResultVariables(Resource resultVars) throws OpenRDFException { ProjectionElemList projElemList = new ProjectionElemList(); Iteration<? extends Resource, QueryEvaluationException> iter = Statements.listResources(resultVars, store); while (iter.hasNext()) { Resource r = iter.next(); ProjectionElem projElem = visitResultVariable(r); projElemList.addElement(projElem); } Projection proj = new Projection(); proj.setProjectionElemList(projElemList); tupleRoot = proj; SingletonSet stub = new SingletonSet(); proj.setArg(stub); tupleNode = stub; return proj; }
private Projection visitResultNodes(Resource resultNodes) throws OpenRDFException { ProjectionElemList projElemList = new ProjectionElemList(); Iteration<? extends Resource, QueryEvaluationException> iter = Statements.listResources(resultNodes, store); while (iter.hasNext()) { Resource r = iter.next(); ProjectionElem projElem = visitResultNode(r); projElemList.addElement(projElem); } Projection proj = new Projection(); proj.setProjectionElemList(projElemList); tupleRoot = new DescribeOperator(proj); SingletonSet stub = new SingletonSet(); proj.setArg(stub); tupleNode = stub; return proj; }