use of org.apache.jena.sparql.engine.iterator.Abortable in project jena by apache.
the class PatternMatchData method execute.
/**
* Non-reordering execution of a quad pattern, a graph name and a basic graph pattern,
* given an iterator of bindings as input.
* <p>
* GraphNode is Node.ANY for execution over the union of named graphs.<br/>
* GraphNode is null for execution over the real default graph.
*/
public static QueryIterator execute(DatasetGraph dsg, Node graphNode, BasicPattern pattern, QueryIterator input, Predicate<Quad> filter, ExecutionContext execCxt) {
// graphNode may be null, meaning default graph
if (Quad.isUnionGraph(graphNode))
graphNode = Node.ANY;
if (Quad.isDefaultGraph(graphNode))
graphNode = null;
List<Triple> triples = pattern.getList();
boolean isDefaultGraph = (graphNode == null);
boolean anyGraph = isDefaultGraph ? false : (Node.ANY.equals(graphNode));
Iterator<Binding> chain = input;
List<Abortable> killList = new ArrayList<>();
for (Triple triple : triples) {
// Plain - no RDF-star.
// chain = StageMatchData.accessQuad(chain, graphNode, triple, filter, anyGraph, execCxt);
// [Match] Missing filter.
chain = SolverRX4.rdfStarQuad(chain, graphNode, triple, execCxt);
chain = SolverLib.makeAbortable(chain, killList);
}
// "killList" will be aborted on timeout.
return new QueryIterAbortable(chain, killList, input, execCxt);
}
use of org.apache.jena.sparql.engine.iterator.Abortable in project jena by apache.
the class PatternMatchTDB2 method execute.
// The worker. Callers choose the NodeTupleTable.
// graphNode may be Node.ANY, meaning we should make triples unique.
// graphNode may be null, meaning default graph
private static QueryIterator execute(NodeTupleTable nodeTupleTable, Node graphNode, BasicPattern pattern, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
if (Quad.isUnionGraph(graphNode))
graphNode = Node.ANY;
if (Quad.isDefaultGraph(graphNode))
graphNode = null;
List<Triple> triples = pattern.getList();
boolean anyGraph = (graphNode == null ? false : (Node.ANY.equals(graphNode)));
int tupleLen = nodeTupleTable.getTupleTable().getTupleLen();
if (graphNode == null) {
if (3 != tupleLen)
throw new TDBException("SolverLib: Null graph node but tuples are of length " + tupleLen);
} else {
if (4 != tupleLen)
throw new TDBException("SolverLib: Graph node specified but tuples are of length " + tupleLen);
}
// Convert from a QueryIterator (Bindings of Var/Node) to BindingNodeId
NodeTable nodeTable = nodeTupleTable.getNodeTable();
Iterator<BindingNodeId> chain = Iter.map(input, SolverLibTDB.convFromBinding(nodeTable));
List<Abortable> killList = new ArrayList<>();
for (Triple triple : triples) {
Tuple<Node> patternTuple = null;
if (graphNode == null)
// 3-tuples
patternTuple = TupleFactory.create3(triple.getSubject(), triple.getPredicate(), triple.getObject());
else
// 4-tuples.
patternTuple = TupleFactory.create4(graphNode, triple.getSubject(), triple.getPredicate(), triple.getObject());
// Plain RDF, no RDF-star
// chain = solve(nodeTupleTable, tuple, anyGraph, chain, filter, execCxt)
// ;
// RDF-star SA
chain = matchQuadPattern(chain, graphNode, triple, nodeTupleTable, patternTuple, anyGraph, filter, execCxt);
chain = makeAbortable(chain, killList);
}
Iterator<Binding> iterBinding = SolverLibTDB.convertToNodes(chain, nodeTable);
// "killList" will be aborted on timeout.
return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}
use of org.apache.jena.sparql.engine.iterator.Abortable in project jena by apache.
the class SolverLibTDB method graphNames.
/**
* Find all the graph names in the quads table.
*/
static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
List<Abortable> killList = new ArrayList<>();
Iterator<Tuple<NodeId>> iter1 = ds.getQuadTable().getNodeTupleTable().find(NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny);
if (filter != null)
iter1 = Iter.filter(iter1, filter);
Iterator<NodeId> iter2 = Iter.map(iter1, t -> t.get(0));
// Project is cheap - don't brother wrapping iter1
iter2 = makeAbortable(iter2, killList);
Iterator<NodeId> iter3 = Iter.distinct(iter2);
iter3 = makeAbortable(iter3, killList);
Iterator<Node> iter4 = NodeLib.nodes(ds.getQuadTable().getNodeTupleTable().getNodeTable(), iter3);
final Var var = Var.alloc(graphNode);
Iterator<Binding> iterBinding = Iter.map(iter4, node -> BindingFactory.binding(var, node));
return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}
use of org.apache.jena.sparql.engine.iterator.Abortable in project jena by apache.
the class PatternMatchTDB1 method execute.
// The worker. Callers choose the NodeTupleTable.
// graphNode may be Node.ANY, meaning we should make triples unique.
// graphNode may be null, meaning default graph
private static QueryIterator execute(NodeTupleTable nodeTupleTable, Node graphNode, BasicPattern pattern, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
if (Quad.isUnionGraph(graphNode))
graphNode = Node.ANY;
if (Quad.isDefaultGraph(graphNode))
graphNode = null;
List<Triple> triples = pattern.getList();
boolean anyGraph = (graphNode == null ? false : (Node.ANY.equals(graphNode)));
int tupleLen = nodeTupleTable.getTupleTable().getTupleLen();
if (graphNode == null) {
if (3 != tupleLen)
throw new TDBException("SolverLib: Null graph node but tuples are of length " + tupleLen);
} else {
if (4 != tupleLen)
throw new TDBException("SolverLib: Graph node specified but tuples are of length " + tupleLen);
}
// Convert from a QueryIterator (Bindings of Var/Node) to BindingNodeId
NodeTable nodeTable = nodeTupleTable.getNodeTable();
Iterator<BindingNodeId> chain = Iter.map(input, SolverLibTDB.convFromBinding(nodeTable));
List<Abortable> killList = new ArrayList<>();
for (Triple triple : triples) {
Tuple<Node> patternTuple = null;
if (graphNode == null)
// 3-tuples
patternTuple = TupleFactory.create3(triple.getSubject(), triple.getPredicate(), triple.getObject());
else
// 4-tuples.
patternTuple = TupleFactory.create4(graphNode, triple.getSubject(), triple.getPredicate(), triple.getObject());
// Plain RDF, no RDF-star
// chain = solve(nodeTupleTable, tuple, anyGraph, chain, filter, execCxt)
// ;
// RDF-star SA
chain = matchQuadPattern(chain, graphNode, triple, nodeTupleTable, patternTuple, anyGraph, filter, execCxt);
chain = makeAbortable(chain, killList);
}
Iterator<Binding> iterBinding = SolverLibTDB.convertToNodes(chain, nodeTable);
// "killList" will be aborted on timeout.
return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}
use of org.apache.jena.sparql.engine.iterator.Abortable in project jena by apache.
the class SolverLibTDB method graphNames.
/**
* Find all the graph names in the quads table.
*/
static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
List<Abortable> killList = new ArrayList<>();
Iterator<Tuple<NodeId>> iter1 = ds.getQuadTable().getNodeTupleTable().find(NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny);
if (filter != null)
iter1 = Iter.filter(iter1, filter);
Iterator<NodeId> iter2 = Iter.map(iter1, t -> t.get(0));
// Project is cheap - don't brother wrapping iter1
iter2 = makeAbortable(iter2, killList);
Iterator<NodeId> iter3 = Iter.distinct(iter2);
iter3 = makeAbortable(iter3, killList);
Iterator<Node> iter4 = NodeLib.nodes(ds.getQuadTable().getNodeTupleTable().getNodeTable(), iter3);
final Var var = Var.alloc(graphNode);
Iterator<Binding> iterBinding = Iter.map(iter4, node -> BindingFactory.binding(var, node));
return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}
Aggregations