@Override public void meet(ExtensionElem node) throws RuntimeException { if(node.getName().equals(needle)) { found = true; } // don't recurse to the children, as this would project non-grouped elements }
@Override public Set<String> getBindingNames() { Set<String> bindingNames = new LinkedHashSet<String>(arg.getBindingNames()); for (ExtensionElem pe : elements) { bindingNames.add(pe.getName()); } return bindingNames; }
@Override public boolean equals(Object other) { if (other instanceof ExtensionElem) { ExtensionElem o = (ExtensionElem)other; return name.equals(o.getName()) && expr.equals(o.getExpr()); } return false; }
/** * @inheritDoc */ @Override public void meet(final ExtensionElem theExtensionElem) throws Exception { mExtensions.put(theExtensionElem.getName(), theExtensionElem.getExpr()); }
@Override public void meet(ExtensionElem node) throws RuntimeException { neededVariables.add(node.getName()); valueNeeded++; super.meet(node); valueNeeded--; }
@Override public void meet(Extension node) { extension = node; List<ExtensionElem> elements = node.getElements(); // NB: preserve ExtensionElem order extensionExprs = new LinkedHashMap<String, ValueExpr>(elements.size()); for (ExtensionElem elem : elements) { extensionExprs.put(elem.getName(), elem.getExpr()); } }
@Override public void meet(final ExtensionElem node) throws RuntimeException { if (node.getName().equals(name)) { result.set(node.getExpr()); } else { super.meet(node); } }
@Override public void meet(final ExtensionElem node) throws RuntimeException { if (node.getName().equals(name)) { result.set(node.getExpr()); } else { super.meet(node); } }
@Override public void meet(Extension node) throws RuntimeException { // visit children before, as there might be dependencies super.meet(node); for(ExtensionElem elem : node.getElements()) { if(elem.getExpr() instanceof Var && ((Var) elem.getExpr()).getName().equals(elem.getName())) { log.debug("ignoring self-aliasing of variable {}", elem.getName()); } else { elements.add(elem); } } }
/** * Constructs an instance of {@link ProjectionEvaluator}. * * @param projectionElems - Defines the structure of the resulting value. (not null) * @param extensions - Extra information about the projection elements when there are anonymous constants or blank * nodes within the projection elements. (not null) */ public ProjectionEvaluator(final ProjectionElemList projectionElems, final Optional<Extension> extensions) { this.projectionElems = requireNonNull(projectionElems); requireNonNull(extensions); // Find all extensions that represent constant insertions. if(extensions.isPresent()) { for(final ExtensionElem extensionElem : extensions.get().getElements()) { final ValueExpr valueExpr = extensionElem.getExpr(); // If the extension is a ValueConstant, store it so that they may be added to the binding sets. if(valueExpr instanceof ValueConstant) { final String sourceName = extensionElem.getName(); final Value targetValue = ((ValueConstant) valueExpr).getValue(); constantSources.put(sourceName, targetValue); } // If the extension is a BNodeGenerator, keep track of the name so that we know we have to generate an ID for it. else if(valueExpr instanceof BNodeGenerator) { final String sourceName = extensionElem.getName(); anonymousSources.add( sourceName ); } } } }
private static Map<String, ExtensionElem> extractExtensions(final TupleExpr rootNode) { final Map<String, ExtensionElem> map = Maps.newHashMap(); for (final UnaryTupleOperator node : extractQueryNodes(rootNode, true)) { if (node instanceof Extension) { for (final ExtensionElem elem : ((Extension) node).getElements()) { final String variable = elem.getName(); final ValueExpr expression = elem.getExpr(); if (!(expression instanceof Var) || !((Var) expression).getName().equals(variable)) { map.put(variable, elem); } } } } return map; }
private static Map<String, ExtensionElem> extractExtensions(final TupleExpr rootNode) { final Map<String, ExtensionElem> map = new HashMap<>(); for (final UnaryTupleOperator node : extractQueryNodes(rootNode, true)) { if (node instanceof Extension) { for (final ExtensionElem elem : ((Extension) node).getElements()) { final String variable = elem.getName(); final ValueExpr expression = elem.getExpr(); if (!(expression instanceof Var) || !((Var) expression).getName().equals(variable)) { map.put(variable, elem); } } } } return map; }
/** * Make a {@link MultiProjectionEvaluator} that processes the logic of a {@link MultiProjection}. * * @param multiProjection - Defines the projections that will be processed. (not null) * @param bNodeIdFactory - Creates the IDs for Blank Nodes. (not null) * @return A {@link MultiProjectionEvaluator} for the provided {@link MultiProjection}. */ public static MultiProjectionEvaluator make(final MultiProjection multiProjection, final BNodeIdFactory bNodeIdFactory) { requireNonNull(multiProjection); // Figure out if there are extensions. final TupleExpr arg = multiProjection.getArg(); final Optional<Extension> extension = (arg instanceof Extension) ? Optional.of((Extension)arg): Optional.empty(); // If there are, iterate through them and find any blank node source names. final Set<String> blankNodeSourceNames = new HashSet<>(); if(extension.isPresent()) { for(final ExtensionElem elem : extension.get().getElements()) { if(elem.getExpr() instanceof BNodeGenerator) { blankNodeSourceNames.add( elem.getName() ); } } } // Create a ProjectionEvaluator for each projection that is part of the multi. final Set<ProjectionEvaluator> projections = new HashSet<>(); for(final ProjectionElemList projectionElemList : multiProjection.getProjections()) { projections.add( new ProjectionEvaluator(projectionElemList, extension) ); } return new MultiProjectionEvaluator(projections, blankNodeSourceNames, bNodeIdFactory); }
private ConstructGraph getConstructGraph(final List<ProjectionElemList> projections, final List<ExtensionElem> extensionElems) { final Map<String, Value> valueMap = new HashMap<>(); //create valueMap to associate source names with Values for(final ExtensionElem elem: extensionElems) { final String name = elem.getName(); final ValueExpr expr = elem.getExpr(); if(expr instanceof ValueConstant) { final Value value = ((ValueConstant) expr).getValue(); valueMap.put(name, value); } else if(expr instanceof BNodeGenerator) { valueMap.put(name, new BNodeImpl(UUID.randomUUID().toString())); } } final Set<ConstructProjection> constructProj = new HashSet<>(); //build ConstructProjection for each ProjectionElemList for(final ProjectionElemList list: projections) { validateProjectionElemList(list); final List<Var> vars = new ArrayList<>(); for(final ProjectionElem elem: list.getElements()) { final String sourceName = elem.getSourceName(); final Var var = new Var(sourceName); if(valueMap.containsKey(sourceName)) { var.setValue(valueMap.get(sourceName)); } vars.add(var); } constructProj.add(new ConstructProjection(vars.get(0), vars.get(1), vars.get(2))); } return new ConstructGraph(constructProj); }
@Override public void meet(ExtensionElem node) { handleType(SeRQO.EXTENSIONELEM); handleLiteral(SeRQO.NAME, node.getName()); handleChild(SeRQO.ARG, node.getExpr()); super.meet(node); }
@Override public void meet(final Extension n) { emit(n.getArg()); if (!(n.getArg() instanceof SingletonSet)) { newline(); } boolean first = true; for (final ExtensionElem e : n.getElements()) { final ValueExpr expr = e.getExpr(); if (!(expr instanceof Var) || !((Var) expr).getName().equals(e.getName())) { if (!first) { newline(); } emit("BIND (").emit(expr).emit(" AS ?").emit(e.getName()).emit(")"); first = false; } } }
@Override public void meet(final Extension n) { emit(n.getArg()); if (!(n.getArg() instanceof SingletonSet)) { newline(); } boolean first = true; for (final ExtensionElem e : n.getElements()) { final ValueExpr expr = e.getExpr(); if (!(expr instanceof Var) || !((Var) expr).getName().equals(e.getName())) { if (!first) { newline(); } emit("BIND (").emit(expr).emit(" AS ?").emit(e.getName()).emit(")"); first = false; } } }
QueryModelNode parent = f.getParentNode(); if(parent instanceof ExtensionElem) { fVar = ((ExtensionElem)parent).getName(); QueryModelNode extension = parent.getParentNode(); filter = getFilter(extension.getParentNode(), fVar);
@Override public void meet(ExtensionElem node) throws RDFHandlerException { listEntry(); handler.handleStatement(valueFactory.createStatement(subject, RDF.TYPE, SP.BIND_CLASS)); Resource var = getVar(node.getName()); handler.handleStatement(valueFactory.createStatement(subject, SP.VARIABLE_PROPERTY, var)); meet(node.getExpr()); }
@Override public BindingSet convert(BindingSet sourceBindings) throws QueryEvaluationException { QueryBindingSet targetBindings = new QueryBindingSet(sourceBindings); for (ExtensionElem extElem : extension.getElements()) { ValueExpr expr = extElem.getExpr(); if (!(expr instanceof AggregateOperator)) { try { // we evaluate each extension element over the targetbindings, so that bindings from // a previous extension element in this same extension can be used by other extension elements. // e.g. if a projection contains (?a + ?b as ?c) (?c * 2 as ?d) Value targetValue = strategy.evaluate(extElem.getExpr(), targetBindings); if (targetValue != null) { // Potentially overwrites bindings from super targetBindings.setBinding(extElem.getName(), targetValue); } } catch (ValueExprEvaluationException e) { // silently ignore type errors in extension arguments. They should not cause the // query to fail but just result in no additional binding. } } } return targetBindings; } }