mu-semtech/mu-cl-resources

Sorting resources unexpected behavior

asjongers opened this issue · 2 comments

Sorting a set of resources based on an attribute sometimes return the list partially ordered.

Call:
http://localhost:4201/classes?sort=title

This call gets transformed to the following query:

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX tf: <http://tenforce.com/sdc/elements/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rm: <http://mu.semte.ch/vocabularies/logical-delete/>
PREFIX typedLiterals: <http://mu.semte.ch/vocabularies/typed-literals/>
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX app: <http://mu.semte.ch/app/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?uuid MAX(?__title32) AS ?__title32 WHERE {
    GRAPH <http://sdc.tenforce.com/application> {
    ?s mu:uuid ?uuid; a tf:Class. 
OPTIONAL {?s dct:title ?__title32.}
}
} GROUP BY ?uuid ORDER BY ASC(?__title32)  OFFSET 0 LIMIT 20

Which returns the following result:
sort_before

Removing the MAX aggregation seems to do the trick but I suspect it's there for a reason (if the attribute occurs more than once for the same UUID?):

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX tf: <http://tenforce.com/sdc/elements/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rm: <http://mu.semte.ch/vocabularies/logical-delete/>
PREFIX typedLiterals: <http://mu.semte.ch/vocabularies/typed-literals/>
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX app: <http://mu.semte.ch/app/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?uuid ?__title32 WHERE {
    GRAPH <http://sdc.tenforce.com/application> {
    ?s mu:uuid ?uuid; a tf:Class. 
?s dct:title ?__title32.
}
} ORDER BY ASC(?__title32)  OFFSET 0 LIMIT 20

Gives the following result:
sort_after

Let me know if there's anything I can do to help!

Hi @asjongers. You are totally right in the full post. This is a bug in Virtuoso, and we don't want to permanently drop the MAX for it. However, an experimental property has been introduced to mitigate this issue for the time being.

You can set the following in your domain.lisp:
(defparameter *max-group-sorted-properties* nil)

Thanks for the clear issue. Please close it if this property solves your problem.

After upgrading to 1.17.0 and adding the provided parameter, it indeed works as expected!

Thanks a bunch for the very quick help.