@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 toValue(FunctionCall node) { String funcName = node.getURI(); IRI funcUri = wellKnownFunctions.apply(funcName); if (funcUri == null) { funcUri = valueFactory.createIRI(funcName); } return funcUri; }
/** * Returns a PeriodicQueryNode for all {@link FunctionCall}s that represent PeriodicQueryNodes, otherwise * an empty Optional is returned. * @param functionCall - FunctionCall taken from a {@lin 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(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(")"); }
@Override public void meet(final FunctionCall n) { final String uri = n.getURI(); String name = NAMES.get(uri); if (name == null && NAMES.values().contains(uri.toUpperCase())) { name = n.getURI().toUpperCase(); } emit(name != null ? name : new URIImpl(uri)).emit("(").emit(n.getArgs(), ", ") .emit(")"); }
@Override public void meet(final FunctionCall n) { final String uri = n.getURI(); String name = NAMES.get(uri); if (name == null && NAMES.values().contains(uri.toUpperCase())) { name = n.getURI().toUpperCase(); } emit(name != null ? name : new URIImpl(uri)).emit("(").emit(n.getArgs(), ", ") .emit(")"); }
@Override public void meet(final FunctionCall fn) { final URI fun = new URIImpl(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 fc) throws RuntimeException { NativeFunction nf = NativeFunctionRegistry.getInstance().get(fc.getURI()); if (nf != null) { optypes.add(nf.getReturnType()); } }
/** * 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(FunctionCall node) throws RuntimeException { NativeFunction nf = NativeFunctionRegistry.getInstance().get(node.getURI()); if(node.getArgs().size() > 0 && nf.getReturnType() == ValueType.STRING) { node.getArgs().get(0).visit(this); } // otherwise stop here, the function call hides the type and language anyways }
@Override public void meet(FunctionCall fc) throws RuntimeException { if((XMLSchema.DOUBLE.toString().equals(fc.getURI()) || XMLSchema.FLOAT.toString().equals(fc.getURI()) ) && fc.getArgs().size() == 1) { optypes.push(ValueType.DOUBLE); fc.getArgs().get(0).visit(this); optypes.pop(); } else if((XMLSchema.INTEGER.toString().equals(fc.getURI()) || XMLSchema.INT.toString().equals(fc.getURI())) && fc.getArgs().size() == 1) { optypes.push(ValueType.INT); fc.getArgs().get(0).visit(this); optypes.pop(); } else if(XMLSchema.BOOLEAN.toString().equals(fc.getURI()) && fc.getArgs().size() == 1) { optypes.push(ValueType.BOOL); fc.getArgs().get(0).visit(this); optypes.pop(); } else if(XMLSchema.DATE.toString().equals(fc.getURI()) && fc.getArgs().size() == 1) { optypes.push(ValueType.DATE); fc.getArgs().get(0).visit(this); } else { String fnUri = fc.getURI();
@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(BooleanLiteralImpl.TRUE)); } } }
@Override public void meet(final FunctionCall call) { final URI fnUri = valueFactory.createURI(call.getURI()); final Var resultVar = IndexingFunctionRegistry.getResultVarFromFunctionCall(fnUri, call.getArgs()); if (resultVar != null && resultVar.getName().equals(matchVar)) { addFilter(valueFactory.createURI(call.getURI()), extractArguments(matchVar, call)); if (call.getParentNode() instanceof Filter || call.getParentNode() instanceof And || call.getParentNode() instanceof LeftJoin) { call.replaceWith(new ValueConstant(valueFactory.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) { handleType(SeRQO.FUNCTIONCALL); handleLiteral(SeRQO.URI, node.getURI()); handleChildList(SeRQO.ARGS, node.getArgs()); super.meet(node); }
@Override public void meet(FunctionCall node) throws OpenRDFException { 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(Filter filter) { super.meet(filter); if(filter.getCondition() instanceof FunctionCall) { String uri = ((FunctionCall) filter.getCondition()).getURI(); if(NativeFunctionRegistry.getInstance().get(uri) != null) { FilterRelocator.relocate(filter); } } else { FilterRelocator.relocate(filter); } } }