@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"); } } }
throws SailException if (f.getURI().startsWith(GEOF.NAMESPACE)) { List<ValueExpr> args = f.getArgs(); if (args.size() != 2) { return; QueryModelNode parent = f.getParentNode(); if (parent instanceof ExtensionElem) { fVar = ((ExtensionElem)parent).getName(); spec.setRelation(f.getURI()); spec.setFunctionParent(parent); spec.setQueryGeometry(qshape);
private Value toValue(FunctionCall node) { String funcName = node.getURI(); IRI funcUri = wellKnownFunctions.apply(funcName); if (funcUri == null) { funcUri = valueFactory.createIRI(funcName); } return funcUri; }
private FunctionCall createFunctionCall(String uri, SimpleNode node, int minArgs, int maxArgs) throws VisitorException { FunctionCall functionCall = new FunctionCall(uri); int noOfArguments = node.jjtGetNumChildren(); if (noOfArguments > maxArgs || noOfArguments < minArgs) { throw new VisitorException( "unexpected number of arguments (" + noOfArguments + ") for function " + uri); } for (int i = 0; i < noOfArguments; i++) { Node argNode = node.jjtGetChild(i); functionCall.addArg((ValueExpr)argNode.jjtAccept(this, null)); } return functionCall; }
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; }
super.meet(functionCall); List<ValueExpr> args = functionCall.getArgs(); functionCall.replaceWith(new ValueConstant(value));
expr = new FunctionCall(funcName, args);
public void addArgs(ValueExpr... args) { for (ValueExpr arg : args) { addArg(arg); } }
throws SailException if (GEOF.DISTANCE.stringValue().equals(f.getURI())) { List<ValueExpr> args = f.getArgs(); if (args.size() != 3) { return; ValueExpr dist = null; String distanceVar = null; QueryModelNode parent = f.getParentNode(); if (parent instanceof ExtensionElem) { distanceVar = ((ExtensionElem)parent).getName();
/** * 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; }
private FunctionCall createFunctionCall(String uri, SimpleNode node, int minArgs, int maxArgs) throws VisitorException { FunctionCall functionCall = new FunctionCall(uri); int noOfArguments = node.jjtGetNumChildren(); if (noOfArguments > maxArgs || noOfArguments < minArgs) { throw new VisitorException( "unexpected number of arguments (" + noOfArguments + ") for function " + uri); } for (int i = 0; i < noOfArguments; i++) { Node argNode = node.jjtGetChild(i); functionCall.addArg((ValueExpr)argNode.jjtAccept(this, null)); } return functionCall; }
public DistanceQuerySpec(FunctionCall distanceFunction, ValueExpr distanceExpr, String distVar, Filter filter) { this.distanceFunction = distanceFunction; this.distanceExpr = distanceExpr; this.distanceVar = distVar; this.filter = filter; if (distanceFunction != null) { List<ValueExpr> args = distanceFunction.getArgs(); this.from = getLiteral(args.get(0)); this.geoVar = getVarName(args.get(1)); this.units = getURI(args.get(2)); } else { this.from = null; this.geoVar = null; this.units = null; } if (distanceExpr != null) { Literal dist = getLiteral(distanceExpr); this.distance = (dist != null) ? dist.doubleValue() : Double.NaN; } else { this.distance = Double.NaN; } }
super.meet(functionCall); List<ValueExpr> args = functionCall.getArgs(); functionCall.replaceWith(new ValueConstant(value));
@Test public void periodicNodeNotPresentTest() throws Exception { List<ValueExpr> values = Arrays.asList(new Var("time"), new ValueConstant(VF.createLiteral(12.0)), new ValueConstant(VF.createLiteral(6.0)), new ValueConstant(VF.createIRI(PeriodicQueryUtil.temporalNameSpace + "hours"))); FunctionCall func = new FunctionCall("uri:func", values); Optional<PeriodicQueryNode> node1 = PeriodicQueryUtil.getPeriodicQueryNode(func, new Join()); Assert.assertEquals(false, node1.isPresent()); }
public void addArgs(Iterable<ValueExpr> args) { for (ValueExpr arg : args) { addArg(arg); } }
/** * 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; }
private FunctionCall createFunctionCall(String uri, SimpleNode node, int minArgs, int maxArgs) throws VisitorException { FunctionCall functionCall = new FunctionCall(uri); int noOfArguments = node.jjtGetNumChildren(); if (noOfArguments > maxArgs || noOfArguments < minArgs) { throw new VisitorException( "unexpected number of arguments (" + noOfArguments + ") for function " + uri); } for (int i = 0; i < noOfArguments; i++) { Node argNode = node.jjtGetChild(i); functionCall.addArg((ValueExpr)argNode.jjtAccept(this, null)); } return functionCall; }