W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > January to March 2007

hacked defn of ORDER BY

From: Eric Prud'hommeaux <eric@w3.org>
Date: Tue, 27 Feb 2007 00:36:22 +0100
To: dawg mailing list <public-rdf-dawg@w3.org>
Message-ID: <20070226233622.GA6562@w3.org>
Tell me if you think this specification based on order functions and
order expressions and large orders of fries is useful:... 

http://www.w3.org/2001/sw/DataAccess/rq23/rq25#modOrderBy
------------------------------------------------------------------------
9.1 ORDER BY

The ORDER BY clause establishes the order of a solution sequence.

Following the ORDER BY clause is a sequence of order functions, comprised of
an expression and an optional order modifier (either ASC() or DESC()). Each
ordering function is either ASCENDING (indicated by the ASC() modifier, or no
modifier) or DESCENDING (indicated by the DESC() modifier).

PREFIX foaf:    <http://xmlns.com/foaf/0.1/>

SELECT ?name
WHERE { ?x foaf:name ?name }
ORDER BY ?name

PREFIX     :    <http://example.org/ns#>
PREFIX foaf:    <http://xmlns.com/foaf/0.1/>
PREFIX xsd:     <http://www.w3.org/2001/XMLSchema#>

SELECT ?name
WHERE { ?x foaf:name ?name ; :empId ?emp }
ORDER BY DESC(?emp)

PREFIX foaf:    <http://xmlns.com/foaf/0.1/>

SELECT ?name
WHERE { ?x foaf:name ?name ; :empId ?emp }
ORDER BY ?name DESC(?emp)

The "<" operator (see the Operator Mapping) defines the relative order of
pairs of numerics, simple literals , xsd:strings , xsd:booleans and
xsd:dateTimes. IRIs are ordered by comparing their codepoint representations
with the "<" operator.

SPARQL also defines a fixed, arbitrary order between some kinds of RDF terms
that would not otherwise be ordered. This arbitrary order is necessary to
provide consistent slicing of query solutions using LIMIT and OFFSET.

 1. (Lowest) no value assigned to the variable or expression in this solution.
 2. Blank nodes
 3. IRIs
 4. RDF literals
 5. A plain literal is lower than an RDF literal with type xsd:string of the
    same lexical form.

The ASCENDING order of two solutions with respect to an ordering function is
established by substituting the solution bindings into the expressions and
comparing them with the "<" operator. The DESCENDING order is the reverse of
the ASCENDING order.

The relative order of two solutions is the relative order of two solutions
with respect to the first ordering function in the sequence. For solutions
where the substitutions of the solution bindings produce the same RDF term,
the order is the relative order of two solutions with respect to the next
ordering function. The relative order of two solutions is undefined if no
order expression evaluated for the two solutions produces a distinct RDF term.

Ordering a sequence of solutions always results in a sequence with the same
number of solutions in it.

Using ORDER BY on a solution sequence for a CONSTRUCT or DESCRIBE query has no
direct effect because only SELECT returns a sequence of results. Used in
combination with LIMIT and OFFSET, ORDER BY can be used to return results
generated from a different slice of the solution sequence.

Grammar rules:@@

@@ Multiple ordering conditions : ordered, by first sort key that
differentiates two solutions.


-- 
-eric

office: +1.617.258.5741 NE43-344, MIT, Cambridge, MA 02144 USA
cell:   +1.857.222.5741

(eric@w3.org)
Feel free to forward this message to any list for any purpose other than
email address distribution.

Received on Monday, 26 February 2007 23:36:35 GMT

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