use of org.apache.jena.sparql.expr.E_LessThan 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.expr.E_LessThan in project jena by apache.
the class SolutionModifierTest method testAddHavingString.
@ContractTest
public void testAddHavingString() throws ParseException {
SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
AbstractQueryBuilder<?> builder = solutionModifier.addHaving("?foo<10");
Query query = builder.build();
assertTrue(query.hasHaving());
List<Expr> having = query.getHavingExprs();
assertEquals(1, having.size());
Expr exp = having.get(0);
assertTrue(exp.isFunction());
assertTrue(exp.getFunction() instanceof E_LessThan);
List<Expr> args = exp.getFunction().getArgs();
assertEquals(new ExprVar("foo"), args.get(0));
assertEquals(new NodeValueInteger(10), args.get(1));
builder = solutionModifier.addHaving("?bar < 10");
query = builder.build();
assertTrue(query.hasHaving());
having = query.getHavingExprs();
assertEquals(2, having.size());
exp = having.get(0);
assertTrue(exp.isFunction());
assertTrue(exp.getFunction() instanceof E_LessThan);
args = exp.getFunction().getArgs();
assertEquals(new ExprVar("foo"), args.get(0));
assertEquals(new NodeValueInteger(10), args.get(1));
exp = having.get(1);
assertTrue(exp.isFunction());
assertTrue(exp.getFunction() instanceof E_LessThan);
args = exp.getFunction().getArgs();
assertEquals(new ExprVar("bar"), args.get(0));
assertEquals(new NodeValueInteger(10), args.get(1));
}
use of org.apache.jena.sparql.expr.E_LessThan 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.expr.E_LessThan in project jena by apache.
the class ExprFactoryTest method ltTest.
@Test
public void ltTest() {
Expr e = factory.lt(factory.none(), factory.none());
assertTrue(e instanceof E_LessThan);
}
use of org.apache.jena.sparql.expr.E_LessThan in project jena by apache.
the class AlgebraExec method main.
public static void main(String[] argv) {
String BASE = "http://example/";
BasicPattern bp = new BasicPattern();
Var var_x = Var.alloc("x");
Var var_z = Var.alloc("z");
// ---- Build expression
bp.add(new Triple(var_x, NodeFactory.createURI(BASE + "p"), var_z));
Op op = new OpBGP(bp);
//Expr expr = ExprUtils.parse("?z < 2 ") ;
Expr expr = new E_LessThan(new ExprVar(var_z), NodeValue.makeNodeInteger(2));
op = OpFilter.filter(expr, op);
// ---- Example setup
Model m = makeModel();
m.write(System.out, "TTL");
System.out.println("--------------");
System.out.print(op);
System.out.println("--------------");
// ---- Execute expression
QueryIterator qIter = Algebra.exec(op, m.getGraph());
// -------- Either read the query iterator directly ...
if (false) {
for (; qIter.hasNext(); ) {
Binding b = qIter.nextBinding();
Node n = b.get(var_x);
System.out.println(NodeFmtLib.displayStr(n));
System.out.println(b);
}
qIter.close();
} else {
// -------- Or make ResultSet from it (but not both - reading an
// iterator consumes the current solution)
List<String> varNames = new ArrayList<>();
varNames.add("x");
varNames.add("z");
ResultSet rs = new ResultSetStream(varNames, m, qIter);
ResultSetFormatter.out(rs);
qIter.close();
}
System.exit(0);
}
Aggregations