Class RepositoryFederatedService
java.lang.Object
org.eclipse.rdf4j.repository.sparql.federation.RepositoryFederatedService
- All Implemented Interfaces:
FederatedService
- Direct Known Subclasses:
RepositoryFederatedService
,SPARQLFederatedService
Federated Service wrapping the
Repository
to communicate with a SPARQL endpoint.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
A convenience iteration for SERVICE expression which evaluates intermediate results in batches and manages all results.private static class
Wrapper iteration which closes aRepositoryConnection
uponRepositoryFederatedService.CloseConnectionIteration.close()
private class
Helper iteration to evaluate a block ofBindingSet
s using the simpleselect(Service, Set, BindingSet, String)
routine. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
The number of bindings sent in a single subquery inevaluate(Service, CloseableIteration, String)
If blockSize is set to 0, the entire input stream is used as block input the block size effectively determines the number of remote requests(package private) static final org.slf4j.Logger
private RepositoryConnection
private final Repository
private static final String
protected boolean
private boolean
Whether to use a fresh repository connection for individual queries -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
ask
(Service service, BindingSet bindings, String baseUri) Evaluate the provided sparqlQueryString at the initializedRepository
of thisFederatedService
.private String
buildVALUESClause
(List<BindingSet> bindings, List<String> relevantBindingNames) Computes the VALUES clause for the set of relevant input bindings.private static void
evaluate
(Service service, CloseableIteration<BindingSet, QueryEvaluationException> bindings, String baseUri) Evaluate the provided SPARQL query at this federated service, possibilities for vectored evaluation.protected CloseableIteration
<BindingSet, QueryEvaluationException> evaluateInternal
(Service service, CloseableIteration<BindingSet, QueryEvaluationException> bindings, String baseUri) Evaluate the SPARQL query that can be constructed from the SERVICE node at the initializedRepository
of thisFederatedService
.evaluateInternalFallback
(Service service, List<BindingSet> allBindings, String baseUri) Evaluate the service expression for the given lists of bindings usingRepositoryFederatedService.FallbackServiceIteration
, i.e.private RepositoryConnection
Return a freshRepositoryConnection
from the configured repository.int
protected RepositoryConnection
Retrieve a (re-usable) connection.getRelevantBindingNames
(List<BindingSet> bindings, Set<String> serviceVars) Compute the relevant binding names using the variables occurring in the service expression and the input bindings.void
Method to perform any initializations, invoked after construction.protected String
insertValuesClause
(String queryString, String valuesClause) Insert the constructed VALUES clause in the beginning of the WHERE block.boolean
Method to check ifFederatedService.initialize()
had been called.Evaluate the provided sparqlQueryString at the initializedRepository
of thisFederatedService
.void
setBoundJoinBlockSize
(int boundJoinBlockSize) void
setUseFreshConnection
(boolean flag) void
shutdown()
Method to perform any shutDown code, invoked at unregistering.
-
Field Details
-
ROW_IDX_VAR
- See Also:
-
logger
static final org.slf4j.Logger logger -
rep
-
boundJoinBlockSize
protected int boundJoinBlockSizeThe number of bindings sent in a single subquery inevaluate(Service, CloseableIteration, String)
If blockSize is set to 0, the entire input stream is used as block input the block size effectively determines the number of remote requests -
useFreshConnection
private boolean useFreshConnectionWhether to use a fresh repository connection for individual queries -
shutDown
protected boolean shutDown -
managedConn
-
-
Constructor Details
-
RepositoryFederatedService
- Parameters:
repo
- the repository to be used
-
RepositoryFederatedService
- Parameters:
repo
- the repository to be usedshutDown
- a flag indicating whether the repository shall be closed inshutdown()
-
-
Method Details
-
select
public CloseableIteration<BindingSet,QueryEvaluationException> select(Service service, Set<String> projectionVars, BindingSet bindings, String baseUri) throws QueryEvaluationException Evaluate the provided sparqlQueryString at the initializedRepository
of thisFederatedService
. Insert bindings into SELECT query and evaluate- Specified by:
select
in interfaceFederatedService
- Parameters:
service
- the reference to the service node, contains additional meta information (vars, prefixes)projectionVars
- The variables with unknown value that should be projected from this evaluationbindings
- the bindings serving as additional constraintsbaseUri
-- Returns:
- an iteration over the results of the query
- Throws:
QueryEvaluationException
- If there was an exception generated while evaluating the query.
-
ask
public boolean ask(Service service, BindingSet bindings, String baseUri) throws QueryEvaluationException Evaluate the provided sparqlQueryString at the initializedRepository
of thisFederatedService
. Insert bindings, send ask query and return final result- Specified by:
ask
in interfaceFederatedService
- Parameters:
service
- the reference to the service node, contains additional meta information (vars, prefixes)bindings
- the bindings serving as additional constraintsbaseUri
-- Returns:
true
if at least one result exists- Throws:
QueryEvaluationException
- If there was an exception generated while evaluating the query.
-
evaluate
public CloseableIteration<BindingSet,QueryEvaluationException> evaluate(Service service, CloseableIteration<BindingSet, QueryEvaluationException> bindings, String baseUri) throws QueryEvaluationExceptionDescription copied from interface:FederatedService
Evaluate the provided SPARQL query at this federated service, possibilities for vectored evaluation.Contracts:
- The original bindings need to be inserted into the result
- SILENT service must be dealt with in the method
Compare
SPARQLFederatedService
for a reference implementation- Specified by:
evaluate
in interfaceFederatedService
- Parameters:
service
- the reference to the service node, contains information to construct the querybindings
- the bindings serving as additional constraints (for vectored evaluation)baseUri
- the baseUri- Returns:
- the result of evaluating the query using bindings as constraints, the original bindings need to be inserted into the results!
- Throws:
QueryEvaluationException
- If there was an exception generated while evaluating the query.
-
evaluateInternal
protected CloseableIteration<BindingSet,QueryEvaluationException> evaluateInternal(Service service, CloseableIteration<BindingSet, QueryEvaluationException> bindings, String baseUri) throws QueryEvaluationExceptionEvaluate the SPARQL query that can be constructed from the SERVICE node at the initializedRepository
of thisFederatedService
. Use specified bindings as constraints to the query. Try to evaluate using VALUES clause, if this yields an exception fall back to the naive implementation. This method deals with SILENT SERVICEs.- Throws:
QueryEvaluationException
-
evaluateInternalFallback
private CloseableIteration<BindingSet,QueryEvaluationException> evaluateInternalFallback(Service service, List<BindingSet> allBindings, String baseUri) Evaluate the service expression for the given lists of bindings usingRepositoryFederatedService.FallbackServiceIteration
, i.e. basically as a simple join without VALUES clause.- Parameters:
service
- the SERVICEallBindings
- all bindings to be processedbaseUri
- the base URI- Returns:
- resulting iteration
-
insertValuesClause
Insert the constructed VALUES clause in the beginning of the WHERE block. Also adds theROW_IDX_VAR
projection if it is not already present.- Parameters:
queryString
- the SELECT query string from the SERVICE nodevaluesClause
- the constructed VALUES clause- Returns:
- the final String
-
initialize
Description copied from interface:FederatedService
Method to perform any initializations, invoked after construction.- Specified by:
initialize
in interfaceFederatedService
- Throws:
QueryEvaluationException
- If there was an exception generated while initializing the service.
-
isInitialized
public boolean isInitialized()Description copied from interface:FederatedService
Method to check ifFederatedService.initialize()
had been called.- Specified by:
isInitialized
in interfaceFederatedService
-
getBoundJoinBlockSize
public int getBoundJoinBlockSize() -
setBoundJoinBlockSize
public void setBoundJoinBlockSize(int boundJoinBlockSize) - Parameters:
boundJoinBlockSize
- the bound join block size, 0 to evaluate all in a single request
-
setUseFreshConnection
public void setUseFreshConnection(boolean flag) - Parameters:
flag
- whether to use a freshRepositoryConnection
for each individual query
-
shutdown
Description copied from interface:FederatedService
Method to perform any shutDown code, invoked at unregistering.- Specified by:
shutdown
in interfaceFederatedService
- Throws:
QueryEvaluationException
- If there was an exception generated while shutting down the service.
-
freshConnection
Return a freshRepositoryConnection
from the configured repository.- Returns:
- connection
- Throws:
RepositoryException
-
getConnection
Retrieve a (re-usable) connection. If it is not yet created, open a fresh connection. Note that this connection is closed automatically when shutting this service.- Returns:
- connection
- Throws:
RepositoryException
-
getRelevantBindingNames
Compute the relevant binding names using the variables occurring in the service expression and the input bindings. The idea is find all variables which need to be projected in the subquery, i.e. those that will not be bound by an input binding.If the resulting list is empty, the cross product needs to be formed.
- Parameters:
bindings
-serviceVars
-- Returns:
- the list of relevant bindings (if empty: the cross product needs to be formed)
-
buildVALUESClause
private String buildVALUESClause(List<BindingSet> bindings, List<String> relevantBindingNames) throws QueryEvaluationException Computes the VALUES clause for the set of relevant input bindings. The VALUES clause is attached to a subquery for block-nested-loop evaluation. Implementation note: we use a special binding to mark the rowIndex of the input binding.- Parameters:
bindings
-relevantBindingNames
-- Returns:
- a string with the VALUES clause for the given set of relevant input bindings
- Throws:
QueryEvaluationException
-
closeQuietly
-