Package org.eclipse.rdf4j.federated.util
Class QueryAlgebraUtil
java.lang.Object
org.eclipse.rdf4j.federated.util.QueryAlgebraUtil
Various static functions for query handling and parsing (alegbra expression).
- Author:
- Andreas Schwarte
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static Var
appendVar
(Var var, Set<String> varNames, BindingSet bindings) Clone the specified variable and attach bindings.protected static Var
appendVarId
(Var var, String varID, Set<String> varNames, BindingSet bindings) Clone the specified variable and attach bindings, moreover change name of variable by appending "_varId" to it.protected static Union
constructInnerUnion
(StatementPattern stmt, int outerID, Set<String> varNames, List<BindingSet> bindings) protected static StatementPattern
constructStatement
(StatementPattern stmt, Set<String> varNames, BindingSet bindings) Construct the statement string, i.e.protected static TupleExpr
constructStatementCheckId
(StatementPattern stmt, int varID, Set<String> varNames, BindingSet bindings) Construct the statement string, i.e.protected static StatementPattern
constructStatementId
(StatementPattern stmt, String varID, Set<String> varNames, BindingSet bindings) Construct the statement string, i.e.static Collection
<String> getFreeVars
(TupleExpr tupleExpr) Computes the collection of free variables in the givenTupleExpr
.static Value
getVarValue
(Var var, BindingSet bindings) Return theValue
of the variable which is either taken from the variable itself (bound) or from the bindingsset (unbound).static boolean
hasFreeVars
(StatementPattern stmt, BindingSet bindings) returns true iff there is at least one free variable, i.e.static TupleExpr
selectQuery
(ExclusiveGroup group, BindingSet bindings, FilterValueExpr filterExpr, AtomicBoolean evaluated) Construct a SELECT query for the providedExclusiveGroup
.static TupleExpr
selectQuery
(StatementPattern stmt, BindingSet bindings, FilterValueExpr filterExpr, AtomicBoolean evaluated) Construct a SELECT query for the provided statement.static TupleExpr
selectQueryBoundUnion
(StatementPattern stmt, List<BindingSet> unionBindings, FilterValueExpr filterExpr, Boolean evaluated) Construct a SELECT query expression for a bound union.static TupleExpr
selectQueryStringBoundCheck
(StatementPattern stmt, List<BindingSet> unionBindings) Construct a SELECT query for a grouped bound check.static Statement
toStatement
(StatementPattern stmt) static Statement
toStatement
(StatementPattern stmt, BindingSet bindings) static StatementPattern
toStatementPattern
(Resource subj, IRI pred, Value obj) static StatementPattern
toStatementPattern
(Statement stmt) static TupleExpr
toTupleExpr
(ArbitraryLengthPath node, Set<String> varNames, BindingSet bindings) Convert the givenArbitraryLengthPath
to a freshTupleExpr
where all provided bindings are bound.
-
Constructor Details
-
QueryAlgebraUtil
public QueryAlgebraUtil()
-
-
Method Details
-
hasFreeVars
returns true iff there is at least one free variable, i.e. there is no binding for any variable- Parameters:
stmt
-bindings
-- Returns:
- whether there is at least one free variable
-
getVarValue
Return theValue
of the variable which is either taken from the variable itself (bound) or from the bindingsset (unbound).- Parameters:
var
-bindings
- the bindings, must not be null, useEmptyBindingSet
instead- Returns:
- the value or null
-
toTupleExpr
public static TupleExpr toTupleExpr(ArbitraryLengthPath node, Set<String> varNames, BindingSet bindings) Convert the givenArbitraryLengthPath
to a freshTupleExpr
where all provided bindings are bound.- Parameters:
node
-varNames
-bindings
-- Returns:
- the fresh and bound expression
-
toStatementPattern
-
toStatementPattern
-
toStatement
-
toStatement
-
selectQuery
public static TupleExpr selectQuery(StatementPattern stmt, BindingSet bindings, FilterValueExpr filterExpr, AtomicBoolean evaluated) throws IllegalQueryException Construct a SELECT query for the provided statement.- Parameters:
stmt
-bindings
-filterExpr
-evaluated
- parameter can be used outside this method to check whether FILTER has been evaluated, false in beginning- Returns:
- the SELECT query
- Throws:
IllegalQueryException
-
selectQuery
public static TupleExpr selectQuery(ExclusiveGroup group, BindingSet bindings, FilterValueExpr filterExpr, AtomicBoolean evaluated) Construct a SELECT query for the providedExclusiveGroup
. Note that bindings and filterExpr are applied whenever possible.- Parameters:
group
- the expression for the querybindings
- the bindings to be appliedfilterExpr
- a filter expression or nullevaluated
- parameter can be used outside this method to check whether FILTER has been evaluated, false in beginning- Returns:
- the SELECT query
-
selectQueryBoundUnion
public static TupleExpr selectQueryBoundUnion(StatementPattern stmt, List<BindingSet> unionBindings, FilterValueExpr filterExpr, Boolean evaluated) Construct a SELECT query expression for a bound union. Pattern: SELECT ?v_1 ?v_2 ?v_N WHERE { { ?v_1 p o } UNION { ?v_2 p o } UNION ... } Note that the filterExpr is not evaluated at the moment.- Parameters:
stmt
-unionBindings
-filterExpr
-evaluated
- parameter can be used outside this method to check whether FILTER has been evaluated, false in beginning- Returns:
- the SELECT query
-
selectQueryStringBoundCheck
public static TupleExpr selectQueryStringBoundCheck(StatementPattern stmt, List<BindingSet> unionBindings) Construct a SELECT query for a grouped bound check. Pattern: SELECT DISTINCT ?o_1 .. ?o_N WHERE { { s1 p1 ?o_1 FILTER ?o_1=o1 } UNION ... UNION { sN pN ?o_N FILTER ?o_N=oN }}- Parameters:
stmt
-unionBindings
-- Returns:
- the SELECT query
-
constructInnerUnion
protected static Union constructInnerUnion(StatementPattern stmt, int outerID, Set<String> varNames, List<BindingSet> bindings) -
constructStatement
protected static StatementPattern constructStatement(StatementPattern stmt, Set<String> varNames, BindingSet bindings) Construct the statement string, i.e. "s p o . " with bindings inserted wherever possible. Note that the free variables are added to the varNames set for further evaluation.- Parameters:
stmt
-varNames
-bindings
-- Returns:
- the
StatementPattern
-
constructStatementId
protected static StatementPattern constructStatementId(StatementPattern stmt, String varID, Set<String> varNames, BindingSet bindings) Construct the statement string, i.e. "s p o . " with bindings inserted wherever possible. Variables are renamed to "var_"+varId to identify query results in bound queries. Note that the free variables are also added to the varNames set for further evaluation.- Parameters:
stmt
-varNames
-bindings
-- Returns:
- the
StatementPattern
-
constructStatementCheckId
protected static TupleExpr constructStatementCheckId(StatementPattern stmt, int varID, Set<String> varNames, BindingSet bindings) Construct the statement string, i.e. "s p ?o_varID FILTER ?o_N=o ". This kind of statement pattern is necessary to later on identify available results.- Parameters:
stmt
-varID
-varNames
-bindings
-- Returns:
- the expression
-
appendVar
Clone the specified variable and attach bindings.- Parameters:
var
-varNames
-bindings
-- Returns:
- the variable
-
appendVarId
Clone the specified variable and attach bindings, moreover change name of variable by appending "_varId" to it.- Parameters:
var
-varID
-varNames
-bindings
-- Returns:
- the variable
-
getFreeVars
Computes the collection of free variables in the givenTupleExpr
.- Parameters:
tupleExpr
- the expression- Returns:
- the free variables
- See Also:
-