Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn the input to Group(..) and to Aggregation(..) into solution sequences #98

Merged
merged 7 commits into from
Jun 29, 2023
39 changes: 21 additions & 18 deletions spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9368,22 +9368,10 @@ <h3>SPARQL Algebra</h3>
</div>
<div class="defn">
<p><b>Definition: <span id="defn_algDistinct">Distinct</span></b></p>
<p>Let <var>Ψ</var> be a sequence of elements which may be either solution mappings or lists of RDF terms.</p>
<p>Distinct(<var>Ψ</var>) is a sequence of elements that has the following properties.</p>
<ol>
<li>Every element in <var>Ψ</var> is contained in Distinct(<var>Ψ</var>).</li>
<li>Every element in Distinct(<var>Ψ</var>) is contained in <var>Ψ</var>.</li>
<li>Distinct(<var>Ψ</var>) is free of duplicates. That is, the element at the |i|-th position in Distinct(<var>Ψ</var>) is different from the element at the |j|-th position in Distinct(<var>Ψ</var>) for every two natural numbers |i| and |j| such that |i| &ne; |j|.
</li>
<li>For every two elements <var>e<sub>1</sub></var> and <var>e<sub>2</sub></var> in Distinct(<var>Ψ</var>), the relative order of their first occurrences in <var>Ψ</var> is preserved in Distinct(<var>Ψ</var>). That is, if <var>i<sub>1</sub></var>&nbsp;&lt;&nbsp;<var>i<sub>2</sub></var>, then <var>j<sub>1</sub></var>&nbsp;&lt;&nbsp;<var>j<sub>2</sub></var>, where
<ul>
<li><var>i<sub>1</sub></var> is the smallest natural number such that <var>e<sub>1</sub></var> is at the <var>i<sub>1</sub></var>-th position in <var>Ψ</var>,</li>
<li><var>i<sub>2</sub></var> is the smallest natural number such that <var>e<sub>2</sub></var> is at the <var>i<sub>2</sub></var>-th position in <var>Ψ</var>,</li>
<li><var>j<sub>1</sub></var> is the position of <var>e<sub>1</sub></var> in Distinct(<var>Ψ</var>), and</li>
<li><var>j<sub>2</sub></var> is the position of <var>e<sub>2</sub></var> in Distinct(<var>Ψ</var>).</li>
</ul>
</li>
</ol>
<p>Let Ψ be a sequence of solution mappings. We define:</p>
<p>Distinct(Ψ) = [ μ | μ in Ψ ]</p>
<p>card[Distinct(Ψ)](μ) = 1</p>
<p>The order of Distinct(Ψ) must preserve any ordering given by OrderBy.</p>
hartig marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div class="defn">
<p><b>Definition: <span id="defn_algReduced">Reduced</span></b></p>
Expand Down Expand Up @@ -9469,10 +9457,25 @@ <h4>Aggregate Algebra</h4>
<p>where<br>
&nbsp;&nbsp;M(Ψ) = [ ListEval(exprlist, μ) | μ in Ψ ]<br>
&nbsp;&nbsp;F(Ψ) = func(M(Ψ), scalarvals), for non-<code>DISTINCT</code><br>
hartig marked this conversation as resolved.
Show resolved Hide resolved
&nbsp;&nbsp;F(Ψ) = func(Distinct(M(Ψ)), scalarvals), for <code>DISTINCT</code></p>
&nbsp;&nbsp;F(Ψ) = func(Dedup(M(Ψ)), scalarvals), for <code>DISTINCT</code></p>
<p>with Dedup(M(Ψ)) being an order-preserving, duplicate-free version of the sequence M(Ψ); that is, Dedup(M(Ψ)) is a sequence of RDF terms that has the following four properties.</p>
<ol>
<li>Every unique element in M(Ψ) is contained in Dedup(M(Ψ)).</li>
<li>Every element in Dedup(M(Ψ)) is contained in M(Ψ).</li>
<li>Dedup(M(Ψ)) is free of duplicates. That is, the element at the |i|-th position in Dedup(M(Ψ)) is not the same term as the element at the |j|-th position in Dedup(M(Ψ)) for every two natural numbers |i| and |j| such that |i| &ne; |j|.</li>
<li>For any two elements <var>e<sub>1</sub></var> and <var>e<sub>2</sub></var> in Dedup(M(Ψ)), the relative order of their first occurrences in M(Ψ) is preserved in Dedup(M(Ψ)). That is, if <var>i<sub>1</sub></var>&nbsp;&lt;&nbsp;<var>i<sub>2</sub></var>, then <var>j<sub>1</sub></var>&nbsp;&lt;&nbsp;<var>j<sub>2</sub></var>, where
<ul>
<li><var>i<sub>1</sub></var> is the smallest natural number such that <var>e<sub>1</sub></var> is at the <var>i<sub>1</sub></var>-th position in M(Ψ),</li>
<li><var>i<sub>2</sub></var> is the smallest natural number such that <var>e<sub>2</sub></var> is at the <var>i<sub>2</sub></var>-th position in M(Ψ),</li>
<li><var>j<sub>1</sub></var> is the position of <var>e<sub>1</sub></var> in Dedup(M(Ψ)), and</li>
<li><var>j<sub>2</sub></var> is the position of <var>e<sub>2</sub></var> in Dedup(M(Ψ)).</li>
hartig marked this conversation as resolved.
Show resolved Hide resolved
</ul>
</li>
</ol>

<p><b>Special Case:</b> when <code>COUNT</code> is used with the expression
<code>*</code> the value of F will be the cardinality of the group solution sequence,
<code>card[Ψ]</code>, or <code>card[Distinct(Ψ)]</code> if the <code>DISTINCT</code>
<code>card[Ψ]</code>, or <code>card[Dedup(Ψ)]</code> if the <code>DISTINCT</code>
hartig marked this conversation as resolved.
Show resolved Hide resolved
keyword is present.</p>
</div>
<p><i>scalarvals</i> are used to pass values to the underlying set function, bypassing
Expand Down