Search in sources :

Example 6 with TableN

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;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) TableN(org.apache.jena.sparql.algebra.table.TableN)

Example 7 with TableN

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);
}
Also used : QueryIterator(org.apache.jena.sparql.engine.QueryIterator) TableN(org.apache.jena.sparql.algebra.table.TableN)

Example 8 with TableN

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;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) TableN(org.apache.jena.sparql.algebra.table.TableN)

Example 9 with TableN

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);
}
Also used : QueryIterator(org.apache.jena.sparql.engine.QueryIterator) TableN(org.apache.jena.sparql.algebra.table.TableN)

Example 10 with TableN

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);
}
Also used : ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) TableN(org.apache.jena.sparql.algebra.table.TableN) HashSet(java.util.HashSet)

Aggregations

TableN (org.apache.jena.sparql.algebra.table.TableN)14 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)13 Binding (org.apache.jena.sparql.engine.binding.Binding)4 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Table (org.apache.jena.sparql.algebra.Table)1 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)1