use of org.apache.jena.atlas.lib.Pair in project jena by apache.
the class TransformFilterImplicitJoin method apply.
private static Op apply(ExprList exprs, Op subOp) {
// ---- Find and extract any implicit join filters.
Pair<List<Pair<Var, Var>>, ExprList> p = preprocessFilterImplicitJoin(subOp, exprs);
if (p == null || p.getLeft().size() == 0)
return null;
List<Pair<Var, Var>> joins = p.getLeft();
Collection<Var> varsMentioned = varsMentionedInImplictJoins(joins);
ExprList remaining = p.getRight();
// enhancement to this optimizer
if (varsMentioned.size() != joins.size() * 2)
return null;
// ---- Check if the subOp is the right shape to transform.
Op op = subOp;
// hence eliminate all rows. Return the empty table.
if (testSpecialCaseUnused(subOp, joins, remaining))
return OpTable.empty();
// This is { OPTIONAL{P1} OPTIONAL{P2} ... FILTER(?x = :x) }
if (testSpecialCaseOptional(subOp, joins, remaining)) {
// Find backbone of ops
List<Op> ops = extractOptionals(subOp);
ops = processSpecialCaseOptional(ops, joins);
// Put back together
op = rebuild((Op2) subOp, ops);
// Put all filters - either we optimized, or we left alone.
// Either way, the complete set of filter expressions.
op = OpFilter.filterBy(exprs, op);
return op;
}
// Special case : filter is over a union where one/both sides are always false
if (testSpecialCaseUnion(subOp, joins)) {
// This will attempt to eliminate the sides that are always false
op = processSpecialCaseUnion(subOp, joins);
// operator at this point and can return immediately
if (op instanceof OpTable)
return op;
}
if (!safeToTransform(joins, varsMentioned, op))
return null;
for (Pair<Var, Var> implicitJoin : joins) {
// TODO Where there are multiple conditions it may be necessary to
// apply the substitutions more intelligently
op = processFilterWorker(op, implicitJoin.getLeft(), implicitJoin.getRight());
}
// ---- Place any filter expressions around the processed sub op.
if (remaining.size() > 0)
op = OpFilter.filterBy(remaining, op);
return op;
}
use of org.apache.jena.atlas.lib.Pair in project jena by apache.
the class TransformFilterInequality method preprocessFilterInequality.
// --- find and extract
private static Pair<List<Pair<Var, NodeValue>>, ExprList> preprocessFilterInequality(ExprList exprs) {
List<Pair<Var, NodeValue>> exprsFilterInequality = new ArrayList<>();
ExprList exprsOther = new ExprList();
for (Expr e : exprs.getList()) {
Pair<Var, NodeValue> p = preprocess(e);
if (p != null)
exprsFilterInequality.add(p);
else
exprsOther.add(e);
}
if (exprsFilterInequality.size() == 0)
return null;
return Pair.create(exprsFilterInequality, exprsOther);
}
use of org.apache.jena.atlas.lib.Pair in project jena by apache.
the class ObjectFileTrans method append.
/** Copy from the temporary file to the real file */
private void append() {
// We could write directly to the real file if:
// we record the truncate point needed for an abort
// manage partial final writes
// deny the existence of nodes after the transaction mark.
// Later - stay simple for now.
// Truncate/position the ObjectFile.
base.reposition(otherAllocOffset);
Iterator<Pair<Long, ByteBuffer>> iter = transObjects.all();
for (; iter.hasNext(); ) {
Pair<Long, ByteBuffer> p = iter.next();
String s = StrUtils.fromUTF8bytes(p.getRight().array());
long x = base.write(p.getRight());
if (p.getLeft() + otherAllocOffset != x)
throw new FileException("Expected id of " + (p.getLeft() + otherAllocOffset) + ", got an id of " + x);
}
}
use of org.apache.jena.atlas.lib.Pair in project jena by apache.
the class NodeTableTrans method dump.
// Debugging only
private void dump() {
System.err.println(">>>>>>>>>>");
System.err.println("label = " + label);
System.err.println("txn = " + txn);
System.err.println("offset = " + allocOffset);
System.err.println("journalStartOffset = " + journalObjFileStartOffset);
System.err.println("journal = " + journalObjFile.getLabel());
if (true)
return;
System.err.println("nodeTableJournal >>>");
Iterator<Pair<NodeId, Node>> iter = nodeTableJournal.all();
for (; iter.hasNext(); ) {
Pair<NodeId, Node> x = iter.next();
NodeId nodeId = x.getLeft();
Node node = x.getRight();
NodeId mapped = mapFromJournal(nodeId);
//debug("append: %s -> %s", x, mapFromJournal(nodeId)) ;
// This does the write.
NodeId nodeId2 = base.getAllocateNodeId(node);
System.err.println(x + " mapped=" + mapped + " getAlloc=" + nodeId2);
}
System.err.println("journal >>>");
Iterator<Pair<Long, ByteBuffer>> iter1 = this.journalObjFile.all();
for (; iter1.hasNext(); ) {
Pair<Long, ByteBuffer> p = iter1.next();
System.err.println(p.getLeft() + " : " + p.getRight());
ByteBufferLib.print(System.err, p.getRight());
}
System.err.println("nodeIndex >>>");
Iterator<Record> iter2 = this.nodeIndex.iterator();
for (; iter2.hasNext(); ) {
Record r = iter2.next();
System.err.println(r);
}
System.err.println("<<<<<<<<<<");
}
Aggregations