Skip to content

Commit

Permalink
Merge pull request #127 from w3c/FollowUpToPR124
Browse files Browse the repository at this point in the history
Improves the definitions of Count, Avg, and Sample
  • Loading branch information
hartig committed Oct 20, 2023
2 parents 092d14f + 0c735c0 commit 580f1f7
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9732,10 +9732,10 @@ <h5>Count</h5>
has a bound, non-error value within the aggregate group.</p>
<div class="defn">
<p><b>Definition: <span id="defn_aggCount">Count</span></b></p>
<pre class="code nohighlight">xsd:integer Count(sequence S)</pre>
<p>L = Flatten(S)</p>
<p>remove error elements from L</p>
<p>Count(S) = <a href="#defn_Card">Card</a>(L)</p>
<pre class="code nohighlight">xsd:integer <var>Count</var>(sequence <var>S</var>)</pre>
<p><var>Count</var>(<var>S</var>) = <a href="#defn_Card">Card</a>(<var>L'</var>),</p>
<p>where <var>L'</var> is the list <var>L</var> = <a href="#defn_Flatten">Flatten</a>(<var>S</var>)
with all error elements removed.</p>
</div>
</section>
<section id="aggSum">
Expand All @@ -9749,7 +9749,7 @@ <h5>Sum</h5>
<p><b>Definition: <span id="defn_aggSum">Sum</span></b></p>
<pre class="code nohighlight">numeric <var>Sum</var>(sequence <var>S</var>)</pre>
<p><var>Sum</var>(<var>S</var>) = <var>SumList</var>(<var>L</var>),</p>
<p>where <var>L</var> = Flatten(<var>S</var>) and
<p>where <var>L</var> = <a href="#defn_Flatten">Flatten</a>(<var>S</var>) and
<var>SumList</var>(<var>L</var>) is defined recursively as follows.</p>
<ul>
<li>If <a href="#defn_Card">Card</a>(<var>L</var>) = 0, then
Expand All @@ -9773,11 +9773,17 @@ <h5>Avg</h5>
average value for an expression over a group. It is defined in terms of Sum and Count.
<div class="defn">
<p><b>Definition: <span id="defn_aggAvg">Avg</span></b></p>
<pre class="code nohighlight">numeric Avg(sequence S)</pre>
<p>Avg(S) = "0"^^xsd:integer if Count(S) = 0</p>
<p>Avg(S) = Sum(S) / Count(S) if Count(S) &gt; 0</p>
</div>
<p>For example, Avg([(1), (2), (3)]) = Sum([(1), (2), (3)])/Count([(1), (2), (3)]) = 6/3 = 2.</p>
<pre class="code nohighlight">numeric <var>Avg</var>(sequence <var>S</var>)</pre>
<p>If <var><a href="#defn_aggCount">Count</a></var>(<var>S</var>) = 0,
then <var>Avg</var>(<var>S</var>) = "0"^^<code>xsd:integer</code>.</p>
<p>If <var><a href="#defn_aggCount">Count</a></var>(<var>S</var>) &gt; 0,
then <var>Avg</var>(<var>S</var>) =
<var><a href="#defn_aggSum">Sum</a></var>(<var>S</var>) /
<var><a href="#defn_aggCount">Count</a></var>(<var>S</var>).</p>
</div>
<p>For example, <var>Avg</var>([(1), (2), (3)]) =
<var>Sum</var>([(1), (2), (3)])/<var>Count</var>([(1), (2), (3)])
= 6/3 = 2.</p>
</section>
<section id="aggMin">
<h5>Min</h5>
Expand All @@ -9789,7 +9795,8 @@ <h5>Min</h5>
<p><b>Definition: <span id="defn_aggMin">Min</span></b></p>
<pre class="code nohighlight">term <var>Min</var>(sequence <var>S</var>)</pre>
<p><var>Min</var>(<var>S</var>) = <var>MinList</var>(<var>L</var>),</p>
<p>where <var>L</var> is the list of values obtained by Flatten(<var>S</var>)
<p>where <var>L</var> is the list of values obtained by
<a href="#defn_Flatten">Flatten</a>(<var>S</var>)
and then ordered as per the <code>ORDER BY ASC</code> clause,
and <var>MinList</var>(<var>L</var>) is defined as follows.</p>
<ul>
Expand All @@ -9812,7 +9819,8 @@ <h5>Max</h5>
<p><b>Definition: <span id="defn_aggMax">Max</span></b></p>
<pre class="code nohighlight">term <var>Max</var>(sequence <var>S</var>)</pre>
<p><var>Max</var>(<var>S</var>) = <var>MaxList</var>(<var>L</var>),</p>
<p>where <var>L</var> is the list of values obtained by Flatten(<var>S</var>)
<p>where <var>L</var> is the list of values obtained by
<a href="#defn_Flatten">Flatten</a>(<var>S</var>)
and then ordered as per the <code>ORDER BY DESC</code> clause,
and <var>MaxList</var>(<var>L</var>) is defined as follows.</p>
<ul>
Expand Down Expand Up @@ -9845,8 +9853,8 @@ <h5>GroupConcat</h5>
</ul>
<p><var>GroupConcat</var>(<var>S</var>, <var>scalarvals</var>) =
<var>GCList</var>(<var>L</var>, <var>sep</var>),</p>
<p>where <var>L</var> = Flatten(<var>S</var>) and
<var>GCList</var>(<var>L</var>, <var>sep</var>)
<p>where <var>L</var> = <a href="#defn_Flatten">Flatten</a>(<var>S</var>)
and <var>GCList</var>(<var>L</var>, <var>sep</var>)
is defined recursively as follows.</p>
<ul>
<li>If <a href="#defn_Card">Card</a>(<var>L</var>) = 0, then
Expand All @@ -9872,12 +9880,15 @@ <h5>Sample</h5>
to it.</p>
<div class="defn">
<p><b>Definition: <span id="defn_aggSample">Sample</span></b></p>
<pre class="code nohighlight">RDFTerm Sample(sequence S)</pre>
<p>Sample(S) = v, where v in Flatten(S)</p>
<p>Sample([]) = error</p>
</div>
<p>For example, given Sample([("a"), ("b"), ("c")]), "a", "b", and "c" are all valid return
values. Note that Sample() is not required to be deterministic for a given input, the
<pre class="code nohighlight">RDFTerm <var>Sample</var>(sequence <var>S</var>)</pre>
<p>If <a href="#defn_Card">Card</a>(<var>S</var>) = 0, then
<var>Sample</var>(<var>S</var>) = error.</p>
<p>If <a href="#defn_Card">Card</a>(<var>S</var>) &gt; 0, then
<var>Sample</var>(<var>S</var>) = <var>v</var>, where <var>v</var>
in <a href="#defn_Flatten">Flatten</a>(<var>S</var>).</p>
</div>
<p>For example, given <var>Sample</var>([("a"), ("b"), ("c")]), "a", "b", and "c" are all valid return
values. Note that the <var>Sample</var> 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.</p>
</section>
</section>
Expand Down

0 comments on commit 580f1f7

Please sign in to comment.