Search in sources :

Example 6 with RowSetRewindable

use of org.apache.jena.sparql.exec.RowSetRewindable in project jena by apache.

the class TestSolverTDB method exec.

/**
 * Execute in triples and quad forms. Check the algebra expression gets the same
 * results
 */
private static RowSet exec(String pattern) {
    Op op1 = SSE.parseOp(pattern, pmap);
    List<Var> vars = new ArrayList<>();
    vars.addAll(OpVars.visibleVars(op1));
    Op op2 = Algebra.toQuadForm(op1);
    // Execute in triples and quad forms.
    QueryIterator qIter1 = Algebra.exec(op1, dataset.asDatasetGraph());
    RowSetRewindable rs1 = RowSet.create(qIter1, vars).rewindable();
    QueryIterator qIter2 = Algebra.exec(op2, dataset.asDatasetGraph());
    RowSetRewindable rs2 = RowSet.create(qIter2, vars).rewindable();
    ;
    equals(rs1, rs2);
    rs1.reset();
    rs2.reset();
    return rs1;
}
Also used : Op(org.apache.jena.sparql.algebra.Op) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Var(org.apache.jena.sparql.core.Var) RowSetRewindable(org.apache.jena.sparql.exec.RowSetRewindable) ArrayList(java.util.ArrayList)

Example 7 with RowSetRewindable

use of org.apache.jena.sparql.exec.RowSetRewindable in project jena by apache.

the class AbstractTestAdditional method substitute_1.

/**
 * Check substitution into patterns.
 */
@Test
public void substitute_1() {
    Dataset dataset = dataset();
    String resultsStr = StrUtils.strjoinNL("(resultset (?s ?p ?o)", "(row (?s :s1) (?p :p) (?o :o))", ")");
    RowSetRewindable expected = SSE.parseRowSet(resultsStr).rewindable();
    Txn.executeWrite(dataset, () -> {
        String data = StrUtils.strjoinNL("(dataset", "  (:g1 :s1 :p :o)", "  (:g1 :s2 :p :o)", "  (:g2 :s1 :p :o)", "  (:g2 :s2 :p :o)", ")");
        DatasetGraph dsg = SSE.parseDatasetGraph(data);
        dataset.asDatasetGraph().addAll(dsg);
        String qs = PREFIXES + "SELECT * { VALUES ?s { :s1 } GRAPH <" + Quad.unionGraph + "> { ?s ?p ?o } }";
        Query query = QueryFactory.create(qs);
        try (QueryExec qExec = QueryExec.dataset(dsg).query(query).build()) {
            RowSetRewindable rs = qExec.select().rewindable();
            testRS(expected, rs);
        }
    });
}
Also used : QueryExec(org.apache.jena.sparql.exec.QueryExec) RowSetRewindable(org.apache.jena.sparql.exec.RowSetRewindable) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 8 with RowSetRewindable

use of org.apache.jena.sparql.exec.RowSetRewindable in project jena by apache.

the class ResultSetCompare method equalsByTerm.

/**
 * See {@link #equalsByTerm(ResultSet, ResultSet)}
 */
public static boolean equalsByTerm(RowSet rs1, RowSet rs2) {
    if (!compareHeader(rs1, rs2))
        return false;
    RowSetRewindable rs1a = rs1.rewindable();
    RowSetRewindable rs2a = rs2.rewindable();
    // Aligned rows
    if (equivalent(convert(rs1a), convert(rs2a), new BNodeIso(NodeUtils.sameNode)))
        return true;
    rs1a.reset();
    rs2a.reset();
    return isomorphic(rs1a, rs2a);
}
Also used : RowSetRewindable(org.apache.jena.sparql.exec.RowSetRewindable)

Aggregations

RowSetRewindable (org.apache.jena.sparql.exec.RowSetRewindable)8 Var (org.apache.jena.sparql.core.Var)3 ArrayList (java.util.ArrayList)2 Op (org.apache.jena.sparql.algebra.Op)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 Prologue (org.apache.jena.sparql.core.Prologue)1 Binding (org.apache.jena.sparql.engine.binding.Binding)1 QueryExec (org.apache.jena.sparql.exec.QueryExec)1 SerializationContext (org.apache.jena.sparql.serializer.SerializationContext)1 Test (org.junit.Test)1