@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; }
private Value[] extractArguments(final String matchName, final FunctionCall call) { final Value args[] = new Value[call.getArgs().size() - 1]; int argI = 0; for (int i = 0; i != call.getArgs().size(); ++i) { final ValueExpr arg = call.getArgs().get(i); if (argI == i && arg instanceof Var && matchName.equals(((Var)arg).getName())) { continue; } if (arg instanceof ValueConstant) { args[argI] = ((ValueConstant)arg).getValue(); } else if (arg instanceof Var && ((Var)arg).hasValue()) { args[argI] = ((Var)arg).getValue(); } else { throw new IllegalArgumentException("Query error: Found " + arg + ", expected a Literal, BNode or URI"); } ++argI; } return args; }
/** * 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("<").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(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); } } }
@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. */ 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 RDFHandlerException { Resource currentSubj = subject; flushPendingStatement(); handler.handleStatement(valueFactory.createStatement(subject, RDF.TYPE, toValue(node))); List<ValueExpr> args = node.getArgs(); for (int i = 0; i < args.size(); i++) { predicate = toArgProperty(i + 1); args.get(i).visit(this); } subject = currentSubj; predicate = null; }
@Override public void meet(final Filter node) throws Exception { super.meet(node); final ValueExpr arg = node.getCondition(); if (arg instanceof FunctionCall) { final FunctionCall fc = (FunctionCall) arg; if (RANGE.stringValue().equals(fc.getURI())) { //range(?var, start, end) final List<ValueExpr> valueExprs = fc.getArgs(); if (valueExprs.size() != 3) { throw new QueryEvaluationException("org.apache:range must have 3 parameters: variable, start, end"); } final Var var = (Var) valueExprs.get(0); final ValueConstant startVc = (ValueConstant) valueExprs.get(1); final ValueConstant endVc = (ValueConstant) valueExprs.get(2); final Value start = startVc.getValue(); final Value end = endVc.getValue(); rangeValues.put(var, new RangeValue(start, end)); node.setCondition(new ValueConstant(BooleanLiteral.TRUE)); } } }
/** * 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); }
/** * 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"); } } }