Adds a global term ordering for ORDER BY

Allows having a global order on the results even if it's unspecified by SPARQL.

This ordering is likely to change in the future (addition of proper support of other datatypes...).
pull/190/head
Tpt 3 years ago
parent 6dffbe09ad
commit 581ee0e7af
  1. 16
      lib/src/sparql/eval.rs
  2. 6
      testsuite/oxigraph-tests/sparql/manifest.ttl
  3. 3
      testsuite/oxigraph-tests/sparql/order_terms.rq
  4. 66
      testsuite/oxigraph-tests/sparql/order_terms.ttl

@ -2567,7 +2567,21 @@ fn cmp_terms(dataset: &DatasetView, a: Option<&EncodedTerm>, b: Option<&EncodedT
a => match b {
_ if b.is_named_node() || b.is_blank_node() => Ordering::Greater,
_ if b.is_triple() => Ordering::Less,
b => partial_cmp_literals(dataset, a, b).unwrap_or(Ordering::Equal),
b => {
if let Some(ord) = partial_cmp_literals(dataset, a, b) {
ord
} else if let (Ok(Term::Literal(a)), Ok(Term::Literal(b))) =
(dataset.decode_term(a), dataset.decode_term(b))
{
(a.value(), a.datatype(), a.language()).cmp(&(
b.value(),
b.datatype(),
b.language(),
))
} else {
Ordering::Equal // Should never happen
}
}
},
},
(Some(_), None) => Ordering::Greater,

@ -25,6 +25,7 @@
:halloween_problem
:nested_path
:nested_expression
:order_terms
) .
:small_unicode_escape_with_multibytes_char rdf:type mf:NegativeSyntaxTest ;
@ -108,3 +109,8 @@
:nested_expression rdf:type mf:PositiveSyntaxTest11 ;
mf:name "A very nested expression" ;
mf:action <nested_expression.rq> .
:order_terms rdf:type mf:QueryEvaluationTest ;
mf:name "literals have an order for ORDER BY" ;
mf:action [ qt:query <order_terms.rq> ] ;
mf:result <order_terms.ttl> .

@ -0,0 +1,3 @@
SELECT ?o WHERE {
VALUES ?o { 4.0 "v" "u"@en "a" "d"@de "c"@en "b" "foo"^^<http://example.com/h> 1 "2021-30-30"^^<http://www.w3.org/2001/XMLSchema#date> "2020-30-29T00:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> d }
} ORDER BY ?o

@ -0,0 +1,66 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rs: <http://www.w3.org/2001/sw/DataAccess/tests/result-set#> .
[] rdf:type rs:ResultSet ;
rs:resultVariable
"o" ;
rs:solution [ rs:binding [ rs:value -1e3 ;
rs:variable "o"
] ;
rs:index 1
] ;
rs:solution [ rs:binding [ rs:value 1 ;
rs:variable "o"
] ;
rs:index 2
] ;
rs:solution [ rs:binding [ rs:value "2020-30-29T00:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> ;
rs:variable "o"
] ;
rs:index 3
] ;
rs:solution [ rs:binding [ rs:value "2021-30-30"^^<http://www.w3.org/2001/XMLSchema#date> ;
rs:variable "o"
] ;
rs:index 4
] ;
rs:solution [ rs:binding [ rs:value 4.0 ;
rs:variable "o"
] ;
rs:index 5
] ;
rs:solution [ rs:binding [ rs:value "a" ;
rs:variable "o"
] ;
rs:index 6
] ;
rs:solution [ rs:binding [ rs:value "b" ;
rs:variable "o"
] ;
rs:index 7
] ;
rs:solution [ rs:binding [ rs:value "c"@en ;
rs:variable "o"
] ;
rs:index 8
] ;
rs:solution [ rs:binding [ rs:value "d"@de ;
rs:variable "o"
] ;
rs:index 9
] ;
rs:solution [ rs:binding [ rs:value "foo"^^<http://example.com/h> ;
rs:variable "o"
] ;
rs:index 10
] ;
rs:solution [ rs:binding [ rs:value "u"@en ;
rs:variable "o"
] ;
rs:index 11
] ;
rs:solution [ rs:binding [ rs:value "v" ;
rs:variable "o"
] ;
rs:index 12
] .
Loading…
Cancel
Save