Search in sources :

Example 1 with ExecutionContext

use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.

the class TupleTable method iterator.

public QueryIterator iterator() {
    SDBRequest request = new SDBRequest(store, null);
    String tableName = desc.getTableName();
    SQLBridge b = store.getSQLBridgeFactory().create(request, sqlTable, vars);
    b.build();
    try {
        String sqlStr = store.getSQLGenerator().generateSQL(request, b.getSqlNode());
        //System.out.println(sqlStr) ;
        ResultSetJDBC tableData = store.getConnection().execQuery(sqlStr);
        ExecutionContext execCxt = new ExecutionContext(new Context(), null, null, null);
        return b.assembleResults(tableData, BindingRoot.create(), execCxt);
    } catch (SQLException ex) {
        throw new SDBExceptionSQL(ex);
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) SDBExceptionSQL(org.apache.jena.sdb.sql.SDBExceptionSQL) SQLException(java.sql.SQLException) ResultSetJDBC(org.apache.jena.sdb.sql.ResultSetJDBC) SDBRequest(org.apache.jena.sdb.core.SDBRequest)

Example 2 with ExecutionContext

use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.

the class Eval method evalGraph.

static Table evalGraph(OpGraph opGraph, Evaluator evaluator) {
    ExecutionContext execCxt = evaluator.getExecContext();
    if (!Var.isVar(opGraph.getNode())) {
        DatasetGraph dsg = execCxt.getDataset();
        Node graphNode = opGraph.getNode();
        if (!dsg.containsGraph(graphNode))
            return new TableEmpty();
        Graph graph = execCxt.getDataset().getGraph(opGraph.getNode());
        if (// But contains was true?!!
        graph == null)
            throw new InternalErrorException("Graph was present, now it's not");
        ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
        Evaluator e2 = EvaluatorFactory.create(execCxt2);
        return eval(e2, opGraph.getSubOp());
    }
    // Graph node is a variable.
    Var gVar = Var.alloc(opGraph.getNode());
    Table current = null;
    for (Iterator<Node> iter = execCxt.getDataset().listGraphNodes(); iter.hasNext(); ) {
        Node gn = iter.next();
        Graph graph = execCxt.getDataset().getGraph(gn);
        ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
        Evaluator e2 = EvaluatorFactory.create(execCxt2);
        Table tableVarURI = TableFactory.create(gVar, gn);
        // Evaluate the pattern, join with this graph node possibility.
        // XXX If Var.ANON then no-opt.
        Table patternTable = eval(e2, opGraph.getSubOp());
        Table stepResult = evaluator.join(patternTable, tableVarURI);
        if (current == null)
            current = stepResult;
        else
            current = evaluator.union(current, stepResult);
    }
    if (current == null)
        // Nothing to loop over
        return new TableEmpty();
    return current;
}
Also used : ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) OpGraph(org.apache.jena.sparql.algebra.op.OpGraph) Graph(org.apache.jena.graph.Graph) Table(org.apache.jena.sparql.algebra.Table) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) TableEmpty(org.apache.jena.sparql.algebra.table.TableEmpty) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 3 with ExecutionContext

use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.

the class PathLib method existsPath.

private static int existsPath(Graph graph, Node subject, Path path, final Node object, ExecutionContext execCxt) {
    if (!subject.isConcrete() || !object.isConcrete())
        throw new ARQInternalErrorException("Non concrete node for existsPath evaluation");
    Iterator<Node> iter = PathEval.eval(graph, subject, path, execCxt.getContext());
    Predicate<Node> filter = node -> Objects.equals(node, object);
    // See if we got to the node we're interested in finishing at.
    iter = Iter.filter(iter, filter);
    long x = Iter.count(iter);
    return (int) x;
}
Also used : Context(org.apache.jena.sparql.util.Context) Binding(org.apache.jena.sparql.engine.binding.Binding) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) BasicPattern(org.apache.jena.sparql.core.BasicPattern) QueryIterConcat(org.apache.jena.sparql.engine.iterator.QueryIterConcat) TriplePath(org.apache.jena.sparql.core.TriplePath) OpPath(org.apache.jena.sparql.algebra.op.OpPath) OpSequence(org.apache.jena.sparql.algebra.op.OpSequence) Graph(org.apache.jena.graph.Graph) ArrayList(java.util.ArrayList) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) QueryIterYieldN(org.apache.jena.sparql.engine.iterator.QueryIterYieldN) Op(org.apache.jena.sparql.algebra.Op) GraphUtils(org.apache.jena.sparql.util.graph.GraphUtils) Iter(org.apache.jena.atlas.iterator.Iter) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) BindingFactory(org.apache.jena.sparql.engine.binding.BindingFactory) PathEval(org.apache.jena.sparql.path.eval.PathEval) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) Triple(org.apache.jena.graph.Triple) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) PropertyFunctionFactory(org.apache.jena.sparql.pfunction.PropertyFunctionFactory) PathBlock(org.apache.jena.sparql.core.PathBlock) Objects(java.util.Objects) List(java.util.List) Explain(org.apache.jena.sparql.mgt.Explain) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) PropertyFunctionRegistry(org.apache.jena.sparql.pfunction.PropertyFunctionRegistry) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) Node(org.apache.jena.graph.Node)

Example 4 with ExecutionContext

use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.

the class ExprUtils method eval.

public static NodeValue eval(Expr expr, Binding binding) {
    Context context = ARQ.getContext().copy();
    context.set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime());
    FunctionEnv env = new ExecutionContext(context, null, null, null);
    NodeValue r = expr.eval(binding, env);
    return r;
}
Also used : SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) FunctionEnv(org.apache.jena.sparql.function.FunctionEnv) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext)

Example 5 with ExecutionContext

use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.

the class TestCancelDistinct method testUnbaggedCancelPropagates.

/**
 *       test that of a QueryIterDistinct is cancelled, so is the
 *       iterator that it wraps.
 */
@Test
public void testUnbaggedCancelPropagates() {
    // Something better than null would be good. But making
    // an ExecutionContext is non-trivial.
    ExecutionContext c = null;
    QueryIteratorBase base = new MockQueryIterator();
    QueryIterDistinct d = new QueryIterDistinct(base, null, c);
    assertFalse(base.getRequestingCancel());
    d.cancel();
    assertTrue(base.getRequestingCancel());
}
Also used : ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) Test(org.junit.Test)

Aggregations

ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)40 Context (org.apache.jena.sparql.util.Context)19 Node (org.apache.jena.graph.Node)14 SerializationContext (org.apache.jena.sparql.serializer.SerializationContext)12 Test (org.junit.Test)12 Binding (org.apache.jena.sparql.engine.binding.Binding)11 Triple (org.apache.jena.graph.Triple)9 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)9 Iterator (java.util.Iterator)8 Iter (org.apache.jena.atlas.iterator.Iter)8 Var (org.apache.jena.sparql.core.Var)8 Predicate (java.util.function.Predicate)7 Graph (org.apache.jena.graph.Graph)7 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)6 Function (java.util.function.Function)5 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)5 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)5 Quad (org.apache.jena.sparql.core.Quad)5 Substitute (org.apache.jena.sparql.core.Substitute)5 BindingFactory (org.apache.jena.sparql.engine.binding.BindingFactory)5