use of org.apache.jena.sparql.expr.Expr in project jena by apache.
the class TransformFilterPlacement method placeProject.
private Placement placeProject(ExprList exprs, OpProject input) {
Collection<Var> varsProject = input.getVars();
ExprList pushed = new ExprList();
ExprList unpushed = new ExprList();
for (Expr expr : exprs) {
Set<Var> exprVars = expr.getVarsMentioned();
if (varsProject.containsAll(exprVars))
pushed.add(expr);
else
unpushed.add(expr);
}
if (pushed.isEmpty())
return resultNoChange(input);
// (filter (project ...)) ===> (project (filter ...))
return processSubOp1(pushed, unpushed, input);
}
use of org.apache.jena.sparql.expr.Expr in project jena by apache.
the class TransformFilterPlacement method placeUnion.
private Placement placeUnion(ExprList exprs, OpUnion input) {
if (false) {
// Push into both sides without thinking.
// Left as a safety fallback.
Op left = input.getLeft();
Placement pLeft = transform(exprs, left);
Op right = input.getRight();
Placement pRight = transform(exprs, right);
if (pLeft != null && !pLeft.unplaced.isEmpty())
return noChangePlacement;
if (pRight != null && !pRight.unplaced.isEmpty())
return noChangePlacement;
// Must be guarded by the above.
left = transformOpAlways(exprs, left);
right = transformOpAlways(exprs, right);
Op op2 = OpUnion.create(left, right);
return result(op2, emptyList);
}
Op left = input.getLeft();
Placement pLeft = transform(exprs, left);
Op right = input.getRight();
Placement pRight = transform(exprs, right);
// If it's placed in neither arm it should be passed back out for placement.
//
// If it's done in both arms, then expression can be left pushed in
// and not passed back out for placement.
// If it is done in one arm and not the other, then it can be left pushed
// in but needs to be redone for the other arm as if it were no placed at all.
// A filter applied twice is safe.
ExprList exprs2 = null;
for (Expr expr : exprs) {
boolean unplacedLeft = (isNoChange(pLeft) || pLeft.unplaced.getList().contains(expr));
boolean unplacedRight = (isNoChange(pRight) || pRight.unplaced.getList().contains(expr));
// if ( unplacedLeft && unplacedRight ) {
// System.out.println("Unplaced: "+expr) ;
// } else if ( unplacedLeft ) {
// System.out.println("Unplaced(L): "+expr) ;
// } else if ( unplacedRight ) {
// System.out.println("Unplaced(R): "+expr) ;
// } else
// System.out.println("Placed(L+R): "+expr) ;
boolean placed = !unplacedLeft && !unplacedRight;
if (placed)
// Went into both arms - expression has been handled completely.
continue;
if (exprs2 == null)
exprs2 = new ExprList();
exprs2.add(expr);
}
Op newLeft = (pLeft == null) ? left : pLeft.op;
Op newRight = (pRight == null) ? right : pRight.op;
if (exprs2 == null)
exprs2 = emptyList;
//Op op2 = OpUnion.create(newLeft, newRight) ;
Op op2 = input.copy(newLeft, newRight);
return result(op2, exprs2);
}
use of org.apache.jena.sparql.expr.Expr in project jena by apache.
the class VariableUsageVisitor method visit.
@Override
public void visit(OpLeftJoin opLeftJoin) {
Collection<Var> vars = new ArrayList<>();
if (opLeftJoin.getExprs() != null) {
for (Expr expr : opLeftJoin.getExprs().getList()) {
ExprVars.varsMentioned(vars, expr);
}
}
action(vars);
}
use of org.apache.jena.sparql.expr.Expr in project jena by apache.
the class TestFunctions2 method test.
private static void test(String string, String result) {
Expr expr = ExprUtils.parse(string, pmap);
NodeValue nv = expr.eval(null, new FunctionEnvBase());
Node r = NodeFactoryExtra.parseNode(result);
NodeValue nvr = NodeValue.makeNode(r);
assertTrue("Not same value: Expected: " + nvr + " : Actual = " + nv, NodeValue.sameAs(nvr, nv));
// test result must be lexical form exact.
assertEquals(r, nv.asNode());
}
use of org.apache.jena.sparql.expr.Expr in project jena by apache.
the class TestExpressions method testEval.
private static void testEval(String string) {
Expr expr = parse(string);
NodeValue v = expr.eval(BindingFactory.binding(), new FunctionEnvBase());
}
Aggregations