Skip to content

Commit 6376d23

Browse files
authored
Merge pull request #108 from w3c/Issue99
Removes inconsistencies between the definitions of the set functions
2 parents fc0566b + dedb4d0 commit 6376d23

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

spec/index.html

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9464,9 +9464,10 @@ <h4>Aggregate Algebra</h4>
94649464
</ol>
94659465

94669466
<p><b>Special Case:</b> when <code>COUNT</code> is used with the expression
9467-
<code>*</code> the value of F will be the cardinality of the group solution sequence,
9468-
<code>card[Ψ]</code>, or <code>card[Dedup(Ψ)]</code> if the <code>DISTINCT</code>
9469-
keyword is present.</p>
9467+
<code>*</code>, then F(Ψ) is the cardinality of the group solution sequence,
9468+
i.e., F(Ψ)&nbsp;=&nbsp;<a href="#defn_Card">Card</a>(Ψ),
9469+
or F(Ψ)&nbsp;=&nbsp;<a href="#defn_Card">Card</a>(Dedup(Ψ))
9470+
if the <code>DISTINCT</code> keyword is present.</p>
94709471
</div>
94719472
<p><i>scalarvals</i> are used to pass values to the underlying set function, bypassing
94729473
the mechanics of the grouping. For example, the aggregate expression
@@ -9514,11 +9515,11 @@ <h4>Aggregate Algebra</h4>
95149515
<p><b>Definition: AggregateJoin</b></p>
95159516
<p>Let S<sub>1</sub>, ..., S<sub>n</sub> be a list of sets, where each set
95169517
S<sub>i</sub> contains key to (aggregated) value maps as produced by Aggregate.</p>
9517-
<p>Let K = { key | key in dom(S<sub>j</sub>) for some 1 &lt;= j &lt;= n } be the set of
9518+
<p>Let K = { key | key in dom(S<sub>j</sub>) for some 1 &le; j &le; n } be the set of
95189519
keys, then<br>
95199520
AggregateJoin(S<sub>1</sub>, ..., S<sub>n</sub>) = { agg<sub>1</sub>→val<sub>1</sub>,
95209521
..., agg<sub>n</sub>→val<sub>n</sub> | key in K and key→val<sub>i</sub> in
9521-
S<sub>i</sub> for each 1 &lt;= i &lt;= n }</p>
9522+
S<sub>i</sub> for each 1 &le; i &le; n }</p>
95229523
</div>
95239524
<p>Flatten is a function which is used to collapse a sequence of lists into a single list.
95249525
For example, [(1,&nbsp;2), (3,&nbsp;4)] becomes (1, 2, 3, 4).</p>
@@ -9527,6 +9528,11 @@ <h4>Aggregate Algebra</h4>
95279528
<p>The Flatten(S) function takes a sequence of lists, S = [(L<sub>1</sub>, L<sub>2</sub>,
95289529
...), ...], and returns the list ( x | L in S and x in L ).</p>
95299530
</div>
9531+
<p>Card is a function that returns the cardinality of a sequence or a list of elements (which may be solution mappings or other types of elements, depending on the context).
9532+
<div class="defn">
9533+
<p><b>Definition: <span id="defn_Card">Card</span></b></p>
9534+
<p>Given a sequence or a list |L|, Card(|L|) is the cardinality of |L|.</p>
9535+
</div>
95309536
<section id="setFunctions">
95319537
<h5>Set Functions</h5>
95329538
<p>The set functions which underlie SPARQL aggregates all have a common signature:
@@ -9558,7 +9564,7 @@ <h5>Count</h5>
95589564
<pre class="code nohighlight">xsd:integer Count(sequence S)</pre>
95599565
<p>L = Flatten(S)</p>
95609566
<p>remove error elements from L</p>
9561-
<p>Count(S) = card[L]</p>
9567+
<p>Count(S) = <a href="#defn_Card">Card</a>(L)</p>
95629568
</div>
95639569
</section>
95649570
<section id="aggSum">
@@ -9573,10 +9579,10 @@ <h5>Sum</h5>
95739579
<pre class="code nohighlight">numeric Sum(sequence S)</pre>
95749580
<p>L = Flatten(S)</p>
95759581
<p>Sum(S) = Sum(L)</p>
9576-
<p>Sum(L) = op:numeric-add(L<sub>1</sub>, Sum(L<sub>2..n</sub>)) when card[L] &gt;
9582+
<p>Sum(L) = op:numeric-add(L<sub>1</sub>, Sum(L<sub>2..n</sub>)) if <a href="#defn_Card">Card</a>(L) &gt;
95779583
1<br>
9578-
Sum(L) = op:numeric-add(L<sub>1</sub>, 0) when card[L] = 1<br>
9579-
Sum(L) = "0"^^xsd:integer when card[L] = 0</p>
9584+
Sum(L) = op:numeric-add(L<sub>1</sub>, 0) if <a href="#defn_Card">Card</a>(L) = 1<br>
9585+
Sum(L) = "0"^^xsd:integer if <a href="#defn_Card">Card</a>(L) = 0</p>
95809586
<p>In this way, Sum( (1, 2, 3) ) = op:numeric-add(1, op:numeric-add(2,
95819587
op:numeric-add(3, 0))).</p>
95829588
</div>
@@ -9588,8 +9594,8 @@ <h5>Avg</h5>
95889594
<div class="defn">
95899595
<p><b>Definition: <span id="defn_aggAvg">Avg</span></b></p>
95909596
<pre class="code nohighlight">numeric Avg(sequence S)</pre>
9591-
<p>Avg(S) = "0"^^xsd:integer, where Count(S) = 0</p>
9592-
<p>Avg(S) = Sum(S) / Count(S), where Count(S) &gt; 0</p>
9597+
<p>Avg(S) = "0"^^xsd:integer if Count(S) = 0</p>
9598+
<p>Avg(S) = Sum(S) / Count(S) if Count(S) &gt; 0</p>
95939599
</div>
95949600
<p>For example, Avg([(1), (2), (3)]) = Sum([(1), (2), (3)])/Count([(1), (2), (3)]) = 6/3 = 2.</p>
95959601
</section>
@@ -9605,8 +9611,8 @@ <h5>Min</h5>
96059611
<p>L = Flatten(S)</p>
96069612
<p>Min(S) = Min(L)</p>
96079613
<p>The flattened list L of values is ordered as per the <code>ORDER BY ASC</code> clause.</p>
9608-
<p>Min(L) = L<sub>0</sub> if card[L] > 0<br>
9609-
Min(L) = error if card[L] = 0</p>
9614+
<p>Min(L) = L<sub>1</sub> if <a href="#defn_Card">Card</a>(L) > 0<br>
9615+
Min(L) = error if <a href="#defn_Card">Card</a>(L) = 0</p>
96109616
</div>
96119617
</section>
96129618
<section id="aggMax">
@@ -9621,8 +9627,8 @@ <h5>Max</h5>
96219627
<p>L = Flatten(S)</p>
96229628
<p>Max(S) = Max(L)</p>
96239629
<p>The flattened list L of values is ordered as per the <code>ORDER BY DESC</code> clause.</p>
9624-
<p>Max(L) = L<sub>0</sub> if card[L] > 0<br>
9625-
Max(L) = error if card[L] = 0</p>
9630+
<p>Max(L) = L<sub>1</sub> if <a href="#defn_Card">Card</a>(L) > 0<br>
9631+
Max(L) = error if <a href="#defn_Card">Card</a>(L) = 0</p>
96269632
</div>
96279633
</section>
96289634
<section id="aggGroupConcat">
@@ -9633,17 +9639,18 @@ <h5>GroupConcat</h5>
96339639
SEPARATOR.</p>
96349640
<div class="defn">
96359641
<p><b>Definition: <span id="defn_aggGroupConcat">GroupConcat</span></b></p>
9636-
<pre class="code nohighlight">literal GroupConcat(sequence S)</pre>
9637-
<p>If the "separator" scalar argument is absent from GROUP_CONCAT then it is taken to
9638-
be the "space" character, unicode codepoint U+0020.</p>
9642+
<pre class="code nohighlight">literal GroupConcat(sequence S, function scalarvals)</pre>
9643+
<p>If the scalarvals argument is absent from GROUP_CONCAT, then scalarvals is taken to
9644+
be the empty function.</p>
9645+
<p>|separator| = scalarvals("separator") if scalarvals is defined for the argument "separator"</p>
9646+
<p>|separator| = the "space" character, unicode codepoint U+0020, if scalarvals is undefined for the argument "separator"</p>
96399647
<p>L = Flatten(S)</p>
9640-
<p>GroupConcat(S, scalarvals) = GroupConcat(L, scalarvals("separator"))</p>
9641-
<p>GroupConcat(L, sep) = "", where <span style=
9642-
"font-size: 140%">|</span>L<span style="font-size: 140%">|</span> = 0</p>
9643-
<p>GroupConcat(L, sep) = CONCAT("", L<sub>0</sub>), where
9644-
<span style="font-size: 140%">|</span>L<span style="font-size: 140%">|</span> = 1</p>
9645-
<p>GroupConcat(L, sep) = CONCAT(L<sub>0</sub>, sep, GroupConcat(L<sub>1..n-1</sub>,
9646-
sep)), where <span style="font-size: 140%">|</span>L<span style="font-size: 140%">|</span> &gt; 1</p>
9648+
<p>GroupConcat(S, scalarvals) = GroupConcat(L, |separator|)</p>
9649+
<p>GroupConcat(L, sep) = "" if <a href="#defn_Card">Card</a>(L) = 0</p>
9650+
<p>GroupConcat(L, sep) = CONCAT("", L<sub>1</sub>) if
9651+
<a href="#defn_Card">Card</a>(L) = 1</p>
9652+
<p>GroupConcat(L, sep) = CONCAT(L<sub>1</sub>, sep, GroupConcat(L<sub>2..n</sub>,
9653+
sep)) if <a href="#defn_Card">Card</a>(L) &gt; 1</p>
96479654
</div>
96489655
<p>For example, GroupConcat([("a"), ("b"), ("c")], {"separator" → "."}) = "a.b.c".</p>
96499656
</section>

0 commit comments

Comments
 (0)