From 2ba4ae3b0993824cb615d5c83ce897567a669479 Mon Sep 17 00:00:00 2001
From: Olaf Hartig A solution sequence modifier is one of:Solution Sequence Modifiers
SPARQL Algebra
described above.
Definition: Filter
-Let Ω be a multiset of solution mappings and expr be an expression. We define:
-Filter(expr, Ω) = { μ | μ in Ω and expr(μ) is an expression that has an +
Let Ω be a multiset of solution mappings and expr be an expression. We define:
+Filter(expr, Ω) = { μ | μ in Ω and expr(μ) is an expression that has an effective boolean value of true }
-multiplicity( μ | Filter(expr, Ω) ) - = multiplicity( μ | Ω )
+multiplicity( μ | Filter(expr, Ω) ) + = multiplicity( μ | Ω )
Note that evaluating anexists(pattern)
expression uses the dataset and active graph, D(G). See the evaluation of filter. @@ -9771,141 +9771,137 @@SPARQL Algebra
Definition: Join
-Let Ω1 and Ω2 be multisets of solution mappings. We define:
-Join(Ω1, Ω2) = { merge(μ1, μ2) | - μ1 in Ω1 and μ2 in Ω2, and μ1 and - μ2 are compatible }
-multiplicity( μ | Join(Ω1, Ω2) ) =
- for each merge(μ1, μ2), μ1 in
- Ω1 and μ2 in Ω2 such that μ = merge(μ1,
- μ2),
- sum over (μ1, μ2),
- multiplicity( μ1 | Ω1 ) * multiplicity( μ2 | Ω2 )
Let Ω1 and Ω2 be multisets of solution mappings. We define:
+Join(Ω1, Ω2) = { merge(μ1, μ2) | + μ1 in Ω1 and μ2 in Ω2, and μ1 and + μ2 are compatible }
+multiplicity( μ | Join(Ω1, Ω2) ) =
+ for each merge(μ1, μ2), μ1 in
+ Ω1 and μ2 in Ω2 such that μ = merge(μ1,
+ μ2),
+ sum over (μ1, μ2),
+ multiplicity( μ1 | Ω1 ) * multiplicity( μ2 | Ω2 )
It is possible that a solution mapping μ in a Join can arise in different solution - mappings, μ1 and μ2 in the multisets being joined. The multiplicity - of μ is the sum of the multiplicities from all possibilities.
+It is possible that a solution mapping μ in a Join can arise in different solution + mappings, μ1 and μ2 in the multisets being joined. The multiplicity + of μ is the sum of the multiplicities from all possibilities.
Definition: Diff
-Let Ω1 and Ω2 be multisets of solution mappings and expr be an +
Let Ω1 and Ω2 be multisets of solution mappings and expr be an expression. We define:
-Diff(Ω1, Ω2, expr) = { μ | μ in Ω1 such that ∀ μ′ in - Ω2, either μ and μ′ are not compatible or μ and μ' are compatible and - expr(merge(μ, μ')) does not have an effective boolean value of true }
-multiplicity( μ | Diff(Ω1, Ω2, expr) ) = - multiplicity( μ | Ω1 )
+Diff(Ω1, Ω2, expr) = { μ | μ in Ω1 such that ∀ μ' in + Ω2, either μ and μ' are not compatible or μ and μ' are compatible and + expr(merge(μ, μ')) does not have an effective boolean value of true }
+multiplicity( μ | Diff(Ω1, Ω2, expr) ) = + multiplicity( μ | Ω1 )
The evaluation of expr(merge(μ, μ')) does not have an effective boolean +
The evaluation of expr(merge(μ, μ')) does not have an effective boolean value of true if it evaluates to false or if it raises an error.
-Diff is used internally for the definition of LeftJoin.
+Diff is used internally for the definition of LeftJoin.
Definition: LeftJoin
-Let Ω1 and Ω2 be multisets of solution mappings and expr be an +
Let Ω1 and Ω2 be multisets of solution mappings and expr be an expression. We define:
-LeftJoin(Ω1, Ω2, expr) = Filter(expr, Join(Ω1, - Ω2)) ∪ Diff(Ω1, Ω2, expr)
-multiplicity( μ | LeftJoin(Ω1, Ω2, expr) ) = - multiplicity( μ | Filter(expr,Join(Ω1, Ω2)) ) + - multiplicity( μ | Diff(Ω1, Ω2, - expr) )
+LeftJoin(Ω1, Ω2, expr) = Filter(expr, Join(Ω1, + Ω2)) ∪ Diff(Ω1, Ω2, expr)
+multiplicity( μ | LeftJoin(Ω1, Ω2, expr) ) = + multiplicity( μ | Filter(expr, Join(Ω1, Ω2)) ) + + multiplicity( μ | Diff(Ω1, Ω2, + expr) )
Definition: Union
-Let Ω1 and Ω2 be multisets of solution mappings. We define:
-Union(Ω1, Ω2) = { μ | μ in Ω1 or μ in Ω2 +
Let Ω1 and Ω2 be multisets of solution mappings. We define:
+Union(Ω1, Ω2) = { μ | μ in Ω1 or μ in Ω2 }
-multiplicity( μ | Union(Ω1, Ω2) ) = - multiplicity( μ | Ω1 ) + - multiplicity( μ | Ω2 )
+multiplicity( μ | Union(Ω1, Ω2) ) = + multiplicity( μ | Ω1 ) + + multiplicity( μ | Ω2 )
Definition: Minus
-Let Ω1 and Ω2 be multisets of solution mappings. We define:
-Minus(Ω1, Ω2) = { μ | μ in Ω1 . ∀ μ' in - Ω2, either μ and μ' are not compatible or dom(μ) and dom(μ') are disjoint +
Let Ω1 and Ω2 be multisets of solution mappings. We define:
+Minus(Ω1, Ω2) = { μ | μ in Ω1 . ∀ μ' in + Ω2, either μ and μ' are not compatible or dom(μ) and dom(μ') are disjoint }
-multiplicity( μ | Minus(Ω1, Ω2) ) = - multiplicity( μ | Ω1 )
+multiplicity( μ | Minus(Ω1, Ω2) ) = + multiplicity( μ | Ω1 )
The additional restriction on dom(μ) and dom(μ') is added because otherwise if there is - a solution mapping in Ω2 that has no variables in common with the solution - mappings of Ω1, then Minus(Ω1, Ω2) would be empty, - regardless of the rest of Ω2. The empty solution mapping is compatible with +
The additional restriction on dom(μ) and dom(μ') is added because otherwise if there is
+ a solution mapping in Ω2 that has no variables in common with the solution
+ mappings of Ω1, then Minus(Ω1, Ω2) would be empty,
+ regardless of the rest of Ω2. The empty solution mapping is compatible with
every other solution mapping so P MINUS {}
would otherwise be empty for any
pattern P
.
Definition: Extend
-Let μ be a solution mapping, Ω a multiset of solution mappings, var a variable - and expr be an expression, then we define:
-Extend(μ, var, expr) = μ ∪ { (var,value) | var not in dom(μ) and value = expr(μ) }
-Extend(μ, var, expr) = μ if var not in dom(μ) and expr(μ) is an error
-Extend is undefined when var in dom(μ).
-Extend(Ω, var, expr) = { Extend(μ, var, expr) | μ in Ω }
+Definition: Extend
+Let μ be a solution mapping, Ω a multiset of solution mappings, var a variable + and expr be an expression, then we define:
+Extend(μ, var, expr) = μ ∪ { (var, value) | var not in dom(μ) and value = expr(μ) }
+Extend(μ, var, expr) = μ if var not in dom(μ) and expr(μ) is an error
+Extend is undefined if var in dom(μ).
+Write [ x | C ] for a sequence of elements where C is a condition on x.
+Write [ x | C ] for a sequence of elements where C is a condition on x.
Definition: ToList
-Let Ω be a multiset of solution mappings. We define:
-ToList(Ω) = a sequence of mappings μ in Ω in any order, with - multiplicity( μ | Ω ) occurrences of - μ
-multiplicity( μ | ToList(Ω) ) = - multiplicity( μ | Ω )
+Let Ω be a multiset of solution mappings. We define:
+ToList(Ω) = a sequence of mappings μ in Ω in any order, with + multiplicity( μ | Ω ) occurrences of + μ
+multiplicity( μ | ToList(Ω) ) = + multiplicity( μ | Ω )
Definition: OrderBy
-Let Ψ be a sequence of solution mappings. We define:
-multiplicity( μ | OrderBy(Ψ, condition) ) = - multiplicity( μ | Ψ )
+Definition: OrderBy
+Let Ψ be a sequence of solution mappings. We define:
+OrderBy(Ψ, condition) = [ μ | μ in Ψ and the sequence satisfies the ordering condition]
+multiplicity( μ | OrderBy(Ψ, condition) ) = + multiplicity( μ | Ψ )
Definition: Project
-Let Ψ be a sequence of solution mappings and PV a set of variables.
-For mapping μ, write Proj(μ, PV) to be the restriction of μ to variables in PV.
-Project(Ψ, PV) = [ Proj(μ, PV) | μ in Ψ ]
-multiplicity( μ | Project(Ψ, PV) ) = - sum( multiplicity( ν | Ψ ) | ν in Ψ such that ν = Proj(μ, PV))
-The order of Project(Ψ, PV) must preserve any ordering given by OrderBy.
+Definition: Project
+Let Ψ be a sequence of solution mappings and PV a set of variables.
+For mapping μ, write Proj(μ, PV) to be the restriction of μ to variables in PV.
+Project(Ψ, PV) = [ Proj(μ, PV) | μ in Ψ ]
+multiplicity( μ | Project(Ψ, PV) ) = + sum( multiplicity( μ' | Ψ ) | μ' in Ψ such that μ' = Proj(μ, PV) )
+The order of Project(Ψ, PV) must preserve any ordering given by OrderBy.
Definition: Distinct
-Let Ψ be a sequence of solution mappings. We define:
-Distinct(Ψ) = [ μ | μ in Ψ ]
-multiplicity( μ | Distinct(Ψ) ) = 1 - for every μ ∈ Distinct(Ψ)
-multiplicity( μ | Distinct(Ψ) ) = 0 - for every μ ∉ Distinct(Ψ)
-The order of Distinct(Ψ) must preserve any ordering given by OrderBy.
+Let Ψ be a sequence of solution mappings. We define:
+Distinct(Ψ) = [ μ | μ in Ψ ]
+multiplicity( μ | Distinct(Ψ) ) = 1 + for every μ ∈ Distinct(Ψ)
+multiplicity( μ | Distinct(Ψ) ) = 0 + for every μ ∉ Distinct(Ψ)
+The order of Distinct(Ψ) must preserve any ordering given by OrderBy.
Definition: Reduced
-Let Ψ be a sequence of solution mappings. We define:
-Reduced(Ψ) = [ μ | μ in Ψ ]
-multiplicity( μ | Reduced(Ψ) ) is - between 1 and multiplicity( μ | Ψ ) - for every μ ∈ Reduced(Ψ)
-multiplicity( μ | Reduced(Ψ) ) = 0 - for every μ ∉ Reduced(Ψ)
-The order of Reduced(Ψ) must preserve any ordering given by OrderBy.
+Let Ψ be a sequence of solution mappings. We define:
+Reduced(Ψ) = [ μ | μ in Ψ ]
+multiplicity( μ | Reduced(Ψ) ) is + between 1 and multiplicity( μ | Ψ ) + for every μ ∈ Reduced(Ψ)
+multiplicity( μ | Reduced(Ψ) ) = 0 + for every μ ∉ Reduced(Ψ)
+The order of Reduced(Ψ) must preserve any ordering given by OrderBy.
The Reduced solution sequence modifier does not guarantee a defined multiplicity.
+The Reduced solution sequence modifier does not guarantee a defined multiplicity.
Definition: Slice
-Let Ψ be a sequence of solution mappings. We define:
-Let Ψ be a sequence of solution mappings. We define:
+Slice(Ψ, start, length)[i] = Ψ[start+i] for i = 0 to (length-1)
Definition: ToMultiSet
-Let Ψ be a solution sequence. We define:
-ToMultiSet(Ψ) = { μ | μ in Ψ }
-multiplicity( μ | ToMultiSet(Ψ) ) = - multiplicity( μ | Ψ )
+Let Ψ be a solution sequence. We define:
+ToMultiSet(Ψ) = { μ | μ in Ψ }
+multiplicity( μ | ToMultiSet(Ψ) ) = + multiplicity( μ | Ψ )
Definition: Exists
@@ -9916,15 +9912,15 @@Group is a function which groups a solution sequence into multiple solutions, based on +
Group is a function which groups a solution sequence into multiple solutions, based on some attribute of the solutions.
Group evaluates a list of expressions against a solution sequence Ψ, producing a +
Group evaluates a list of expressions against a solution sequence Ψ, producing a partial function from keys to solution sequences.
-Group(exprlist, Ψ) = { +
Group(exprlist, Ψ) = { ListEval(exprlist, μ) → [ μ' | μ' in Ψ such that ListEval(exprlist, μ') and @@ -9947,10 +9943,10 @@
Definition: ListEval
-ListEval((expr1, ..., exprn), μ) returns a list - (e1, ..., en), where ei = expri(μ) or +
ListEval((expr1, ..., exprn), μ) returns a list + (e1, ..., en), where ei = expri(μ) or error.
-ListEval retains errors resulting from the evaluation of the list elements.
+ListEval retains errors resulting from the evaluation of the list elements.
Note that, although the result of ListEval may contain errors, and errors may be used @@ -9959,67 +9955,67 @@
Note also that the result of ListEval((unbound), μ) is the list (error), as the evaluation of an unbound expression is an error.
-Aggregation, a function which calculates a scalar value as an output of the aggregate +
Aggregation, a function which calculates a scalar value as an output of the aggregate expression. It is used in the SELECT clause, the HAVING evaluation process, and in ORDER - BY (where required). Aggregation calculates aggregated values over groups of solutions, + BY (where required). Aggregation calculates aggregated values over groups of solutions, using set functions.
Let exprlist be a list of expressions or `*`; func, a set function; - scalarvals, a partial function (possibly with an empty domain) passed from the aggregate - in the query; and { key1→Ψ1, ..., - keym→Ψm }, a partial function from keys to +
Let exprlist be a list of expressions or `*`; func, a set function; + scalarvals, a partial function (possibly with an empty domain) passed from the aggregate + in the query; and { key1→Ψ1, ..., + keym→Ψm }, a partial function from keys to solution sequences as produced by the grouping step.
-Aggregation applies the set function `func` to the given set and produces a +
Aggregation applies the set function func to the given set and produces a single value for each key and a group of solutions for that key.
-Aggregation(exprlist, func, scalarvals, { key1→Ψ1, ...,
- keym→Ψm } )
- = { (key, F(Ψ)) | key → Ψ in { key1→Ψ1, ...,
- keym→Ψm } }
Aggregation(exprlist, func, scalarvals, { key1→Ψ1, ...,
+ keym→Ψm } )
+ = { (key, F(Ψ)) | key → Ψ in { key1→Ψ1, ...,
+ keym→Ψm } }
where
- M(Ψ) = [ ListEval(exprlist, μ) | μ in Ψ ]
- F(Ψ) = func(M(Ψ), scalarvals), for non-DISTINCT
- F(Ψ) = func(Dedup(M(Ψ)), scalarvals), for DISTINCT
with Dedup(M(Ψ)) being an order-preserving, duplicate-free version of the sequence M(Ψ); that is, Dedup(M(Ψ)) is a sequence of lists that has the following four properties
+ M(Ψ) = [ ListEval(exprlist, μ) | μ in Ψ ]
+ F(Ψ) = func(M(Ψ), scalarvals), for non-DISTINCT
+ F(Ψ) = func(Dedup(M(Ψ)), scalarvals), for DISTINCT
with Dedup(M(Ψ)) being an order-preserving, duplicate-free version of the sequence M(Ψ); that is, Dedup(M(Ψ)) is a sequence of lists that has the following four properties (where each such list in this sequence may contain RDF terms and errors, as it is produced by the ListEval function).
Special Case: when COUNT
is used with the expression
- *
, then F(Ψ) is the cardinality of the group solution sequence,
- i.e., F(Ψ) = Card(Ψ),
- or F(Ψ) = Card(Distinct(Ψ))
+ *
, then F(Ψ) is the cardinality of the group solution sequence,
+ i.e., F(Ψ) = Card(Ψ),
+ or F(Ψ) = Card(Distinct(Ψ))
if the DISTINCT
keyword is present.
scalarvals are used to pass values to the underlying set function, bypassing +
scalarvals are used to pass values to the underlying set function, bypassing
the mechanics of the grouping. For example, the aggregate expression
- GROUP_CONCAT(?x ; separator="|")
has a scalarvals argument of { "separator"
+ GROUP_CONCAT(?x ; separator="|")
has a scalarvals argument of { "separator"
→ "|" }.
All aggregates may have the DISTINCT
keyword as the first token in their
- argument list. If this keyword is present, then first argument to func is Dedup(M(Ψ)).
Example
-Given a solution sequence Ψ with the following values:
+Given a solution sequence Ψ with the following values:
?z | ||||
μ1 | +μ1 | 1 | 2 | 3 |
μ2 | +μ2 | 1 | 3 | 4 |
μ3 | +μ3 | 2 | 5 | 6 | @@ -10050,24 +10046,26 @@
And the query expression SELECT (ex:agg(?y, ?z) AS ?agg) WHERE { ?x ?y ?z } GROUP BY ?x.
-We produce G = Group((?x), Ψ) = { (1) → [μ1, μ2], (2) → - [μ3] }
-And so Aggregation((?y, ?z), ex:agg, {}, G) =
+
We produce G = Group((?x), Ψ) = { (1) → [μ1, μ2], (2) → + [μ3] }
+And so Aggregation((?y, ?z), ex:agg, {}, G) =
{ ((1), eg:agg([(2, 3), (3, 4)], {})), ((2), eg:agg([(5, 6)], {})) }.
Definition: AggregateJoin
-Let S1, ..., Sn be a list of sets, where each set - Si contains key to (aggregated) value maps as produced by Aggregate.
-Let K = { key | key in dom(Sj) for some 1 ≤ j ≤ n } be the set of +
Let S1, ..., S|n| be a list of sets, where each set + Si contains key to (aggregated) value maps as produced by Aggregation.
+Let |K| = { |key| | |key| in dom(S|j|) for some 1 ≤ |j| ≤ |n| } be the set of
keys, then
- AggregateJoin(S1, ..., Sn) = { agg1→val1,
- ..., aggn→valn | key in K and key→vali in
- Si for each 1 ≤ i ≤ n }
The set functions which underlie SPARQL aggregates all have a common signature:
- SetFunc(S), or SetFunc(S, scalarvals) where S is a sequence of lists, and scalarvals is
+ SetFunc(|S|), or SetFunc(|S|, |scalarvals|) where |S| is a sequence of lists, and |scalarvals| is
one or more scalar values that are passed to the set function indirectly via the ( ...
; key=value ) syntax for aggregates in the SPARQL grammar. The only use of this that is
supported by the built-in aggregates in SPARQL Query 1.1 is GROUP_CONCAT
,
@@ -10075,8 +10073,15 @@
Note that the name "Set Function" is somewhat historical — the arguments to set functions are in fact sequences. The name is retained due to the commonality with SQL Set Functions, which operate over multisets.
-The set functions defined in this document are Count, Sum, Min, Max, Avg,
- GroupConcat, and Sample — corresponding to the aggregates COUNT
,
+
The set functions defined in this document are
+ Count,
+ Sum,
+ Min,
+ Max,
+ Avg,
+ GroupConcat, and
+ Sample
+ — corresponding to the aggregates COUNT
,
SUM
, MIN
, MAX
, AVG
,
GROUP_CONCAT
, and SAMPLE
. Definitions may be found in the
following sections. Systems may choose to expand this set using local extensions, using
@@ -10099,7 +10104,7 @@
Flatten(S) is the list +
Flatten(S) is the list ( x | L in S and x in L ).
@@ -10109,7 +10114,7 @@Definition: Card
-Given a sequence or a list |L|, Card(|L|) is the cardinality of |L|.
+Given a sequence or a list |L|, Card(|L|) is the cardinality of |L|.
Sum is a SPARQL set function that returns the numeric value obtained by summing +
Sum is a SPARQL set function that returns the numeric value obtained by summing the values within the aggregate group. Type promotion happens as per the op:numeric-add function, applied transitively, (see definition below) so the value of SUM(?x), in an aggregate group where ?x has values 1 (integer), 2.0e0 (float), and 3.0 (decimal) will be 6.0 (float).
Definition: Sum
-numeric Sum(sequence S)-
Sum(S) = SumList(L),
+numeric Sum(sequence S)+
Sum(S) = SumList(L),
where L = Flatten(S) and SumList(L) is defined recursively as follows.
In this way, Sum( [(1), (2), (3)] ) = SumList( (1, 2, 3) ) = +
In this way, Sum( [(1), (2), (3)] ) = SumList( (1, 2, 3) ) = op:numeric-add(1, op:numeric-add(2, op:numeric-add(3, 0))).
Definition: Avg
-numeric Avg(sequence S)+
numeric Avg(sequence S)
If Count(S) = 0,
- then Avg(S) = "0"^^xsd:integer
.
xsd:integer
.
If Count(S) > 0, - then Avg(S) = + then Avg(S) = Sum(S) / Count(S).
For example, Avg([(1), (2), (3)]) = - Sum([(1), (2), (3)])/Count([(1), (2), (3)]) +
For example, Avg([(1), (2), (3)]) = + Sum([(1), (2), (3)])/Count([(1), (2), (3)]) = 6/3 = 2.
Min is a SPARQL set function that returns the minimum value from a group +
Min is a SPARQL set function that returns the minimum value from a group respectively.
It makes use of the SPARQL ORDER BY ordering definition, to allow ordering over arbitrarily typed expressions.
Definition: Min
-term Min(sequence S)-
Min(S) = MinList(L),
+term Min(sequence S)+
Min(S) = MinList(L),
where L is the list of values obtained by
Flatten(S)
and then ordered as per the ORDER BY ASC
clause,
@@ -10198,14 +10203,14 @@
Max is a SPARQL set function that returns the maximum value from a group +
Max is a SPARQL set function that returns the maximum value from a group respectively.
It makes use of the SPARQL ORDER BY ordering definition, to allow ordering over arbitrarily typed expressions.
Definition: Max
-term Max(sequence S)-
Max(S) = MaxList(L),
+term Max(sequence S)+
Max(S) = MaxList(L),
where L is the list of values obtained by
Flatten(S)
and then ordered as per the ORDER BY DESC
clause,
@@ -10222,13 +10227,13 @@
GroupConcat is a set function which performs a string concatenation across the +
GroupConcat is a set function which performs a string concatenation across the values of an expression with a group. The order of the strings is not specified. The separator character used in the concatenation may be given with the scalar argument SEPARATOR.
Definition: GroupConcat
-literal GroupConcat(sequence S, function scalarvals)+
literal GroupConcat(sequence S, function scalarvals)
If the scalarvals argument is absent from GROUP_CONCAT
,
then scalarvals is taken to be the empty function.
Let sep be a string that is defined as follows.
@@ -10238,7 +10243,7 @@GroupConcat(S, scalarvals) = +
GroupConcat(S, scalarvals) = GCList(L, sep),
where L = Flatten(S) and GCList(L, sep) @@ -10257,25 +10262,25 @@
For example, GroupConcat([("a"), ("b"), ("c")], {"separator" → "."}) +
For example, GroupConcat([("a"), ("b"), ("c")], {"separator" → "."}) = GCList( ("a", "b", "c"), "." ) = "a.b.c".
Sample is a set function which returns an arbitrary value from the sequence passed +
Sample is a set function which returns an arbitrary value from the sequence passed to it.
Definition: Sample
-RDFTerm Sample(sequence S)+
RDFTerm Sample(sequence S)
If Card(S) = 0, then - Sample(S) = error.
+ Sample(S) = error.If Card(S) > 0, then - Sample(S) = v, where v + Sample(S) = v, where v in Flatten(S).
For example, given Sample([("a"), ("b"), ("c")]), "a", "b", and "c" are all valid return - values. Note that the Sample function is not required to be deterministic for a given input. The +
For example, given Sample([("a"), ("b"), ("c")]), "a", "b", and "c" are all valid return + values. Note that the Sample function is not required to be deterministic for a given input. The only restriction is that the output value must be present in the input sequence.
The set functions defined in this document are
- Count,
- Sum,
- Min,
- Max,
- Avg,
- GroupConcat, and
- Sample
+ Count,
+ Sum,
+ Min,
+ Max,
+ Avg,
+ GroupConcat, and
+ Sample
— corresponding to the aggregates COUNT
,
SUM
, MIN
, MAX
, AVG
,
GROUP_CONCAT
, and SAMPLE
. Definitions may be found in the
@@ -10120,27 +10120,27 @@
Count is a SPARQL set function which counts the number of times a given expression +
Count is a SPARQL set function which counts the number of times a given expression has a bound, non-error value within the aggregate group.
Sum is a SPARQL set function that returns the numeric value obtained by summing +
Sum is a SPARQL set function that returns the numeric value obtained by summing the values within the aggregate group. Type promotion happens as per the op:numeric-add function, applied transitively, (see definition below) so the value of SUM(?x), in an aggregate group where ?x has values 1 (integer), 2.0e0 (float), and 3.0 (decimal) will be 6.0 (float).
Definition: Sum
-numeric Sum(sequence S)-
Sum(S) = SumList(L),
+numeric Sum(sequence S)+
Sum(S) = SumList(L),
where L = Flatten(S) and SumList(L) is defined recursively as follows.
In this way, Sum( [(1), (2), (3)] ) = SumList( (1, 2, 3) ) = +
In this way, Sum( [(1), (2), (3)] ) = SumList( (1, 2, 3) ) = op:numeric-add(1, op:numeric-add(2, op:numeric-add(3, 0))).
Definition: Avg
-numeric Avg(sequence S)+
numeric Avg(sequence S)
If Count(S) = 0,
- then Avg(S) = "0"^^xsd:integer
.
xsd:integer
.
If Count(S) > 0, - then Avg(S) = - Sum(S) / - Count(S).
+ then Avg(S) = + Sum(S) / + Count(S).For example, Avg([(1), (2), (3)]) = +
For example, Avg([(1), (2), (3)]) = Sum([(1), (2), (3)])/Count([(1), (2), (3)]) = 6/3 = 2.
Min is a SPARQL set function that returns the minimum value from a group +
Min is a SPARQL set function that returns the minimum value from a group respectively.
It makes use of the SPARQL ORDER BY ordering definition, to allow ordering over arbitrarily typed expressions.
Definition: Min
-term Min(sequence S)-
Min(S) = MinList(L),
+term Min(sequence S)+
Min(S) = MinList(L),
where L is the list of values obtained by
Flatten(S)
and then ordered as per the ORDER BY ASC
clause,
@@ -10203,14 +10203,14 @@
Max is a SPARQL set function that returns the maximum value from a group +
Max is a SPARQL set function that returns the maximum value from a group respectively.
It makes use of the SPARQL ORDER BY ordering definition, to allow ordering over arbitrarily typed expressions.
Definition: Max
-term Max(sequence S)-
Max(S) = MaxList(L),
+term Max(sequence S)+
Max(S) = MaxList(L),
where L is the list of values obtained by
Flatten(S)
and then ordered as per the ORDER BY DESC
clause,
@@ -10227,13 +10227,13 @@
GroupConcat is a set function which performs a string concatenation across the +
GroupConcat is a set function which performs a string concatenation across the values of an expression with a group. The order of the strings is not specified. The separator character used in the concatenation may be given with the scalar argument SEPARATOR.
Definition: GroupConcat
-literal GroupConcat(sequence S, function scalarvals)+
literal GroupConcat(sequence S, function scalarvals)
If the scalarvals argument is absent from GROUP_CONCAT
,
then scalarvals is taken to be the empty function.
Let sep be a string that is defined as follows.
@@ -10243,7 +10243,7 @@GroupConcat(S, scalarvals) = +
GroupConcat(S, scalarvals) = GCList(L, sep),
where L = Flatten(S) and GCList(L, sep) @@ -10262,169 +10262,167 @@
For example, GroupConcat([("a"), ("b"), ("c")], {"separator" → "."}) +
For example, GroupConcat([("a"), ("b"), ("c")], {"separator" → "."}) = GCList( ("a", "b", "c"), "." ) = "a.b.c".
Sample is a set function which returns an arbitrary value from the sequence passed +
Sample is a set function which returns an arbitrary value from the sequence passed to it.
Definition: Sample
-RDFTerm Sample(sequence S)+
RDFTerm Sample(sequence S)
If Card(S) = 0, then - Sample(S) = error.
+ Sample(S) = error.If Card(S) > 0, then - Sample(S) = v, where v + Sample(S) = v, where v in Flatten(S).
For example, given Sample([("a"), ("b"), ("c")]), "a", "b", and "c" are all valid return - values. Note that the Sample function is not required to be deterministic for a given input. The +
For example, given Sample([("a"), ("b"), ("c")]), "a", "b", and "c" are all valid return + values. Note that the Sample function is not required to be deterministic for a given input. The only restriction is that the output value must be present in the input sequence.
We define eval(D(G), algebra expression) as the evaluation of an algebra expression with - respect to a dataset D having active graph G. The active graph is initially the default - graph.
--D : a dataset -D(G) : D a dataset with active graph G (the one patterns match against) -D[i] : The graph with IRI i in dataset D -P, P1, P2 : graph patterns -L : a solution sequence -F : an expression -+
We define eval(|D|(|G|), |A|) as the evaluation of an algebra expression |A| with + respect to a dataset |D| having active graph |G|. The active graph is initially the default + graph of |D|. Further symbols and notation used in the following definitions are:
+Definition: Evaluation of a Basic Graph Pattern
-eval(D(G), BGP) = multiset of solution mappings+
eval( |D|(|G|), |BGP| ) = multiset of solution mappings
See section Basic Graph Patterns
Definition: Evaluation of a Property Path Pattern
-eval(D(G), Path(X, path, Y)) = multiset of solution mappings-
See section Property Path Expresions
+eval( |D|(|G|), Path(|X|, |path|, |Y|) ) = multiset of solution mappings
+See section Property Path Expressions
Definition: Evaluation of Filter
-eval(D(G), Filter(F, P)) = Filter(F, eval(D(G),P), D(G))+
eval( |D|(|G|), Filter(|F|, |P|) ) = Filter( |F|, eval(|D|(|G|), |P|), |D|(|G|) )
'substitute' is a filter function in support of the evaluation of
EXISTS
and NOT EXISTS
forms which were translated to exists
.
Definition: Substitute
-Let μ be a solution mapping.
+Let μ be a solution mapping.
-substitute(pattern, μ) = the pattern formed by replacing every occurrence of - a variable v in pattern by μ(v) for each v in dom(μ)
+substitute(|pattern|, μ) = the pattern formed by replacing every occurrence of + a variable |v| in |pattern| by μ(|v|) for each |v| in dom(μ)
Definition: Evaluation of Exists
-Let μ be the current solution mapping for a filter and P a graph pattern:
+Let μ be the current solution mapping for a filter and |P| a graph pattern:
- The value exists(P), given D(G) is true if and only if eval(D(G), substitute(P, μ)) is + The value exists(|P|), given |D|(|G|) is true if and only if eval( |D|(|G|), substitute(|P|, μ)) is a non-empty sequence.
Definition: Evaluation of Join
-eval(D(G), Join(P1, P2)) = Join(eval(D(G), P1), eval(D(G), P2))+
eval( |D|(|G|), Join(P1, P2) ) = Join( eval(|D|(|G|), P1), eval(|D|(|G|), P2) )
Definition: Evaluation of LeftJoin
--eval(D(G), LeftJoin(P1, P2, F)) = LeftJoin(eval(D(G), P1), eval(D(G), P2), F) -+
+eval( |D|(|G|), LeftJoin(P1, P2, |F|) ) = LeftJoin( eval(|D|(|G|), P1), eval(|D|(|G|), P2), |F| ) +
Definition: Evaluation of Union
-eval(D(G), Union(P1,P2)) = Union(eval(D(G), P1), eval(D(G), P2))+
eval( |D|(|G|), Union(P1, P2) ) = Union( eval(|D|(|G|), P1), eval(|D|(|G|), P2) )
Definition: Evaluation of Graph
-if IRI is a graph name in D - eval(D(G), Graph(IRI,P)) = eval(D(D[IRI]), P) +if IRI is a graph name in D + eval( D(G), Graph(IRI,P) ) = eval( D(D[IRI]), P )
- if IRI is not a graph name in D - eval(D(G), Graph(IRI,P)) = the empty multiset + if IRI is not a graph name in D + eval( D(G), Graph(IRI,P) ) = the empty multiset
-eval(D(G), Graph(var,P)) = - Let R be the empty multiset - foreach IRI i in D - R := Union(R, Join( eval(D(D[i]), P) , Ω(?var->i) ) ) - the result is R +eval( D(G), Graph(var,P) ) = + Let R be the empty multiset + foreach IRI i in D + R := Union(R, Join( eval(D(D[i]), P) , Ω(var->i) ) ) + the result is R
The evaluation of graph uses the SPARQL algebra union operator. The multiplicity of a - solution mapping is the sum of the multiplicities of that solution mapping in each join +
The evaluation of graph uses the Union operator. The multiplicity of a + solution mapping is the sum of the multiplicities of that solution mapping in each Join operation.
eval(D(G), Group(exprlist, P)) = Group(exprlist, eval(D(G), P))
+eval( |D|(|G|), Group(|exprlist|, |P|) ) = Group( |exprlist|, eval(|D|(|G|), |P|) )
eval(D(G), Aggregation(exprlist, func, scalarvals, Grp)) = Aggregation(exprlist, func, - scalarvals, eval(D(G), Grp))
+eval( |D|(|G|), Aggregation(|exprlist|, |func|, |scalarvals|, |Grp|) ) = Aggregation( |exprlist|, |func|, + |scalarvals|, eval(|D|(|G|), |Grp|) )
eval(D(G), AggregateJoin(A1, ..., An)) = - AggregateJoin(eval(D(G), A1), ..., eval(D(G), An))
+eval( |D|(|G|), AggregateJoin(A1, ..., An) ) = + AggregateJoin( eval(|D|(|G|), A1), ..., eval(|D|(|G|), An) )
Note that if eval(D(G), Ai) is an error, it is ignored.
+Note that if eval(|D|(|G|), Ai) is an error, it is ignored.
Definition: Evaluation of Extend
--eval(D(G), Extend(P, var, expr)) = Extend(eval(D(G), P), var, expr) -+
+eval( |D|(|G|), Extend(|P|, |var|, |expr|) ) = Extend( eval(|D|(|G|), |P|), |var|, |expr| ) +
Definition: Evaluation of ToList
-eval(D(G), ToList(P)) = ToList(eval(D(G), P))+
eval( |D|(|G|), ToList(|P|) ) = ToList( eval(|D|(|G|), |P|) )
Definition: Evaluation of Distinct
-eval(D(G), Distinct(L)) = Distinct(eval(D(G), L)) -+
eval( |D|(|G|), Distinct(|L|) ) = Distinct( eval(|D|(|G|), |L|) ) +
Definition: Evaluation of Reduced
-eval(D(G), Reduced(L)) = Reduced(eval(D(G), L)) -+
eval( |D|(|G|), Reduced(|L|) ) = Reduced( eval(|D|(|G|), |L|) ) +
Definition: Evaluation of Project
-eval(D(G), Project(L, vars)) = Project(eval(D(G), L), vars) -+
eval( |D|(|G|), Project(|L|, |vars|) ) = Project( eval(|D|(|G|), |L|), |vars| ) +
Definition: Evaluation of OrderBy
-eval(D(G), OrderBy(L, condition)) = OrderBy(eval(D(G), L), condition) -+
eval( |D|(|G|), OrderBy(|L|, |condition|) ) = OrderBy( eval(|D|(|G|), |L|), |condition| ) +
Definition: Evaluation of ToMultiSet
-eval(D(G), ToMultiSet(L)) = ToMultiSet(eval(D(G), L))+
eval( |D|(|G|), ToMultiSet(|L|) ) = ToMultiSet( eval(|D|(|G|), |L|) )
P MINUS {}
would otherwise be empty for any
pattern P
.
Definition: Extend
+Definition: Extend
Let μ be a solution mapping, Ω a multiset of solution mappings, var a variable and expr be an expression, then we define:
Extend(μ, var, expr) = μ ∪ { (var, value) | var not in dom(μ) and value = expr(μ) }
@@ -9854,14 +9854,14 @@Definition: OrderBy
+Definition: OrderBy
Let Ψ be a sequence of solution mappings. We define:
OrderBy(Ψ, condition) = [ μ | μ in Ψ and the sequence satisfies the ordering condition]
multiplicity( μ | OrderBy(Ψ, condition) ) = multiplicity( μ | Ψ )
Definition: Project
+Definition: Project
Let Ψ be a sequence of solution mappings and PV a set of variables.
For mapping μ, write Proj(μ, PV) to be the restriction of μ to variables in PV.
Project(Ψ, PV) = [ Proj(μ, PV) | μ in Ψ ]