org.eclipse.rdf4j.query.BindingSet Java Examples

The following examples show how to use org.eclipse.rdf4j.query.BindingSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StrictEvaluationStrategyTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Verifies if only those input bindings that actually occur in the query are returned in the result. See SES-2373.
 */
@Test
public void testBindings() throws Exception {
	String query = "SELECT ?a ?b WHERE {}";
	ParsedQuery pq = QueryParserUtil.parseQuery(QueryLanguage.SPARQL, query, null);

	final ValueFactory vf = SimpleValueFactory.getInstance();
	QueryBindingSet constants = new QueryBindingSet();
	constants.addBinding("a", vf.createLiteral("foo"));
	constants.addBinding("b", vf.createLiteral("bar"));
	constants.addBinding("x", vf.createLiteral("X"));
	constants.addBinding("y", vf.createLiteral("Y"));

	CloseableIteration<BindingSet, QueryEvaluationException> result = strategy.evaluate(pq.getTupleExpr(),
			constants);
	assertNotNull(result);
	assertTrue(result.hasNext());
	BindingSet bs = result.next();
	assertTrue(bs.hasBinding("a"));
	assertTrue(bs.hasBinding("b"));
	assertFalse(bs.hasBinding("x"));
	assertFalse(bs.hasBinding("y"));
}
 
Example #2
Source File: StrictEvaluationStrategy.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Value evaluate(Str node, BindingSet bindings) throws QueryEvaluationException {
	Value argValue = evaluate(node.getArg(), bindings);

	if (argValue instanceof IRI) {
		return tripleSource.getValueFactory().createLiteral(argValue.toString());
	} else if (argValue instanceof Literal) {
		Literal literal = (Literal) argValue;

		if (QueryEvaluationUtil.isSimpleLiteral(literal)) {
			return literal;
		} else {
			return tripleSource.getValueFactory().createLiteral(literal.getLabel());
		}
	} else if (argValue instanceof Triple) {
		return tripleSource.getValueFactory().createLiteral(argValue.toString());
	} else {
		throw new ValueExprEvaluationException();
	}
}
 
Example #3
Source File: QueryEvaluationUtil.java    From semagrow with Apache License 2.0 6 votes vote down vote up
public static BindingSet project(ProjectionElemList projElemList,
                                 BindingSet sourceBindings,
                                 BindingSet parentBindings)
{
    QueryBindingSet resultBindings = new QueryBindingSet(parentBindings);

    for (ProjectionElem pe : projElemList.getElements()) {
        Value targetValue = sourceBindings.getValue(pe.getSourceName());
        if (targetValue != null) {
            // Potentially overwrites bindings from super
            resultBindings.setBinding(pe.getTargetName(), targetValue);
        }
    }

    return resultBindings;
}
 
Example #4
Source File: SPARQLServiceEvaluationTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Verify that BIND clause alias from the SERVICE clause gets added to the result set.
 *
 * @see <a href="https://github.com/eclipse/rdf4j/issues/646">#646</a>
 */
@Test
public void testValuesBindClauseHandling() throws Exception {
	String query = "select * { service <" + getRepositoryUrl(1) + "> { Bind(1 as ?val) . VALUES ?x {1 2} . } }";

	try (RepositoryConnection conn = localRepository.getConnection()) {
		TupleQuery tq = conn.prepareTupleQuery(query);
		TupleQueryResult tqr = tq.evaluate();

		assertNotNull(tqr);
		assertTrue(tqr.hasNext());

		List<BindingSet> result = QueryResults.asList(tqr);
		assertEquals(2, result.size());
		for (BindingSet bs : result) {
			assertTrue(bs.hasBinding("val"));
			assertEquals(1, Literals.getIntValue(bs.getValue("val"), 0));
			assertTrue(bs.hasBinding("x"));
			int x = Literals.getIntValue(bs.getValue("x"), 0);
			assertTrue(x == 1 || x == 2);
		}
	}
}
 
Example #5
Source File: LuceneSailConnection.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public synchronized CloseableIteration<? extends BindingSet, QueryEvaluationException> evaluate(TupleExpr tupleExpr,
		Dataset dataset, BindingSet bindings, boolean includeInferred) throws SailException {
	QueryContext qctx = new QueryContext();
	SearchIndexQueryContextInitializer.init(qctx, luceneIndex);

	final CloseableIteration<? extends BindingSet, QueryEvaluationException> iter;
	qctx.begin();
	try {
		iter = evaluateInternal(tupleExpr, dataset, bindings, includeInferred);
	} finally {
		qctx.end();
	}

	// NB: Iteration methods may do on-demand evaluation hence need to wrap
	// these too
	return new QueryContextIteration(iter, qctx);
}
 
Example #6
Source File: RDFStoreTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int verifyQueryResult(CloseableIteration<? extends BindingSet, QueryEvaluationException> resultIter,
		int expectedBindingCount) throws QueryEvaluationException {
	int resultCount = 0;

	while (resultIter.hasNext()) {
		BindingSet resultBindings = resultIter.next();
		resultCount++;

		Assert.assertEquals("Wrong number of binding names for binding set", expectedBindingCount,
				resultBindings.getBindingNames().size());

		int bindingCount = 0;
		Iterator<Binding> bindingIter = resultBindings.iterator();
		while (bindingIter.hasNext()) {
			bindingIter.next();
			bindingCount++;
		}

		Assert.assertEquals("Wrong number of bindings in binding set", expectedBindingCount, bindingCount);
	}

	return resultCount;
}
 
Example #7
Source File: BindingSetHashJoinIterator.java    From rya with Apache License 2.0 6 votes vote down vote up
@Override
public boolean hasNext() throws QueryEvaluationException {
	if (!hasNextCalled && !isEmpty) {
		while (joinedBindingSets.hasNext() || joinIter.hasNext()) {
			if (!joinedBindingSets.hasNext()) {
				Entry<String, BindingSet> entry = joinIter.next();
				joinedBindingSets = joinBindingSetEntry(entry);
			}
			if (!joinedBindingSets.hasNext()) {
				continue;
			}
			next = joinedBindingSets.next();
			hasNextCalled = true;
			return true;
		}

		isEmpty = true;
		return false;
	} else {
		return !isEmpty;
	}
}
 
Example #8
Source File: BindingSetStringConverterTest.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * Ensures that when a binding set is converted from a String back to a
 * BindingSet, null values do not get converted into Bindings.
 */
@Test
public void fromString_nullValues() throws BindingSetConversionException {
    // Setup the String that will be converted.
    final String bindingSetString =
            "http://value 1<<~>>http://www.w3.org/2001/XMLSchema#anyURI:::" +
            BindingSetStringConverter.NULL_VALUE_STRING + ":::" +
            "http://value 2<<~>>http://www.w3.org/2001/XMLSchema#anyURI:::" +
            BindingSetStringConverter.NULL_VALUE_STRING;

    // Convert it to a BindingSet
    final VariableOrder varOrder = new VariableOrder("x", "a", "y", "b");
    final BindingSetConverter<String> converter = new BindingSetStringConverter();
    final BindingSet bindingSet = converter.convert(bindingSetString, varOrder);

    // Ensure it converted to the expected reuslt.
    final MapBindingSet expected = new MapBindingSet();
    expected.addBinding("x", VF.createIRI("http://value 1"));
    expected.addBinding("y", VF.createIRI("http://value 2"));

    assertEquals(expected, bindingSet);
}
 
Example #9
Source File: HashJoinIterationTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testInnerJoin() throws QueryEvaluationException {
	BindingSetAssignment left = new BindingSetAssignment();
	{
		QueryBindingSet leftb = new QueryBindingSet();
		leftb.addBinding("a", vf.createLiteral("1"));
		leftb.addBinding("i", vf.createLiteral("x"));
		left.setBindingSets(Arrays.<BindingSet>asList(leftb));
	}

	BindingSetAssignment right = new BindingSetAssignment();
	{
		QueryBindingSet rightb = new QueryBindingSet();
		rightb.addBinding("b", vf.createLiteral("2"));
		rightb.addBinding("i", vf.createLiteral("x"));
		right.setBindingSets(Arrays.<BindingSet>asList(rightb));
	}

	HashJoinIteration iter = new HashJoinIteration(evaluator, left, right, EmptyBindingSet.getInstance(), false);
	BindingSet actual = iter.next();

	assertEquals("1", actual.getValue("a").stringValue());
	assertEquals("2", actual.getValue("b").stringValue());
	assertEquals("x", actual.getValue("i").stringValue());
}
 
Example #10
Source File: QueryBenchmark.java    From rya with Apache License 2.0 6 votes vote down vote up
public void run() throws MalformedQueryException, QueryEvaluationException, NotEnoughResultsException, SailException {
    CloseableIteration<? extends BindingSet, QueryEvaluationException> it = null;

    try {
        // Execute the query.
        final SPARQLParser sparqlParser = new SPARQLParser();
        final ParsedQuery parsedQuery = sparqlParser.parseQuery(sparql, null);
        it = sailConn.evaluate(parsedQuery.getTupleExpr(), null, null, false);

        // Perform the reads.
        if(numReads.isPresent()) {
            read(it, numReads.get() );
        } else {
            readAll(it);
        }
    } finally {
        if(it != null) {
            it.close();
        }
    }
}
 
Example #11
Source File: PcjIntegrationTestingUtil.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * Create the {@link Mutations} required to write a new {@link BindingSet}
 * to a PCJ table for each {@link VariableOrder} that is provided.
 *
 * @param varOrders
 *            - The variables orders the result will be written to. (not
 *            null)
 * @param result
 *            - A new PCJ result. (not null)
 * @return Mutation that will write the result to a PCJ table.
 * @throws PcjException
 *             The binding set could not be encoded.
 */
private static Set<Mutation> makeWriteResultMutations(
        final Set<VariableOrder> varOrders, final BindingSet result)
                throws PcjException {
    checkNotNull(varOrders);
    checkNotNull(result);

    final Set<Mutation> mutations = new HashSet<>();

    for (final VariableOrder varOrder : varOrders) {
        try {
            // Serialize the result to the variable order.
            final byte[] serializedResult = converter.convert(result, varOrder);

            // Row ID = binding set values, Column Family = variable order
            // of the binding set.
            final Mutation addResult = new Mutation(serializedResult);
            addResult.put(varOrder.toString(), "", "");
            mutations.add(addResult);
        } catch (final BindingSetConversionException e) {
            throw new PcjException("Could not serialize a result.", e);
        }
    }

    return mutations;
}
 
Example #12
Source File: PcjTables.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * Get an {@link Iterator} over the {@link BindingSet}s that are stored in the PCJ table.
 *
 * @param accumuloConn - A connection to the Accumulo that hsots the PCJ table. (not null)
 * @param pcjTableName - The name of the PCJ table that will be scanned. (not null)
 * @param auths - the user's authorizations that will be used to scan the table. (not null)
 * @return An iterator over all of the {@link BindingSet}s that are stored as
 *   results for the PCJ.
 * @throws PCJStorageException The binding sets could not be fetched.
 */
public CloseableIterator<BindingSet> listResults(final Connector accumuloConn, final String pcjTableName, final Authorizations auths) throws PCJStorageException {
    requireNonNull(pcjTableName);

    // Fetch the Variable Orders for the binding sets and choose one of them. It
    // doesn't matter which one we choose because they all result in the same output.
    final PcjMetadata metadata = getPcjMetadata(accumuloConn, pcjTableName);
    final VariableOrder varOrder = metadata.getVarOrders().iterator().next();

    try {
        // Fetch only the Binding Sets whose Variable Order matches the selected one.
        final Scanner scanner = accumuloConn.createScanner(pcjTableName, auths);
        scanner.fetchColumnFamily( new Text(varOrder.toString()) );

        // Return an Iterator that uses that scanner.
        return new ScannerBindingSetIterator(scanner, varOrder);

    } catch (final TableNotFoundException e) {
        throw new PCJStorageException(String.format("PCJ Table does not exist for name '%s'.", pcjTableName), e);
    }
}
 
Example #13
Source File: StatementPatternMatcherTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void variableContext_contextFreeStatement() throws Exception {
    // Create a matcher against a pattern that matches a variable context.
    final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp(
            "SELECT * WHERE {" +
                "GRAPH ?c {" +
                    "?s ?p ?o ." +
                "}" +
            "}"));

    // Create a statement that does not have a context value.
    final ValueFactory vf = SimpleValueFactory.getInstance();
    final Statement statement = vf.createStatement(vf.createIRI("urn:Alice"), vf.createIRI("urn:talksTo"), vf.createIRI("urn:Bob"));

    // Show the statement did not match.
    final Optional<BindingSet> bs = matcher.match(statement);
    assertFalse(bs.isPresent());
}
 
Example #14
Source File: SimpleCardinalityEstimator.java    From semagrow with Apache License 2.0 5 votes vote down vote up
public BigInteger getCardinality(BindingSetAssignment assignment){
    Iterator<BindingSet> it = assignment.getBindingSets().iterator();

    int i = 0;

    while (it.hasNext()) {
        it.next();
        i++;
    }

    return BigInteger.valueOf(i);
}
 
Example #15
Source File: KafkaLatencyBenchmark.java    From rya with Apache License 2.0 5 votes vote down vote up
private void updatePeriodicStatsFromKafka(final String topic) {
    try (KafkaConsumer<String, BindingSet> consumer = new KafkaConsumer<>(options.getKafkaConsumerProperties(), new StringDeserializer(), new BindingSetSerDe())) {
        consumer.subscribe(Arrays.asList(topic));
        while (!futureList.isEmpty()) {
            final ConsumerRecords<String, BindingSet> records = consumer.poll(500);  // check kafka at most twice a second.
            handle(records);
        }
    } catch (final Exception e) {
        logger.warn("Exception occurred", e);
    }
}
 
Example #16
Source File: StatementMetadataNode.java    From rya with Apache License 2.0 5 votes vote down vote up
public PropertyFilterAndBindingSetJoinIteration(
        final CloseableIteration<? extends Entry<RyaStatement, BindingSet>, RyaDAOException> statements,
        final Map<RyaIRI, Var> properties, final StatementPattern sp) {
    this.statements = statements;
    this.properties = properties;
    this.sp = sp;
}
 
Example #17
Source File: EvaluationStrategyImpl.java    From semagrow with Apache License 2.0 5 votes vote down vote up
public void processAggregate(BindingSet s) throws QueryEvaluationException {
    Value v = this.evaluate(s);
    if(this.distinctValue(v)) {
        if(this.max == null) {
            this.max = v;
        } else if(this.comparator.compare(v, this.max) > 0) {
            this.max = v;
        }
    }

}
 
Example #18
Source File: VOIDStatistics.java    From semagrow with Apache License 2.0 5 votes vote down vote up
public StatsItem getStats(final StatementPattern pattern, BindingSet bindings) {
    return new StatsItemImpl(pattern,
            getPatternCount(pattern, (IRI)site.getID()),
            getDistinctSubjects(pattern,(IRI) site.getID()),
            getDistinctPredicates(pattern, (IRI)site.getID()),
            getDistinctObjects(pattern, (IRI) site.getID()));
}
 
Example #19
Source File: SparqlTripleSource.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> getStatements(
		StatementPattern stmt, BindingSet bindings, FilterValueExpr filterExpr, QueryInfo queryInfo)
		throws RepositoryException, MalformedQueryException,
		QueryEvaluationException {

	throw new RuntimeException("NOT YET IMPLEMENTED.");
}
 
Example #20
Source File: ComplexSPARQLQueryTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean containsSolution(List<BindingSet> result, Binding... solution) {
	final MapBindingSet bs = new MapBindingSet();
	for (Binding b : solution) {
		bs.addBinding(b);
	}
	return result.contains(bs);
}
 
Example #21
Source File: HalyardTupleExprEvaluation.java    From Halyard with Apache License 2.0 5 votes vote down vote up
/**
 * Evaluate {@link SingletonSet} query model nodes
 * @param parent
 * @param singletonSet
 * @param bindings
 */
private void evaluateSingletonSet(BindingSetPipe parent, SingletonSet singletonSet, BindingSet bindings) {
    try {
        if (parent.push(bindings)) {
            parent.push(null);
        }
    } catch (InterruptedException e) {
        parent.handleException(e);
    }
}
 
Example #22
Source File: AccumuloIndexSetTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void accumuloIndexSetTestWithNoBindingSet() throws RepositoryException, PcjException, TableNotFoundException,
RyaTypeResolverException, MalformedQueryException, SailException, QueryEvaluationException, AccumuloException, AccumuloSecurityException {
    // Load some Triples into Rya.
    final Set<Statement> triples = new HashSet<>();
    triples.add( VF.createStatement(VF.createIRI("http://Alice"), VF.createIRI("http://hasAge"), VF.createLiteral(BigInteger.valueOf(14))) );
    triples.add( VF.createStatement(VF.createIRI("http://Alice"), VF.createIRI("http://playsSport"), VF.createLiteral("Soccer")) );
    triples.add( VF.createStatement(VF.createIRI("http://Bob"), VF.createIRI("http://hasAge"), VF.createLiteral(BigInteger.valueOf(16))) );
    triples.add( VF.createStatement(VF.createIRI("http://Bob"), VF.createIRI("http://playsSport"), VF.createLiteral("Soccer")) );
    triples.add( VF.createStatement(VF.createIRI("http://Charlie"), VF.createIRI("http://hasAge"), VF.createLiteral(BigInteger.valueOf(12))) );
    triples.add( VF.createStatement(VF.createIRI("http://Charlie"), VF.createIRI("http://playsSport"), VF.createLiteral("Soccer")) );
    triples.add( VF.createStatement(VF.createIRI("http://Eve"), VF.createIRI("http://hasAge"), VF.createLiteral(43)) );
    triples.add( VF.createStatement(VF.createIRI("http://Eve"), VF.createIRI("http://playsSport"), VF.createLiteral("Soccer")) );

    for(final Statement triple : triples) {
        ryaConn.add(triple);
    }

    // Create a PCJ table will include those triples in its results.
    final String sparql =
            "SELECT ?name ?age " +
            "{" +
              "FILTER(?age < 30) ." +
              "?name <http://hasAge> ?age." +
              "?name <http://playsSport> \"Soccer\" " +
            "}";

    final String pcjTableName = new PcjTableNameFactory().makeTableName(prefix, "testPcj");

    // Create and populate the PCJ table.
    PcjIntegrationTestingUtil.createAndPopulatePcj(ryaConn, accumuloConn, pcjTableName, sparql, new String[]{"name", "age"}, Optional.absent());

    final AccumuloIndexSet ais = new AccumuloIndexSet(conf, pcjTableName);

    final CloseableIteration<BindingSet, QueryEvaluationException> results = ais.evaluate(new HashSet<BindingSet>());

    Assert.assertEquals(false, results.hasNext());

}
 
Example #23
Source File: MaxCountBenchmarkEmpty.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Benchmark
public void sparqlGroupByInsteadOfShacl() {

	SailRepository repository = new SailRepository(new MemoryStore());

	repository.init();

	try (SailRepositoryConnection connection = repository.getConnection()) {
		connection.begin();
		connection.commit();
	}
	try (SailRepositoryConnection connection = repository.getConnection()) {
		for (List<Statement> statements : allStatements) {
			connection.begin();
			connection.add(statements);
			try (Stream<BindingSet> stream = connection
					.prepareTupleQuery("select ?a (count(?c) as ?count) where {?a a <" + RDFS.RESOURCE + ">. ?a <"
							+ RDFS.LABEL + "> ?c} group by ?a having(?count > 1)")
					.evaluate()
					.stream()) {
				stream.forEach(System.out::println);
			}
			connection.commit();
		}
	}
	repository.shutDown();

}
 
Example #24
Source File: FederatedEvaluationStrategyImpl.java    From semagrow with Apache License 2.0 5 votes vote down vote up
public Flux<BindingSet> evaluateReactorInternal(SourceQuery expr, List<BindingSet> bindingList)
        throws QueryEvaluationException
{
    LoggingUtil.logSourceQuery(logger, expr);

    //return queryExecutor.evaluateReactorInternal(null, expr.getArg(), bindings)
    return evaluateSourceReactive(expr.getSite(), expr.getArg(), bindingList);

}
 
Example #25
Source File: RepositoryConnectionTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testPreparedTupleQuery() throws Exception {
	testCon.add(alice, name, nameAlice, context2);
	testCon.add(alice, mbox, mboxAlice, context2);
	testCon.add(context2, publisher, nameAlice);
	testCon.add(bob, name, nameBob, context1);
	testCon.add(bob, mbox, mboxBob, context1);
	testCon.add(context1, publisher, nameBob);
	StringBuilder queryBuilder = new StringBuilder();
	queryBuilder.append(" SELECT name, mbox");
	queryBuilder.append(" FROM {} foaf:name {name};");
	queryBuilder.append("         foaf:mbox {mbox}");
	queryBuilder.append(" USING NAMESPACE foaf = <" + FOAF_NS + ">");
	TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SERQL, queryBuilder.toString());
	query.setBinding(NAME, nameBob);

	try (TupleQueryResult result = query.evaluate();) {
		assertThat(result).isNotNull();
		assertThat(result.hasNext()).isTrue();
		while (result.hasNext()) {
			BindingSet solution = result.next();
			assertThat(solution.hasBinding(NAME)).isTrue();
			assertThat(solution.hasBinding(MBOX)).isTrue();
			Value nameResult = solution.getValue(NAME);
			Value mboxResult = solution.getValue(MBOX);
			assertEquals("unexpected value for name: " + nameResult, nameBob, nameResult);
			assertEquals("unexpected value for mbox: " + mboxResult, mboxBob, mboxResult);
		}
	}
}
 
Example #26
Source File: IndependentJoingroupBindingsIteration2.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected BindingSet getNextElement() throws QueryEvaluationException {
	
	if (result==null) {
		result = computeResult();
	}
	
	if (currentIdx>=result.size())
		return null;
	
	return result.get(currentIdx++);
}
 
Example #27
Source File: FederationStrategy.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(TupleExpr expr, BindingSet bindings)
		throws QueryEvaluationException {
	CloseableIteration<BindingSet, QueryEvaluationException> result;
	if (expr instanceof NaryJoin) {
		result = evaluate((NaryJoin) expr, bindings);
	} else if (expr instanceof OwnedTupleExpr) {
		result = evaluate((OwnedTupleExpr) expr, bindings);
	} else {
		result = super.evaluate(expr, bindings);
	}
	return result;
}
 
Example #28
Source File: EvaluationStrategyImpl.java    From semagrow with Apache License 2.0 5 votes vote down vote up
public Observable<BindingSet> evaluateReactiveInternal(Extension expr, BindingSet bindings)
        throws QueryEvaluationException
{
    return evaluateReactiveInternal(expr.getArg(), bindings)
            .concatMap((b) -> {
                try {
                    return Observable.just(QueryEvaluationUtil.extend(this, expr.getElements(), b));
                } catch (Exception e) {
                    return Observable.error(e);
                }
            }).onErrorResumeNext(Observable::error);
}
 
Example #29
Source File: BindJoinImpl.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void handleRestart() {
	iteration.restart();
	if (leftIter instanceof RestartableCloseableIteration) {
		((RestartableCloseableIteration<BindingSet>) leftIter).restart();
	}
	scheduler.schedule(new AsyncBindingTask());
}
 
Example #30
Source File: SparqlFederationEvalStrategy.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluateBoundJoinStatementPattern(
		StatementTupleExpr stmt, List<BindingSet> bindings)
{
	// we can omit the bound join handling
	if (bindings.size()==1)
		return evaluate(stmt, bindings.get(0));
			
	FilterValueExpr filterExpr = null;
	if (stmt instanceof FilterTuple)
		filterExpr = ((FilterTuple)stmt).getFilterExpr();
	
	Boolean isEvaluated = false;
	String preparedQuery = QueryStringUtil.selectQueryStringBoundUnion((StatementPattern)stmt, bindings, filterExpr, isEvaluated);
	
	CloseableIteration<BindingSet, QueryEvaluationException> result = evaluateAtStatementSources(preparedQuery, stmt.getStatementSources(), stmt.getQueryInfo());
					
	// apply filter and/or convert to original bindings
	if (filterExpr!=null && !isEvaluated) {
		result = new BoundJoinConversionIteration(result, bindings);		// apply conversion
		result = new FilteringIteration(this, filterExpr, result);				// apply filter
		if (!result.hasNext()) {
			result.close();
			return new EmptyIteration<BindingSet, QueryEvaluationException>();
		}
	} else {
		result = new BoundJoinConversionIteration(result, bindings);
	}
		
	// in order to avoid leakage of http route during the iteration
	return new BufferedCloseableIterator<BindingSet, QueryEvaluationException>(result);		
}