Search in sources :

Example 6 with ExprVar

use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.

the class TransformElementLib method applyVar.

public static Var applyVar(Var v, ExprTransform exprTransform) {
    if (exprTransform == null)
        return v;
    ExprVar expr = new ExprVar(v);
    Expr e = exprTransform.transform(expr);
    if (e instanceof ExprVar)
        return ((ExprVar) e).asVar();
    throw new InternalErrorException("Managed to turn a variable " + v + " into " + e);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Example 7 with ExprVar

use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.

the class TestQueryIterSort method setup.

@Before
public void setup() {
    random = new Random();
    Var[] vars = new Var[] { Var.alloc("1"), Var.alloc("2"), Var.alloc("3"), Var.alloc("4"), Var.alloc("5"), Var.alloc("6"), Var.alloc("7"), Var.alloc("8"), Var.alloc("9"), Var.alloc("0") };
    unsorted = new ArrayList<>();
    for (int i = 0; i < 500; i++) {
        unsorted.add(randomBinding(vars));
    }
    List<SortCondition> conditions = new ArrayList<>();
    conditions.add(new SortCondition(new ExprVar("8"), Query.ORDER_ASCENDING));
    comparator = new BindingComparator(conditions);
    iterator = new CallbackIterator(unsorted.iterator(), 25, null);
    iterator.setCallback(new Callback() {

        @Override
        public void call() {
            throw new QueryCancelledException();
        }
    });
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) SortCondition(org.apache.jena.query.SortCondition) BindingComparator(org.apache.jena.sparql.engine.binding.BindingComparator) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) ArrayList(java.util.ArrayList) Random(java.util.Random) QueryCancelledException(org.apache.jena.query.QueryCancelledException) Before(org.junit.Before)

Example 8 with ExprVar

use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.

the class TestExpressions method testVar.

private static void testVar(String string, String rightVarName) {
    Expr expr = parse(string);
    assertTrue("Not a NodeVar: " + expr, expr.isVariable());
    ExprVar v = (ExprVar) expr;
    assertEquals("Different variable names", rightVarName, v.getVarName());
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr)

Example 9 with ExprVar

use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.

the class TestOptimizer method combine_assign_02.

@Test
public void combine_assign_02() {
    Op assign = OpAssign.create(OpTable.unit(), new VarExprList(Var.alloc("x"), new NodeValueInteger(1)));
    assign = OpAssign.create(assign, new VarExprList(Var.alloc("y"), new ExprVar("x")));
    String opExpectedString = StrUtils.strjoinNL("(assign ((?x 1) (?y ?x))", "  (table unit))");
    check(assign, new TransformExtendCombine(), opExpectedString);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Op(org.apache.jena.sparql.algebra.Op) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) VarExprList(org.apache.jena.sparql.core.VarExprList) Test(org.junit.Test)

Example 10 with ExprVar

use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.

the class TestOptimizer method combine_extend_02.

@Test
public void combine_extend_02() {
    Op extend = OpExtend.create(OpTable.unit(), new VarExprList(Var.alloc("x"), new NodeValueInteger(1)));
    extend = OpExtend.create(extend, new VarExprList(Var.alloc("y"), new ExprVar("x")));
    String opExpectedString = StrUtils.strjoinNL("(extend ((?x 1) (?y ?x))", "  (table unit))");
    check(extend, new TransformExtendCombine(), opExpectedString);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Op(org.apache.jena.sparql.algebra.Op) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) VarExprList(org.apache.jena.sparql.core.VarExprList) Test(org.junit.Test)

Aggregations

ExprVar (org.apache.jena.sparql.expr.ExprVar)20 Expr (org.apache.jena.sparql.expr.Expr)12 Var (org.apache.jena.sparql.core.Var)8 Test (org.junit.Test)7 Op (org.apache.jena.sparql.algebra.Op)5 ArrayList (java.util.ArrayList)4 Node (org.apache.jena.graph.Node)4 Triple (org.apache.jena.graph.Triple)4 E_Multiply (org.apache.jena.sparql.expr.E_Multiply)4 SortCondition (org.apache.jena.query.SortCondition)3 Binding (org.apache.jena.sparql.engine.binding.Binding)3 BindingComparator (org.apache.jena.sparql.engine.binding.BindingComparator)3 E_Regex (org.apache.jena.sparql.expr.E_Regex)3 SortedDataBag (org.apache.jena.atlas.data.SortedDataBag)2 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)2 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)2 BasicPattern (org.apache.jena.sparql.core.BasicPattern)2 VarExprList (org.apache.jena.sparql.core.VarExprList)2 NodeValueInteger (org.apache.jena.sparql.expr.nodevalue.NodeValueInteger)2 ElementFilter (org.apache.jena.sparql.syntax.ElementFilter)2