Search in sources :

Example 91 with Binding

use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.

the class TSVInputIterator method moveToNextBinding.

@Override
protected Binding moveToNextBinding() {
    if (!hasNext())
        throw new NoSuchElementException();
    Binding b = this.binding;
    this.binding = null;
    return b;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) NoSuchElementException(java.util.NoSuchElementException)

Example 92 with Binding

use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.

the class JSONInputIterator method moveToNextBinding.

@Override
protected Binding moveToNextBinding() {
    if (!hasNext())
        throw new NoSuchElementException();
    Binding b = this.binding;
    this.binding = null;
    return b;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding)

Example 93 with Binding

use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.

the class TestQueryExecutionTimeout2 method test2.

private static void test2(long timeout1, long timeout2, int delay, boolean exceptionExpected) {
    // Enough rows to keep the iterator pipeline full.
    try (QueryExecution qExec = QueryExecutionFactory.create(prefix + "SELECT * { ?s ?p ?o }", ds)) {
        qExec.setTimeout(timeout1, timeout2);
        // No rewrite optimizations.
        // qExec.getContext().set(ARQConstants.sysOptimizerFactory, Optimize.noOptimizationFactory) ;
        ResultSet rs = qExec.execSelect();
        // ... wait for first binding.
        Binding b1 = rs.nextBinding();
        //System.err.println(b1) ;
        // ... then a possible timeout.
        sleep(delay);
        if (exceptionExpected)
            exceptionExpected(rs);
        else
            noException(rs);
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding)

Example 94 with Binding

use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.

the class SelectResultsMetadata method makeColumns.

/**
     * Makes column information for SELECT results
     * 
     * @param results
     *            Result Set
     * @param rset
     *            Underlying SPARQL results
     * @return Column information
     * @throws SQLException
     *             Thrown if the column information cannot be created
     */
private static ColumnInfo[] makeColumns(JenaResultSet results, ResultSetPeekable rset) throws SQLException {
    List<String> vars = rset.getResultVars();
    ColumnInfo[] columns = new ColumnInfo[vars.size()];
    int level = JdbcCompatibility.normalizeLevel(results.getJdbcCompatibilityLevel());
    boolean columnsAsStrings = JdbcCompatibility.shouldTypeColumnsAsString(level);
    boolean columnsDetected = JdbcCompatibility.shouldDetectColumnTypes(level);
    Binding b = null;
    if (columnsDetected) {
        if (rset.hasNext()) {
            b = rset.peekBinding();
        } else {
            // If we were supposed to detect columns but there is no data
            // available then we will just fallback to typing everything as
            // strings
            columnsAsStrings = true;
            columnsDetected = false;
        }
    }
    for (int i = 0; i < columns.length; i++) {
        if (!columnsAsStrings && !columnsDetected) {
            // Low compatibility, report columns as being typed as
            // JAVA_OBJECT with ARQ Node as the column class
            columns[i] = new SparqlColumnInfo(vars.get(i), Types.JAVA_OBJECT, columnNullable);
            LOGGER.info("Low JDBC compatibility, column " + vars.get(i) + " is being typed as Node");
        } else if (columnsAsStrings) {
            // Medium compatibility, report columns as being typed as
            // NVARCHAR with String as the column class
            columns[i] = new StringColumn(vars.get(i), columnNullable);
            LOGGER.info("Medium JDBC compatibility, column " + vars.get(i) + " is being typed as String");
        } else if (columnsDetected) {
            // High compatibility, detect columns types based on first row
            // of results
            columns[i] = JdbcCompatibility.detectColumnType(vars.get(i), b.get(Var.alloc(vars.get(i))), true);
            LOGGER.info("High compatibility, column " + vars.get(i) + " was detected as being of type " + columns[i].getClassName());
        } else {
            throw new SQLFeatureNotSupportedException("Unknown JDBC compatibility level was set");
        }
    }
    return columns;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) StringColumn(org.apache.jena.jdbc.results.metadata.columns.StringColumn) SparqlColumnInfo(org.apache.jena.jdbc.results.metadata.columns.SparqlColumnInfo) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) ColumnInfo(org.apache.jena.jdbc.results.metadata.columns.ColumnInfo) SparqlColumnInfo(org.apache.jena.jdbc.results.metadata.columns.SparqlColumnInfo)

Example 95 with Binding

use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.

the class TableJoin method joinWorkerN.

private static QueryIterator joinWorkerN(QueryIterator left, Table right, JoinType joinType, ExprList conditions, ExecutionContext execCxt) {
    List<Binding> out = new ArrayList<>();
    for (; left.hasNext(); ) {
        Binding bindingLeft = left.next();
        int count = 0;
        for (Iterator<Binding> iter = right.rows(); iter.hasNext(); ) {
            Binding bindingRight = iter.next();
            Binding r = Algebra.merge(bindingLeft, bindingRight);
            if (r == null)
                continue;
            // This does the conditional part. Theta-join.
            if (conditions == null || conditions.isSatisfied(r, execCxt)) {
                count++;
                out.add(r);
            }
        }
        if (count == 0 && (joinType == LEFT))
            // Conditions on left?
            out.add(bindingLeft);
    }
    return new QueryIterPlainWrapper(out.iterator(), execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) ArrayList(java.util.ArrayList)

Aggregations

Binding (org.apache.jena.sparql.engine.binding.Binding)132 Node (org.apache.jena.graph.Node)39 ArrayList (java.util.ArrayList)36 Var (org.apache.jena.sparql.core.Var)33 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)27 Test (org.junit.Test)21 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)16 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)10 BindingComparator (org.apache.jena.sparql.engine.binding.BindingComparator)8 BuilderBinding (org.apache.jena.sparql.sse.builders.BuilderBinding)8 NoSuchElementException (java.util.NoSuchElementException)7 Triple (org.apache.jena.graph.Triple)7 ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)7 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)5 Op (org.apache.jena.sparql.algebra.Op)5 BasicPattern (org.apache.jena.sparql.core.BasicPattern)5 ResultSet (org.apache.jena.query.ResultSet)4 SortCondition (org.apache.jena.query.SortCondition)4 TableN (org.apache.jena.sparql.algebra.table.TableN)4 File (java.io.File)3