private Value toValue(FunctionCall node) { String funcName = node.getURI(); IRI funcUri = wellKnownFunctions.apply(funcName); if (funcUri == null) { funcUri = valueFactory.createIRI(funcName); } return funcUri; }
@Override public boolean equals(Object other) { if (other instanceof FunctionCall) { FunctionCall o = (FunctionCall)other; return uri.equals(o.getURI()) && args.equals(o.getArgs()); } return false; }
@Override public boolean equals(Object other) { if (other instanceof FunctionCall) { FunctionCall o = (FunctionCall)other; return uri.equals(o.getURI()) && args.equals(o.getArgs()); } return false; }
/** * Returns a PeriodicQueryNode for all {@link FunctionCall}s that represent PeriodicQueryNodes, otherwise * an empty Optional is returned. * @param functionCall - FunctionCall taken from a {@link TupleExpr} * @param arg - TupleExpr that will be the argument of the PeriodicQueryNode if it is created * @return - Optional containing a PeriodicQueryNode if FunctionCall represents PeriodicQueryNode and empty Optional otherwise * @throws Exception */ public static Optional<PeriodicQueryNode> getPeriodicQueryNode(FunctionCall functionCall, TupleExpr arg) throws Exception { if (functionCall.getURI().equals(PeriodicQueryURI)) { return Optional.of(parseAndSetValues(functionCall.getArgs(), arg)); } return Optional.empty(); }
/** * @inheritDoc */ @Override public void meet(FunctionCall theOp) throws Exception { mBuffer.append("<").append(theOp.getURI()).append(">("); boolean aFirst = true; for (ValueExpr aArg : theOp.getArgs()) { if (!aFirst) { mBuffer.append(", "); } else { aFirst = false; } aArg.visit(this); } mBuffer.append(")"); }
/** * @inheritDoc */ @Override public void meet(FunctionCall theOp) throws Exception { mBuffer.append(theOp.getURI()).append("("); boolean aFirst = true; for (ValueExpr aArg : theOp.getArgs()) { if (!aFirst) { mBuffer.append(", "); } else { aFirst = false; } aArg.visit(this); } mBuffer.append(")"); }
/** * @inheritDoc */ @Override public void meet(FunctionCall theOp) throws Exception { mBuffer.append("<").append(theOp.getURI()).append(">("); boolean aFirst = true; for (ValueExpr aArg : theOp.getArgs()) { if (!aFirst) { mBuffer.append(", "); } else { aFirst = false; } aArg.visit(this); } mBuffer.append(")"); }
/** * @inheritDoc */ @Override public void meet(FunctionCall theOp) throws Exception { mBuffer.append(theOp.getURI()).append("("); boolean aFirst = true; for (ValueExpr aArg : theOp.getArgs()) { if (!aFirst) { mBuffer.append(", "); } else { aFirst = false; } aArg.visit(this); } mBuffer.append(")"); }
/** * @inheritDoc */ @Override public void meet(FunctionCall theOp) throws Exception { mBuffer.append("<").append(theOp.getURI()).append(">("); boolean aFirst = true; for (ValueExpr aArg : theOp.getArgs()) { if (!aFirst) { mBuffer.append(", "); } else { aFirst = false; } aArg.visit(this); } mBuffer.append(")"); }
/** * @inheritDoc */ @Override public void meet(FunctionCall theOp) throws Exception { mBuffer.append(theOp.getURI()).append("("); boolean aFirst = true; for (ValueExpr aArg : theOp.getArgs()) { if (!aFirst) { mBuffer.append(", "); } else { aFirst = false; } aArg.visit(this); } mBuffer.append(")"); }
@Override public void meet(final FunctionCall fn) { final IRI fun = VF.createIRI(fn.getURI()); final Var result = IndexingFunctionRegistry.getResultVarFromFunctionCall(fun, fn.getArgs()); if (result != null && !searchProperties.contains(result)) { searchProperties.add(result); } } }
/** * Determines if the provided zero-arg function is a function that should return a constant value for * the entire query execution (e.g NOW()), or if it should generate a new value for every call (e.g. * RAND()). * * @param functionCall * a zero-arg function call. * @return <code>true<code> iff the provided function returns a constant value for the query execution, <code>false</code> * otherwise. */ private boolean isConstantZeroArgFunction(FunctionCall functionCall) { Function function = FunctionRegistry.getInstance().get(functionCall.getURI()).orElseThrow( () -> new QueryEvaluationException( "Unable to find function with the URI: " + functionCall.getURI())); // we treat constant functions as the 'regular case' and make // exceptions for specific SPARQL built-in functions that require // different treatment. if (function instanceof Rand || function instanceof UUID || function instanceof STRUUID) { return false; } return true; }
@Override public void meet(FunctionCall node) throws IncompatibleOperationException { if (HALYARD.PARALLEL_SPLIT_FUNCTION.toString().equals(node.getURI())) { throw new IncompatibleOperationException(); } super.meet(node); } @Override
/** * Evaluates a function. */ private Value evaluate(FunctionCall node, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException { Optional<Function> function = FunctionRegistry.getInstance().get(node.getURI()); if (!function.isPresent()) { throw new QueryEvaluationException("Unknown function '" + node.getURI() + "'"); } // the NOW function is a special case as it needs to keep a shared return // value for the duration of the query. if (function.get() instanceof Now) { return evaluate((Now) function.get(), bindings); } List<ValueExpr> args = node.getArgs(); Value[] argValues = new Value[args.size()]; for (int i = 0; i < args.size(); i++) { argValues[i] = evaluate(args.get(i), bindings); } return function.get().evaluate(valueFactory, argValues); }
@Override public void meet(FunctionCall node) throws IllegalArgumentException { if (PARALLEL_SPLIT_FUNCTION.toString().equals(node.getURI())) { List<ValueExpr> args = node.getArgs(); if (args.size() < 2) throw new IllegalArgumentException(PARALLEL_SPLIT_FUNCTION.getLocalName() + " function has at least two mandatory arguments: <constant number of parallel forks> and <binding variable(s) to filter by>"); try { int num = Integer.parseInt(((ValueConstant)args.get(0)).getValue().stringValue()); if (num < 1) throw new NullPointerException(); if (forks == 0) { forks = num; } else if (forks != num) { throw new IllegalArgumentException(PARALLEL_SPLIT_FUNCTION.getLocalName() + " function is used twice with different first argument (number of forks)"); } } catch (ClassCastException | NullPointerException | NumberFormatException ex) { throw new IllegalArgumentException(PARALLEL_SPLIT_FUNCTION.getLocalName() + " function first argument (number of forks) must be integer constant >0"); } } } }
/** * Evaluates a function. */ public Value evaluate(FunctionCall node, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException { Function function = FunctionRegistry.getInstance().get(node.getURI()).orElseThrow( () -> new QueryEvaluationException("Unknown function '" + node.getURI() + "'")); // the NOW function is a special case as it needs to keep a shared // return // value for the duration of the query. if (function instanceof Now) { return evaluate((Now)function, bindings); } List<ValueExpr> args = node.getArgs(); Value[] argValues = new Value[args.size()]; for (int i = 0; i < args.size(); i++) { argValues[i] = evaluate(args.get(i), bindings); } return function.evaluate(tripleSource.getValueFactory(), argValues); }
@Override public void meet(final FunctionCall call) { final IRI fnUri = VF.createIRI(call.getURI()); final Var resultVar = IndexingFunctionRegistry.getResultVarFromFunctionCall(fnUri, call.getArgs()); if (resultVar != null && resultVar.getName().equals(matchVar)) { addFilter(VF.createIRI(call.getURI()), extractArguments(matchVar, call)); if (call.getParentNode() instanceof Filter || call.getParentNode() instanceof And || call.getParentNode() instanceof LeftJoin) { call.replaceWith(new ValueConstant(VF.createLiteral(true))); } else { throw new IllegalArgumentException("Query error: Found " + call + " as part of an expression that is too complex"); } } }
@Override public void meet(FunctionCall node) throws RDF4JException { String name = node.getURI(); if (!functionRegistry.has(name)) { IRI funcUri = vf.createIRI(name); Function f = parser.parseFunction(funcUri, tripleSource); functionRegistry.add(f); } super.meet(node); } }
@Override public void meet(FunctionCall node) throws RDF4JException { String name = node.getURI(); if (!functionRegistry.has(name)) { IRI funcUri = vf.createIRI(name); Function f = parser.parseFunction(funcUri, tripleSource); functionRegistry.add(f); } super.meet(node); } }
@Override public void meet(final Filter node) throws QueryRulesetException { final ValueExpr condition = node.getCondition(); // If the condition is a function call, and we don't know about the function, don't try to test for it. if (condition instanceof FunctionCall) { final String uri = ((FunctionCall) condition).getURI(); if (FunctionRegistry.getInstance().get(uri) == null) { // Just extract statement patterns from the child as if there were no filter. node.getArg().visit(this); } } // Otherwise, assume we can test for it: extract rules from below this node, and add the condition to each one. else { final RulesetVisitor childVisitor = new RulesetVisitor(); node.getArg().visit(childVisitor); for (final CopyRule rule : childVisitor.rules) { rule.addCondition(condition); rules.add(rule); } superclasses.addAll(childVisitor.superclasses); superproperties.addAll(childVisitor.superproperties); } }