qlever icon indicating copy to clipboard operation
qlever copied to clipboard

JSON SPARQL result sorted alphabeticly by variable name

Open fbelleau opened this issue 1 year ago • 2 comments

I am building a Superset/SPARQL connector experimenting with QLever. I have observed that the JSON response to a SPARQL query are in alphabetically ordered column which is a problem for me. Why are the json value predicates not in the same order as the one in the SELECT part of the query ?

Is there a parameter to fix this ?

This new project home https://github.com/fbelleau/superset4sparql

fbelleau avatar Mar 31 '23 22:03 fbelleau

for example

select ?t (count(?s) as ?c)
where {
  ?s a ?t .
} 
group by ?t
order by ?t

returns

{
"head": {
"vars": [
"t",
"c"
]
},
"results": {
"bindings": [
{
"c": {
"datatype": "http://www.w3.org/2001/XMLSchema#int",
"type": "literal",
"value": "253203"
},
"t": {
"type": "uri",
"value": "http://bio2rdf.org/bibtex#Article"
}

it should respect SELECT variable order ?t before ?c

{
"head": {
"vars": [
"t",
"c"
]
},
"results": {
"bindings": [
{
,
"t": {
"type": "uri",
"value": "http://bio2rdf.org/bibtex#Article"
},
"c": {
"datatype": "http://www.w3.org/2001/XMLSchema#int",
"type": "literal",
"value": "253203"
},

fbelleau avatar Apr 01 '23 01:04 fbelleau

Thanks for your interest in QLever, I will have a look at your project when I find the time for it (probably after the easter holidays)

Concerning your question: The array vars is in order (first t then c). The individual entries of the bindings array are objects (dictionaries/hash maps) that have no ordering but are accessed via the corresponding variable (e.g. bindings[1]["c"]). Any JSON deserializer should handle these entries independently of the order. I can see if we can configure our JSON serializer to print these results in order, but I would be interested in knowing how you use these results in a way that makes a difference.

Best regards Johannes

joka921 avatar Apr 03 '23 19:04 joka921