Search in sources :

Example 1 with RowSetRewindable

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

the class TestSolverTDB method same.

private static void same(RowSet rs1, RowSet rs2, boolean result) {
    RowSetRewindable rsw1 = rs1.rewindable();
    RowSetRewindable rsw2 = rs2.rewindable();
    boolean b = ResultSetCompare.equalsByValue(rsw1, rsw2);
    if (b != result) {
        System.out.println("Different: ");
        rsw1.reset();
        rsw2.reset();
        RowSetOps.out(rsw1);
        RowSetOps.out(rsw2);
        System.out.println();
    }
    assertTrue(b == result);
}
Also used : RowSetRewindable(org.apache.jena.sparql.exec.RowSetRewindable)

Example 2 with RowSetRewindable

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

the class TestSolverTDB method same.

private static void same(RowSet rs1, RowSet rs2, boolean result) {
    RowSetRewindable rsw1 = rs1.rewindable();
    RowSetRewindable rsw2 = rs2.rewindable();
    boolean b = ResultSetCompare.equalsByValue(rsw1, rsw2);
    if (b != result) {
        System.out.println("Different: ");
        rsw1.reset();
        rsw2.reset();
        RowSetOps.out(rsw1);
        RowSetOps.out(rsw2);
        System.out.println();
    }
    assertTrue(b == result);
}
Also used : RowSetRewindable(org.apache.jena.sparql.exec.RowSetRewindable)

Example 3 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 4 with RowSetRewindable

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

the class RowSetWriterText method output$.

private static void output$(AWriter out, RowSet rowSet, String colStart, String colSep, String colEnd, Context cxt) {
    Prologue prologue = choosePrologue(rowSet, cxt);
    SerializationContext context = new SerializationContext(prologue);
    try {
        if (rowSet.getResultVars().size() == 0) {
            out.println("==== No variables ====");
        }
        RowSetRewindable resultSetRewindable = rowSet.rewindable();
        int numCols = resultSetRewindable.getResultVars().size();
        int[] colWidths = colWidths(resultSetRewindable, context);
        String[] row = new String[numCols];
        int lineWidth = 0;
        for (int col = 0; col < numCols; col++) {
            String rVar = rowSet.getResultVars().get(col).getVarName();
            row[col] = rVar;
            lineWidth += colWidths[col];
            if (col > 0)
                lineWidth += colSep.length();
        }
        if (colStart != null)
            lineWidth += colStart.length();
        if (colEnd != null)
            lineWidth += colEnd.length();
        for (int i = 0; i < lineWidth; i++) out.print('-');
        out.println();
        printRow(out, row, colWidths, colStart, colSep, colEnd);
        for (int i = 0; i < lineWidth; i++) out.print('=');
        out.println();
        for (; resultSetRewindable.hasNext(); ) {
            Binding rBind = resultSetRewindable.next();
            for (int col = 0; col < numCols; col++) {
                Var var = rowSet.getResultVars().get(col);
                row[col] = getVarValueAsString(rBind, var, context);
            }
            printRow(out, row, colWidths, colStart, colSep, colEnd);
        }
        for (int i = 0; i < lineWidth; i++) out.print('-');
        out.println();
        resultSetRewindable = null;
    } finally {
        out.flush();
    }
}
Also used : SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) Binding(org.apache.jena.sparql.engine.binding.Binding) Prologue(org.apache.jena.sparql.core.Prologue) RowSetRewindable(org.apache.jena.sparql.exec.RowSetRewindable) Var(org.apache.jena.sparql.core.Var)

Example 5 with RowSetRewindable

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

the class ResultSetCompare method equalsByValue.

/**
 * See {@link #equalsByValue(ResultSet, ResultSet)}
 */
public static boolean equalsByValue(RowSet rs1, RowSet rs2) {
    if (!compareHeader(rs1, rs2))
        return false;
    RowSetRewindable rs1a = rs1.rewindable();
    RowSetRewindable rs2a = rs2.rewindable();
    if (equivalent(convert(rs1a), convert(rs2a), new BNodeIso(NodeUtils.sameValue)))
        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