@Override public void meet(Projection node) { this.projection = node; node.getArg().visit(this); }
/** * Make a {@link ProjectionEvaluator} that processes the logic of a {@link Projection}. * * @param projection - Defines the projection that will be processed. (not null) * @return A {@link ProjectionEvaluator} for the provided {@link Projection}. */ public static ProjectionEvaluator make(final Projection projection) { requireNonNull(projection); final ProjectionElemList projectionElems = projection.getProjectionElemList(); final TupleExpr arg = projection.getArg(); final Optional<Extension> extension = arg instanceof Extension ? Optional.of((Extension)arg) : Optional.empty(); return new ProjectionEvaluator(projectionElems, extension); }
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; } }
@Override public void meet(Projection projectionNode) throws Exception { projectionNode.visitChildren(this); if (projectionNode.getArg() instanceof AggregationPipelineQueryNode && projectionNode.getParentNode() != null) { AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) projectionNode.getArg(); if (pipelineNode.project(Arrays.asList(projectionNode.getProjectionElemList()))) { projectionNode.replaceWith(pipelineNode); } } }
@Override public Projection clone() { Projection clone = (Projection)super.clone(); clone.setProjectionElemList(getProjectionElemList().clone()); return clone; }
@Override protected BindingSet convert(BindingSet sourceBindings) throws QueryEvaluationException { return project(projection.getProjectionElemList(), sourceBindings, parentBindings, !isOuterProjection); }
@Override public void meet(Projection node) throws RepositoryException { TupleExpr arg = node.getArg(); if (arg instanceof StatementPattern && arg.getBindingNames().equals(node.getBindingNames())) { meetNode(node); } else { arg.visit(this); if (patternNode == null) return; Map<String, String> map = new HashMap<String, String>(); for (ProjectionElem e : node.getProjectionElemList().getElements()) { String source = variables.get(e.getSourceName()); if (source == null) { source = safe(e.getSourceName()); } map.put(e.getTargetName(), source); } this.variables = map; this.patternNode = node; } }
@Override public void meet(Projection node) throws RuntimeException { super.meet(node); if (node.getArg() instanceof SelectQuery) { SelectQuery query = (SelectQuery)node.getArg(); Map<String, String> bindingVars = new HashMap<String, String>(); List<SelectProjection> selection = new ArrayList<SelectProjection>(); ProjectionElemList list = node.getProjectionElemList(); for (ProjectionElem e : list.getElements()) { String source = e.getSourceName(); String target = e.getTargetName(); bindingVars.put(target, source); SelectProjection s = query.getSelectProjection(source); if (s != null) { selection.add(s); } } query.setBindingVars(bindingVars); query.setSqlSelectVar(selection); node.replaceWith(query); } }
private void meetNodeLocalParentOwned(StringBuilder builder, boolean mapping, Map<String, String> bindings, ProjectionElemList list, OwnedTupleExpr owned) throws RepositoryException, MalformedQueryException { owned.prepare(QueryLanguage.SPARQL, builder.toString(), bindings); if (mapping) { Projection proj = new Projection(owned.clone(), list); owned.replaceWith(proj); } }
/** * * 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; }
private UnaryTupleOperator visitTemplates(Resource templates) throws OpenRDFException { List<ProjectionElemList> projElemLists = new ArrayList<ProjectionElemList>(); Iteration<? extends Resource, QueryEvaluationException> iter = Statements.listResources(templates, store); while (iter.hasNext()) { Resource r = iter.next(); ProjectionElemList projElems = visitTemplate(r); projElemLists.add(projElems); } UnaryTupleOperator expr; if (projElemLists.size() > 1) { MultiProjection proj = new MultiProjection(); proj.setProjections(projElemLists); expr = proj; } else { Projection proj = new Projection(); proj.setProjectionElemList(projElemLists.get(0)); expr = proj; } Reduced reduced = new Reduced(); reduced.setArg(expr); tupleRoot = reduced; SingletonSet stub = new SingletonSet(); expr.setArg(stub); tupleNode = stub; return expr; }
private ParsedGraphQuery createGraphQuery(AugurStatementNode node) { TupleExpr tupleExpr = node.getTupleExpr(); String subjName = node.getSubjectName(); String predName = node.getPredicateName(); String objName = node.getObjectName(); String ctxName = node.getContextName(); ProjectionElem projSubj = new ProjectionElem(subjName, "subject"); ProjectionElem projPred = new ProjectionElem(predName, "predicate"); ProjectionElem projObj = new ProjectionElem(objName, "object"); ProjectionElem projCtx = new ProjectionElem(ctxName, "context"); ProjectionElemList projElemList = new ProjectionElemList(projSubj, projPred, projObj, projCtx); Projection proj = new Projection(tupleExpr, projElemList); ParsedGraphQuery query = new ParsedGraphQuery(proj); if (logger.isDebugEnabled()) { logger.debug(proj.toString()); } return query; }
result = new Projection(result, projElemList); ((Projection)result).setProjectionContext(graphPattern.getContextVar());
@Override public Set<String> getBindingNames() { return tupleExpr.getBindingNames(); }
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; } }
public Projection(TupleExpr arg, ProjectionElemList elements) { this(arg); setProjectionElemList(elements); }
final Multimap<String, BindingSet> bindingSetHashMap = HashMultimap.create(); HashJoinType joinType = HashJoinType.CONSTANT_JOIN_VAR; final Set<String> unAssuredVariables = Sets.difference(getTupleExpr().getBindingNames(), getTupleExpr().getAssuredBindingNames()); boolean useColumnScan = false; boolean isCrossProd = false; for (final String b : getTupleExpr().getAssuredBindingNames()) { final Binding v = bs.getBinding(b); if (v != null) {
@Override public String getSignature() { return "(External Projection) " + Joiner.on(", ").join(tupleExpr.getProjectionElemList().getElements()).replaceAll("\\s+", " "); }
@Override public void meet(Projection node) throws RepositoryException { TupleExpr arg = node.getArg(); if (arg instanceof StatementPattern && arg.getBindingNames().equals(node.getBindingNames())) { meetNode(node); } else { arg.visit(this); if (patternNode == null) { return; } Map<String, String> map = new HashMap<String, String>(); for (ProjectionElem e : node.getProjectionElemList().getElements()) { String source = variables.get(e.getSourceName()); if (source == null) { source = safe(e.getSourceName()); } map.put(e.getTargetName(), source); } this.variables = map; this.patternNode = node; } }