[tests] Test for GROUP BY

I've added some test for GROUP BY, separate for the aggregates tests.

http://www.w3.org/2009/sparql/docs/tests/data-sparql11/grouping/

group03 is testing what happens when the GROUP BY contains an unbound 
variable.  In ARQ, this just leads to a key for a group.

--------------
@prefix : <http://example/> .

:s1 :p 1 .
:s1 :q 9 .
:s2 :p 2 .
--------------
PREFIX : <http://example/>

SELECT ?w (SAMPLE(?v) AS ?S)
{
   ?s :p ?v .
   OPTIONAL { ?s :q ?w }
}
GROUP BY ?w
--------------

and ARQ gives:

---------
| w | S |
=========
| 9 | 1 |
|   | 2 |
---------

the unbound variable in one row causes there to be a key for "unbound or 
error"

The definition:

[[
Group(ExprList, Ω) = { ListEval(ExprList, μ) -> { μ' | μ' in Ω, 
ListEval(ExprList, μ) = ListEval(ExprList, μ') } | μ in Ω }
]]

uses "ExprList" which does not remove errors. It would be worth adding 
this to ListEval (changes suggested marked __)

[[
Definition: ListEval

ListEval(ExprList, μ) returns a list E, where Ei =
μ(ExprListi) _or error_.

_ListEval retains errors in evaluation of the list elements._

A variant, ListEvalE, is the same except that all elements of E which 
are errors are removed.
]]

Test 'group5' adds to this to test that the whole group key isn't 
collapsed to a single item by an error:

--------------
@prefix : <http://example/> .

:s1 :p 1 .
:s3 :p 1 .
:s1 :q 9 .
:s2 :p 2 .
--------------
PREFIX : <http://example/>

SELECT ?s ?w
{
   ?s :p ?v .
   OPTIONAL { ?s :q ?w }
}
GROUP BY ?s ?w
--------------
--------------------------
| s                   | w |
===========================
| <http://example/s1> | 9 |
| <http://example/s2> |   |
| <http://example/s3> |   |
---------------------------

so the group keys are (:s1, 9) (:s2, error) and (:s3, error)

 Andy

Editorial:

Defn: Group
s/from explitic groups/from explicit groups/

but I'd suggest
"from groups where the ExprList is non-empty"

because the text causes me to ask "what's an _explicit_ group".

Received on Friday, 1 October 2010 10:10:08 UTC