Search in sources :

Example 26 with VarExprList

use of org.apache.jena.sparql.core.VarExprList in project jena by apache.

the class ApplyTransformVisitor method visit.

@Override
public void visit(OpGroup opGroup) {
    boolean changed = false;
    VarExprList varExpr = opGroup.getGroupVars();
    VarExprList varExpr2 = collect(varExpr);
    if (varExpr != varExpr2)
        changed = true;
    List<ExprAggregator> aggs = opGroup.getAggregators();
    List<ExprAggregator> aggs2 = aggs;
    // And the aggregators...
    aggs2 = new ArrayList<>();
    for (ExprAggregator agg : aggs) {
        Aggregator aggregator = agg.getAggregator();
        Var v = agg.getVar();
        // Variable associated with the aggregate
        // Not .getExprVar()
        Expr eVar = agg.getAggVar();
        Expr eVar2 = transform(eVar);
        if (eVar != eVar2)
            changed = true;
        // The Aggregator expression
        ExprList e = aggregator.getExprList();
        ExprList e2 = e;
        if (e != null)
            // Null means "no relevant expression" e.g. COUNT(*)
            e2 = transform(e);
        if (e != e2)
            changed = true;
        Aggregator a2 = aggregator.copy(e2);
        aggs2.add(new ExprAggregator(eVar2.asVar(), a2));
    }
    OpGroup opGroup2 = opGroup;
    if (changed)
        opGroup2 = OpGroup.create(opGroup.getSubOp(), varExpr2, aggs2);
    visit1(opGroup2);
}
Also used : VarExprList(org.apache.jena.sparql.core.VarExprList) Var(org.apache.jena.sparql.core.Var) Aggregator(org.apache.jena.sparql.expr.aggregate.Aggregator) VarExprList(org.apache.jena.sparql.core.VarExprList)

Example 27 with VarExprList

use of org.apache.jena.sparql.core.VarExprList in project jena by apache.

the class ApplyTransformVisitor method collect.

// Special test cases for collectors.
// Careful about order.
private VarExprList collect(VarExprList varExprList) {
    if (varExprList == null)
        return varExprList;
    List<Var> vars = varExprList.getVars();
    VarExprList varExpr2 = new VarExprList();
    List<Expr> x = collect(vars.size());
    boolean changed = false;
    for (int i = 0; i < vars.size(); i++) {
        Var v = vars.get(i);
        Expr e2 = x.get(i);
        Expr e = varExpr2.getExpr(v);
        if (e != e2)
            changed = true;
        if (e2 == null)
            varExpr2.add(v);
        else {
            varExpr2.add(v, e2);
        }
    }
    return changed ? varExpr2 : varExprList;
}
Also used : Var(org.apache.jena.sparql.core.Var) VarExprList(org.apache.jena.sparql.core.VarExprList)

Example 28 with VarExprList

use of org.apache.jena.sparql.core.VarExprList in project jena by apache.

the class TestTransformPromoteTableEmpty method promote_table_empty_assignment_03.

@Test
public void promote_table_empty_assignment_03() {
    // Force algebra to have separate extends by using extendDirect()
    Op input = OpTable.empty();
    input = OpExtend.create(input, new VarExprList(Var.alloc("x"), new NodeValueInteger(1)));
    input = OpExtend.create(input, new VarExprList(Var.alloc("y"), new NodeValueInteger(2)));
    test(input, t_promote, "(table empty)");
}
Also used : 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 29 with VarExprList

use of org.apache.jena.sparql.core.VarExprList in project jena by apache.

the class TestOptimizer method combine_extend_03.

@Test
public void combine_extend_03() {
    // Technically illegal SPARQL here but useful to validate that the optimizer doesn't do the wrong thing
    Op extend = OpExtend.create(OpTable.unit(), new VarExprList(Var.alloc("x"), new NodeValueInteger(1)));
    extend = OpExtend.create(extend, new VarExprList(Var.alloc("x"), new NodeValueInteger(2)));
    String opExpectedString = StrUtils.strjoinNL("(extend ((?x 2))", "  (extend ((?x 1))", "    (table unit)))");
    check(extend, new TransformExtendCombine(), opExpectedString);
}
Also used : 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 30 with VarExprList

use of org.apache.jena.sparql.core.VarExprList 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)

Aggregations

VarExprList (org.apache.jena.sparql.core.VarExprList)49 Var (org.apache.jena.sparql.core.Var)21 Test (org.junit.Test)15 Op (org.apache.jena.sparql.algebra.Op)12 Expr (org.apache.jena.sparql.expr.Expr)8 Query (org.apache.jena.query.Query)7 NodeValueInteger (org.apache.jena.sparql.expr.nodevalue.NodeValueInteger)7 ContractTest (org.xenei.junit.contract.ContractTest)6 E_Random (org.apache.jena.sparql.expr.E_Random)4 QueryParseException (org.apache.jena.query.QueryParseException)3 ExprAggregator (org.apache.jena.sparql.expr.ExprAggregator)2 ExprVar (org.apache.jena.sparql.expr.ExprVar)2 StringReader (java.io.StringReader)1 Map (java.util.Map)1 ExprRewriter (org.apache.jena.arq.querybuilder.rewriters.ExprRewriter)1 Node (org.apache.jena.graph.Node)1 SortCondition (org.apache.jena.query.SortCondition)1 OpAssign (org.apache.jena.sparql.algebra.op.OpAssign)1 OpExtend (org.apache.jena.sparql.algebra.op.OpExtend)1 BindingHashMap (org.apache.jena.sparql.engine.binding.BindingHashMap)1