ruby-rdf / sparql-client

SPARQL client for Ruby.
http://rubygems.org/gems/sparql-client
The Unlicense
112 stars 58 forks source link

Added support for specifying the sort order in SPARQL::Client::Query.order() #61

Closed ckristo closed 9 years ago

ckristo commented 9 years ago

Hi,

based on a short discussion (issue #60) -- I added support for specifying the sort order direction with sparql-client's query DSL ::

Both -- Arrays and Hashes are supported as arguments. If not both should be supported, I will remove one of them.

Cheers, Chris

gkellogg commented 9 years ago

I'll look at this, but we should also have #desc and #asc methods to keep with the spirit of the DSL.

ckristo commented 9 years ago

@gkellogg something like query.order(asc(:o), desc(:p)) or query.order(:o).asc().order(:p).desc()?

gkellogg commented 9 years ago

The SPARQL Grammar is:

    [23]  OrderClause             ::= 'ORDER' 'BY' OrderCondition+
    [24]  OrderCondition          ::= ( ( 'ASC' | 'DESC' ) BrackettedExpression )
                                    | ( Constraint | Var )

So, it problable need to include things such as:

where order(:c) is a variable, and the arguments to asc and desc are also just variables. Trying to do a BracketedExpression or Constraint would be beyond the scope of the DSL. order.asc(:s) would be equivalent to asc(:s), or even just order(:s), as ASC is the default. order(:s, desc: true) or order(s: :desc) is also reasonable. Adding more variables could loose order, but Ruby 2+ preserves order in hashes, so it's probably also reasonable.

ckristo commented 9 years ago

Hashes preserve ordering since Ruby 1.9 -- I've checked that before implementing the PR (cf. 1

And as far as I remeber, sparql-client requires ruby 1.9, right?

Chris

On 27 Aug 2015, at 00:20, Gregg Kellogg notifications@github.com wrote:

I'll look at this, but we should also have #desc and #asc methods to keep with the spirit of the DSL.

— Reply to this email directly or view it on GitHub.