Search in sources :

Example 91 with Op

use of org.apache.jena.sparql.algebra.Op in project jena by apache.

the class QueryUtils method checkOp.

public static void checkOp(Query query, boolean optimizeAlgebra) {
    IndentedLineBuffer buff = new IndentedLineBuffer();
    Op op = Algebra.compile(query);
    if (optimizeAlgebra)
        op = Algebra.optimize(op);
    WriterSSE.out(buff, op, query);
    String str = buff.toString();
    try {
        Op op2 = SSE.parseOp(str);
        if (op.hashCode() != op2.hashCode()) {
            op.hashCode();
            op2.hashCode();
            dump(op, op2);
            throw new QueryCheckException("reparsed algebra expression hashCode does not equal algebra from query");
        }
        if (!op.equals(op2)) {
            dump(op, op2);
            throw new QueryCheckException("reparsed algebra expression does not equal query algebra");
        }
    } catch (SSEParseException | BuildException ex) {
        System.err.println(str);
        throw ex;
    }
// Breakpoint
}
Also used : Op(org.apache.jena.sparql.algebra.Op) SSEParseException(org.apache.jena.sparql.sse.SSEParseException) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) BuildException(org.apache.jena.sparql.sse.builders.BuildException) IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Example 92 with Op

use of org.apache.jena.sparql.algebra.Op in project jena by apache.

the class QueryOutputUtils method printOp.

public static void printOp(IndentedWriter out, Query query, boolean printOptimized) {
    Op op = Algebra.compile(query);
    if (printOptimized)
        op = Algebra.optimize(op);
    WriterSSE.out(out, op, query);
    out.flush();
}
Also used : Op(org.apache.jena.sparql.algebra.Op)

Example 93 with Op

use of org.apache.jena.sparql.algebra.Op in project jena by apache.

the class TestCustomAggregates method customAgg_22.

@Test
public void customAgg_22() {
    String qs = "SELECT (<" + aggIRI + ">(?o) AS ?x) {?s ?p ?o }";
    Query q = QueryFactory.create(qs, Syntax.syntaxARQ);
    Op op = Algebra.compile(q);
    String x = StrUtils.strjoinNL("(project (?x)", "   (extend ((?x ?.0))", "       (group () ((?.0 (agg <http://example.test/agg> ?o)))", "         (bgp (triple ?s ?p ?o)))))");
    Op op2 = SSE.parseOp(x);
    assertEquals(op2, op);
}
Also used : Op(org.apache.jena.sparql.algebra.Op) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 94 with Op

use of org.apache.jena.sparql.algebra.Op in project jena by apache.

the class tdbreorder method main.

public static void main(String... args) {
    if (args.length != 2) {
        System.err.println("Usage: PATTERN STATS");
        System.exit(1);
    }
    LogCtl.enable(StatsMatcher.class);
    LogCtl.enable(ReorderTransformationSubstitution.class);
    if (args.length != 2) {
        System.err.println("Usage: op stats");
        System.exit(1);
    }
    String pattern = args[0];
    String statsFile = args[1];
    Op op = SSE.readOp(pattern);
    BasicPattern bgp;
    if (op instanceof OpQuadPattern) {
        bgp = ((OpQuadPattern) op).getBasicPattern();
    } else if (op instanceof OpBGP) {
        bgp = ((OpBGP) op).getPattern();
    } else {
        System.err.println("Not a quad or triple pattern");
        System.exit(2);
        bgp = null;
    }
    ReorderTransformation reorder = chooseReorder(statsFile);
    // ReorderTransformation reorder = ReorderLib.fixed() ;
    BasicPattern bgp2 = reorder.reorder(bgp);
    System.out.println();
    print(bgp);
    System.out.println();
    System.out.println(" ======== >>>>>>>>");
    print(bgp2);
    System.out.println();
}
Also used : Op(org.apache.jena.sparql.algebra.Op) OpQuadPattern(org.apache.jena.sparql.algebra.op.OpQuadPattern) ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 95 with Op

use of org.apache.jena.sparql.algebra.Op in project jena by apache.

the class OpExecutorTDB1 method optimizeExecuteTriples.

/** Execute, with optimization, a basic graph pattern on the default graph storage */
private static QueryIterator optimizeExecuteTriples(DatasetGraphTDB dsgtdb, QueryIterator input, BasicPattern pattern, ExprList exprs, ExecutionContext execCxt) {
    if (!input.hasNext())
        return input;
    // Must pass this iterator into the next stage.
    if (pattern.size() >= 2) {
        // Must be 2 or triples to reorder. 
        ReorderTransformation transform = dsgtdb.getReorderTransform();
        if (transform != null) {
            QueryIterPeek peek = QueryIterPeek.create(input, execCxt);
            // Must pass on
            input = peek;
            pattern = reorder(pattern, peek, transform);
        }
    }
    // -- Filter placement
    Op op = null;
    if (exprs != null)
        op = TransformFilterPlacement.transform(exprs, pattern);
    else
        op = new OpBGP(pattern);
    return plainExecute(op, input, execCxt);
}
Also used : QueryIterPeek(org.apache.jena.sparql.engine.iterator.QueryIterPeek) Op(org.apache.jena.sparql.algebra.Op) ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation)

Aggregations

Op (org.apache.jena.sparql.algebra.Op)166 Var (org.apache.jena.sparql.core.Var)29 VarExprList (org.apache.jena.sparql.core.VarExprList)18 Query (org.apache.jena.query.Query)17 ExprList (org.apache.jena.sparql.expr.ExprList)17 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)15 Test (org.junit.Test)14 Triple (org.apache.jena.graph.Triple)13 Expr (org.apache.jena.sparql.expr.Expr)13 BasicPattern (org.apache.jena.sparql.core.BasicPattern)11 ArrayList (java.util.ArrayList)9 Node (org.apache.jena.graph.Node)8 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)7 NodeValueInteger (org.apache.jena.sparql.expr.nodevalue.NodeValueInteger)7 Binding (org.apache.jena.sparql.engine.binding.Binding)5 ExprVar (org.apache.jena.sparql.expr.ExprVar)5 BaseTest (org.apache.jena.atlas.junit.BaseTest)3 Pair (org.apache.jena.atlas.lib.Pair)3 Table (org.apache.jena.sparql.algebra.Table)3 TransformCopy (org.apache.jena.sparql.algebra.TransformCopy)3