use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class AbstractTestTupleIndex method TupleIndexRecordPOS_3.
@Test
public void TupleIndexRecordPOS_3() {
TupleIndex index = createIndex("POS");
add(index, n1, n2, n3);
Tuple<NodeId> tuple2 = TupleFactory.tuple(null, n2, n3);
Iterator<Tuple<NodeId>> iter = index.find(tuple2);
assertTrue("Can't find tuple", iter.hasNext());
iter.next();
assertFalse(iter.hasNext());
}
use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class AbstractTestTupleIndex method TupleIndexRecordPOS_1.
@Test
public void TupleIndexRecordPOS_1() {
TupleIndex index = createIndex("POS");
add(index, n1, n2, n3);
Tuple<NodeId> tuple2 = TupleFactory.tuple(n1, n2, n3);
Iterator<Tuple<NodeId>> iter = index.find(tuple2);
assertTrue("Can't find tuple", iter.hasNext());
iter.next();
assertFalse(iter.hasNext());
}
use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class OpExecutorTDB1 method optimizeExecuteQuads.
/**
* Execute, with optimization, a quad pattern
*/
private static QueryIterator optimizeExecuteQuads(DatasetGraphTDB dsgtdb, QueryIterator input, Node gn, BasicPattern bgp, ExprList exprs, ExecutionContext execCxt) {
if (!input.hasNext())
return input;
// ---- Graph names with special meaning.
gn = decideGraphNode(gn, execCxt);
if (gn == null)
return optimizeExecuteTriples(dsgtdb, input, bgp, exprs, execCxt);
// ---- Execute quads+filters
if (bgp.size() >= 2) {
ReorderTransformation transform = dsgtdb.getReorderTransform();
if (transform != null) {
QueryIterPeek peek = QueryIterPeek.create(input, execCxt);
// Original input now invalid.
input = peek;
bgp = reorder(bgp, peek, transform);
}
}
if (exprs == null) {
// Triple-backed (but may be named as explicit default graph).
Explain.explain("Execute", bgp, execCxt.getContext());
Predicate<Tuple<NodeId>> filter = QC2.getFilter(execCxt.getContext());
return PatternMatchTDB1.execute(dsgtdb, gn, bgp, input, filter, execCxt);
}
// -- Filter placement
Op op = TransformFilterPlacement.transform(exprs, gn, bgp);
return plainExecute(op, input, execCxt);
}
use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class SolverLibTDB method testForGraphName.
/**
* Find whether a specific graph name is in the quads table.
*/
static QueryIterator testForGraphName(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
NodeId nid = TDBInternal.getNodeId(ds, graphNode);
boolean exists = !NodeId.isDoesNotExist(nid);
if (exists) {
// Node exists but is it used in the quad position?
NodeTupleTable ntt = ds.getQuadTable().getNodeTupleTable();
// Don't worry about abortable - this iterator should be fast
// (with normal indexing - at least one G???).
// Either it finds a starting point, or it doesn't. We are only
// interested in the first .hasNext.
Iterator<Tuple<NodeId>> iter1 = ntt.find(nid, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny);
if (filter != null)
iter1 = Iter.filter(iter1, filter);
exists = iter1.hasNext();
}
if (exists)
return input;
else {
input.close();
return QueryIterNullIterator.create(execCxt);
}
}
use of org.apache.jena.atlas.lib.tuple.Tuple 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