use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class SolverRX3 method rdfStarTripleSub.
private static Iterator<Binding> rdfStarTripleSub(Binding input, Triple xPattern, ExecutionContext execCxt) {
Triple tPattern = Substitute.substitute(xPattern, input);
Node s = nodeTopLevel(tPattern.getSubject());
Node p = nodeTopLevel(tPattern.getPredicate());
Node o = nodeTopLevel(tPattern.getObject());
Graph graph = execCxt.getActiveGraph();
ExtendedIterator<Triple> graphIter = graph.find(s, p, o);
ExtendedIterator<Binding> matched = graphIter.mapWith(tData -> matchTriple(input, tData, tPattern)).filterDrop(Objects::isNull);
return matched;
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class StageMatchData method accessQuad.
static Iterator<Binding> accessQuad(Binding binding, Node graphName, Triple pattern, Predicate<Quad> filter, boolean anyGraph, ExecutionContext execCxt) {
// Assumes if anyGraph, then graphName ==ANY.
// graphName == null for triples.
Node g = graphName;
Node s = pattern.getSubject();
Node p = pattern.getPredicate();
Node o = pattern.getObject();
Node[] matchConst = new Node[4];
Var[] vars = new Var[4];
boolean b = prepareQuad(binding, graphName, pattern, matchConst, vars);
if (!b)
return Iter.nullIterator();
Node gm = matchConst[QG];
Node sm = matchConst[QS];
Node pm = matchConst[QP];
Node om = matchConst[QO];
DatasetGraph dsg = execCxt.getDataset();
// Union -> findNG - do not include default graph.
Iterator<Quad> iterMatches = anyGraph ? dsg.findNG(gm, sm, pm, om) : dsg.find(gm, sm, pm, om);
if (false) {
// Debug
List<Quad> x = Iter.toList(iterMatches);
System.out.println(x);
iterMatches = x.iterator();
}
// ** Allow a triple or quad filter here.
if (filter != null)
iterMatches = Iter.filter(iterMatches, filter);
// Assumes that tuples are not shared.
if (anyGraph) {
iterMatches = Iter.map(iterMatches, quadsToUnion);
// Guaranteed
iterMatches = Iter.distinct(iterMatches);
// This depends on the way indexes are chosen and
// the indexing pattern. It assumes that the index
// chosen ends in G so same triples are adjacent
// in a union query.
//
// If any slot is defined, then the index will be X??G.
// If no slot is defined, then the index will be ???G.
// Must be guaranteed.
//
// iterMatches = Iter.distinctAdjacent(iterMatches);
}
BindingBuilder bindingBuilder = BindingFactory.builder(binding);
Function<Quad, Binding> binder = quad -> quadToBinding(bindingBuilder, quad, matchConst, vars);
return Iter.iter(iterMatches).map(binder).removeNulls();
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class QueryIterService method nextStage.
@Override
protected QueryIterator nextStage(Binding outerBinding) {
boolean silent = opService.getSilent();
ExecutionContext execCxt = getExecContext();
Context cxt = execCxt.getContext();
ServiceExecutorRegistry registry = ServiceExecutorRegistry.get(cxt);
ServiceExecution svcExec = null;
OpService substitutedOp = (OpService) QC.substitute(opService, outerBinding);
try {
// ---- Find handler
if (registry != null) {
for (ServiceExecutorFactory factory : registry.getFactories()) {
// Internal consistency check
if (factory == null) {
Log.warn(this, "SERVICE <" + opService.getService().toString() + ">: Null item in custom ServiceExecutionRegistry");
continue;
}
svcExec = factory.createExecutor(substitutedOp, opService, outerBinding, execCxt);
if (svcExec != null)
break;
}
}
// ---- Execute
if (svcExec == null)
throw new QueryExecException("No SERVICE handler");
QueryIterator qIter = svcExec.exec();
qIter = QueryIter.makeTracked(qIter, getExecContext());
// There should be no variables in common because of the OpSubstitute.substitute
return new QueryIterCommonParent(qIter, outerBinding, getExecContext());
} catch (RuntimeException ex) {
if (silent) {
Log.warn(this, "SERVICE " + NodeFmtLib.strTTL(substitutedOp.getService()) + " : " + ex.getMessage());
// Return the input
return QueryIterSingleton.create(outerBinding, getExecContext());
}
throw ex;
}
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class TestPath method eval.
private static List<Binding> eval(Graph graph, Node start, String pathStr, Node finish) {
Path path = SSE.parsePath(pathStr, pmap);
QueryIterator qIter = PathLib.execTriplePath(BindingFactory.root(), start, path, finish, new ExecutionContext(ARQ.getContext(), graph, null, null));
return Iter.toList(qIter);
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class SolverRX method matchQuadPattern.
// Entry point from SolverLib.
/*package*/
static Iterator<BindingNodeId> matchQuadPattern(Iterator<BindingNodeId> chain, Node graphNode, Triple tPattern, NodeTupleTable nodeTupleTable, Tuple<Node> patternTuple, boolean anyGraph, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
if (DATAPATH) {
if (!tripleHasEmbTripleWithVars(tPattern))
// No RDF-star <<>> with variables.
return StageMatchTuple.access(nodeTupleTable, chain, patternTuple, filter, anyGraph, execCxt);
}
// RDF-star <<>> with variables.
// This path should work regardless.
boolean isTriple = (patternTuple.len() == 3);
NodeTable nodeTable = nodeTupleTable.getNodeTable();
Function<BindingNodeId, Iterator<BindingNodeId>> step = bnid -> find(bnid, nodeTupleTable, graphNode, tPattern, anyGraph, filter, execCxt);
return Iter.flatMap(chain, step);
}
Aggregations