use of org.apache.jena.sparql.algebra.table.TableN in project jena by apache.
the class EvaluatorSimple method minusWorker.
private Table minusWorker(Table tableLeft, Table tableRight) {
// Minus(Ω1, Ω2) = { μ | μ in Ω1 such that for all μ' in Ω2, either μ and μ' are not compatible or dom(μ) and dom(μ') are disjoint }
TableN results = new TableN();
QueryIterator iterLeft = tableLeft.iterator(execCxt);
for (; iterLeft.hasNext(); ) {
Binding bindingLeft = iterLeft.nextBinding();
boolean includeThisRow = true;
// Find a reason not to include the row.
// That's is not disjoint and not compatible.
QueryIterator iterRight = tableRight.iterator(execCxt);
for (; iterRight.hasNext(); ) {
Binding bindingRight = iterRight.nextBinding();
if (Algebra.disjoint(bindingLeft, bindingRight))
// Disjoint - not a reason to exclude
continue;
if (!Algebra.compatible(bindingLeft, bindingRight))
// Compatible - not a reason to exclude.
continue;
includeThisRow = false;
break;
}
iterRight.close();
if (includeThisRow)
results.addBinding(bindingLeft);
}
iterLeft.close();
return results;
}
use of org.apache.jena.sparql.algebra.table.TableN in project jena by apache.
the class EvaluatorSimple method slice.
@Override
public Table slice(Table table, long start, long length) {
QueryIterator qIter = table.iterator(getExecContext());
qIter = new QueryIterSlice(qIter, start, length, getExecContext());
return new TableN(qIter);
}
use of org.apache.jena.sparql.algebra.table.TableN in project jena by apache.
the class EvaluatorSimple method diffWorker.
// @@ Abstract compatibility
private Table diffWorker(Table tableLeft, Table tableRight) {
QueryIterator left = tableLeft.iterator(execCxt);
TableN r = new TableN();
for (; left.hasNext(); ) {
Binding b = left.nextBinding();
if (tableRight.contains(b))
r.addBinding(b);
}
tableLeft.close();
tableRight.close();
return r;
}
use of org.apache.jena.sparql.algebra.table.TableN in project jena by apache.
the class EvaluatorSimple method joinWorker.
private Table joinWorker(Table tableLeft, Table tableRight, boolean leftJoin, ExprList conditions) {
QueryIterator left = tableLeft.iterator(execCxt);
JoinType joinType = (leftJoin ? JoinType.LEFT : JoinType.INNER);
QueryIterator qIter = TableJoin.joinWorker(left, tableRight, joinType, conditions, execCxt);
tableLeft.close();
tableRight.close();
// qIter and left should be properly closed by use or called code.
return new TableN(qIter);
}
use of org.apache.jena.sparql.algebra.table.TableN in project jena by apache.
the class TestTableJoin method test.
private void test(Table left, Table right, boolean normalJoin, ExprList exprs, Table expected) {
ExecutionContext execCxt = new ExecutionContext(ARQ.getContext(), null, null, null);
QueryIterator leftIter = left.iterator(execCxt);
QueryIterator qIter = normalJoin ? TableJoin.join(leftIter, right, exprs, execCxt) : TableJoin.leftJoin(leftIter, right, exprs, execCxt);
// Order issues
Set<String> vars1 = new HashSet<>();
vars1.addAll(left.getVarNames());
vars1.addAll(right.getVarNames());
TableN results = new TableN(qIter);
boolean b = TableCompare.equalsByTerm(expected, results);
if (!b) {
System.out.println("** Expected");
System.out.println(expected);
System.out.println("** Actual");
System.out.println(results);
}
assertTrue(b);
}
Aggregations