0

the syntax that i have so far is this:

g.V().has('@class', 'Person').order{it.a.last_name <=> it.b.last_name}[0..9]

but it seems like the closure provided to order is executed at the client, which implies the entire extent of the collection needs to move to the client for evaluation.

is this the case, and if so, what are my options for sorting and paging server side with orient-db (2.2+)?

Community
  • 1
  • 1
tony_k
  • 1,983
  • 2
  • 20
  • 27

1 Answers1

1

OrientDB database functions can't be executed in pure GREMLIN language, but you call write 1 line of JS or SQL that executes GREMLIN. Example of a database function with SQL as language:

select expand( gremlin( "g.V().has('@class', 'Person')
            .order{it.a. last_name <=> it.b. last_name}[0..9]" ) )

NOTE: This is working only with last develop version (2.2.1-SNAPSHOT).

Lvca
  • 8,938
  • 2
  • 24
  • 25
  • thanks @lvca, submitting strings of gremlin as you suggest above could be good. would the limitation still apply with the advent of gremlin 3 style syntax: – tony_k May 31 '16 at 03:30
  • (oops hit return) e.g: `g.V().has('@class', 'Person').order().by('last_name', incr).limit(10)` or is there more to it than just eliminating the `order` closure? also, would there be any way to submit such a gremlin string via the java-api without dropping down into sql syntax (i'm admittedly new to orient, but i believe i read that submitting sql occurs outside of any prevailing local transactions)? – tony_k May 31 '16 at 03:40
  • Sure you can: `database.command(new OCommandGremlin("g.V")).execute();` – Lvca Jun 01 '16 at 13:22
  • cool @lvca, that could be good too. i think both mechanisms you suggest accomplish the goal of sorting and paging server side with gremlin against orient, so i will accept your answer. just comes down to the diff between executing the gremlin locally or server side. one related follow-up question: do/can `OCommandGremlin` calls participate in "local" transactions? – tony_k Jun 02 '16 at 16:52
  • one more related question: if there are no closures used, will a string of gremlin steps executed locally (like this tp3 style one `g.V().has('@class', 'Person').order().by('last_name', incr).limit(10)`) result in the complete gremlin query being executed server side? reason i ask is that an ideal programming model (at least when programming in groovy), would be for seamless integration with the gremlin api (vs having to drop into `OCommandGremlin`) and participation in local transactions... – tony_k Jun 02 '16 at 17:01
  • In some cases the query can be converted to SQL, so it would be executed on the server. Unfortunately, sometimes it can't be transformed or the TinkerPop Blueprints layer is not smart enough. – Lvca Jun 02 '16 at 18:27