Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 27, 2015

Conversation

ckristo
Copy link
Contributor

@ckristo ckristo commented Aug 26, 2015

Hi,

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

  • query.order(:var1 => :asc, :var2 => :desc)
  • query.order([:var1, :asc], [:var2, :desc])

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

Cheers,
Chris

@gkellogg
Copy link
Member

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

@ckristo
Copy link
Contributor Author

ckristo commented Aug 26, 2015

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

@gkellogg
Copy link
Member

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:

  • query.order(:o)
  • query.order.asc(:o)
  • query.order.desc(:s).asc(:o)

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
Copy link
Contributor Author

ckristo commented Aug 27, 2015

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 [email protected] 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.

gkellogg added a commit that referenced this pull request Aug 27, 2015
Added support for specifying the sort order in SPARQL::Client::Query.order()
@gkellogg gkellogg merged commit 7602ee0 into ruby-rdf:develop Aug 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants