sparql test for order by and distinct

This pair of data / query caught a couple of bugs in my code where I was
mistakingly doing a DISTINCT on the order by expressions, rather than on
the result values.

Data (data.ttl):
------------------------------
@prefix ex: <http://example.org/abc#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<http://example.org/blah> ex:prop [
  a rdf:Bag ;
  rdf:_1 "value 2" ;
  rdf:_2 "value 3" ;
  rdf:_3 "value 4" ;
  rdf:_4 "value 1"
] .
------------------------------

Query (query.rq)
------------------------------
PREFIX ex: <http://example.org/abc#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?value
FROM <data.ttl>
WHERE {
  ?x ex:prop ?name .
  ?name a rdf:Bag .
  ?name ?liprop ?value .
}
ORDER BY ?name
------------------------------

Expected answer (from AARQ):
-------------
| value     |
=============
| "value 2" |
| "value 3" |
| "value 4" |
| "value 1" |
| rdf:Bag   |
-------------

Actual answer I got with my buggy code:

result: [value=uri<http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag>]

The query has ORDER BY ?name, which is a bug but that's one part of what
caught this problem as it tries to order blank nodes which is
implementation specific. My buggy code collapsed all the blank nodes
into one (!) since it was wrongly doing 'DISTINCT ?name' plus getting
blank node comparisons wrong and I got the one ?value back, the rdf:Bag
(it could have been any of them).

Since the order of blank nodes is implementation specific, I don't think
this can be a test case test.  The number of values returned could be
testable.  4 is the right count.  Maybe it could be reworked into
another form which could be used.

Dave

Received on Wednesday, 27 July 2005 10:59:05 UTC