use of org.apache.jena.sparql.syntax.ElementFilter in project jena by apache.
the class ElementRewriter method visit.
@Override
public void visit(ElementFilter el) {
ExprRewriter exprRewriter = new ExprRewriter(values);
el.getExpr().visit(exprRewriter);
push(new ElementFilter(exprRewriter.getResult()));
}
use of org.apache.jena.sparql.syntax.ElementFilter in project jena by apache.
the class WhereHandlerTest method testAddFilterVarOnly.
@Test
public void testAddFilterVarOnly() throws ParseException {
handler.addFilter("?one");
handler.build();
ExprFactory fact = new ExprFactory();
WhereValidator visitor = new WhereValidator(new ElementFilter(fact.asExpr("?one")));
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementFilter in project jena by apache.
the class WhereHandlerTest method testSetVarsInFilter.
@Test
public void testSetVarsInFilter() throws ParseException {
handler.addFilter("?one < ?v");
handler.build();
E_LessThan expr = new ExprFactory().lt(NodeFactory.createVariable("one"), NodeFactory.createVariable("v"));
WhereValidator visitor = new WhereValidator(new ElementFilter(expr));
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
Map<Var, Node> values = new HashMap<>();
values.put(Var.alloc("v"), NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(10)));
handler.setVars(values);
handler.build();
expr = new ExprFactory().lt(NodeFactory.createVariable("one"), NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(10)));
visitor = new WhereValidator(new ElementFilter(expr));
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementFilter in project jena by apache.
the class WhereClauseTest method testSetVarsInFilter.
@ContractTest
public void testSetVarsInFilter() throws ParseException {
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addFilter("?one < ?v");
ExprVar one = new ExprVar(NodeFactory.createVariable("one"));
ExprVar v = new ExprVar(NodeFactory.createVariable("v"));
Expr expr = new E_LessThan(one, v);
ElementFilter filter = new ElementFilter(expr);
WhereValidator visitor = new WhereValidator(filter);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
Node literal = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(10));
builder.setVar(Var.alloc("v"), literal);
NodeValueInteger lit = new NodeValueInteger(10);
expr = new E_LessThan(one, lit);
filter = new ElementFilter(expr);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementFilter in project jena by apache.
the class WhereHandlerTest method testAddFilter.
@Test
public void testAddFilter() throws ParseException {
handler.addFilter("?one < 10");
handler.build();
BigInteger bi = new BigInteger(Integer.toString(10));
E_LessThan expr = new ExprFactory().lt(NodeFactory.createVariable("one"), bi);
WhereValidator visitor = new WhereValidator(new ElementFilter(expr));
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
Aggregations