W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > July to September 2005

sparql test for order by and distinct

From: Dave Beckett <dave.beckett@bristol.ac.uk>
Date: Wed, 27 Jul 2005 11:58:48 +0100
To: RDF Data Access Working Group <public-rdf-dawg@w3.org>
Message-Id: <1122461928.27845.29.camel@hoth.ilrt.bris.ac.uk>

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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 16:15:23 GMT