Use index for sorting

59 views
Skip to first unread message

toom

unread,
Dec 2, 2020, 2:13:05 AM12/2/20
to JanusGraph users
Hello,

I'm using JanusGraph with Cassandra (0.5.2) and ElasticSearch.

I try to optimize my queries and use the mixed indexes as much as possible, in particular for sortings, but I have some difficulties:

It is not possible to sort by properties that can have missing values (or I get a "The property does not exist as the key has no associated value for the provided element"). Therefore I used ".order().by(coalesce(values('closingDate'), new Date()))" but in this case, the index is not used.

If there is only one sorting criterion, I probably can do something like:

g.inject(1).union(
  g.V().hasLabel('Case').has('closingDate').order().by('closingDate'),
  g.V().hasLabel('Case').hasNot('closingDate'))

But what is my best option if I want to use several criteria?


I also note that the FilterRankingStrategy strategy can have negative effect on performance when there are filters that don't use  index. For example, the following query is faster without step reordering.

g.V().hasLabel('Case').has('closingDate').order().by('closingDate').filter(out('attachment').has('file'))

FilterRanking swaps order() and filter() steps and then index is not used for sorting.

Any help will be much appreciated.

Toom.

HadoopMarc

unread,
Dec 3, 2020, 2:17:27 AM12/3/20
to JanusGraph users
Hi Toom,

No solution, but the exception that you mention comes from TinkerPop:

Apparently, you want all selected vertices, including the ones with null properties, so I would wait for TinkerPop 3.5 and in the mean time use your own workaround for a single filter criterion and do the ordering outside gremlin for more complex sets of filtering criteria.

Best wishes,      Marc

Op woensdag 2 december 2020 om 08:13:05 UTC+1 schreef to...@thehive-project.org:

toom

unread,
Dec 3, 2020, 2:17:34 PM12/3/20
to JanusGraph users

Hi Marc,

Thank you for your response.
If I understand correctly, with TinkerPop 3.5 I will be able to sort on property with missing values. It is a good news.
Do you know it JanusGraph 0.6.0 will be release with that version ?

Regarding the impact of the step order on index use, I wrote a strategy [1] that put HasStep and OrderStep before FilterStep if they follow a GraphStep.

Best regards,

Toom.

Li, Boxuan

unread,
Dec 3, 2020, 8:22:02 PM12/3/20
to janusgra...@googlegroups.com
No, null support is an optional feature for graph providers. JanusGraph does not allow null value and I don’t think it will be supported (in near future).

Apart from the solution suggested by Marc, is it possible for you to come up with some custom value to represent null?

Best regards,
Boxuan

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/janusgraph-users/c6bcb878-bfc2-4d8f-a3ee-38cc214382bcn%40googlegroups.com.

toom

unread,
Dec 4, 2020, 1:59:13 AM12/4/20
to JanusGraph users

The problem of using custom value for null is that we need to choose a value for each data type, and hope that nobody will try to use this particular value. I suppose it is feasible for data type like string, date or double but not for boolean.

Toom.

owner....@gmail.com

unread,
Dec 17, 2020, 2:28:52 AM12/17/20
to JanusGraph users
We use special strategy that rewrite order comparator for supporting missing values https://gist.github.com/mad/6bef960d51d7a0d89a8c310851023303

пятница, 4 декабря 2020 г. в 09:59:13 UTC+3, to...@thehive-project.org:

toom

unread,
Dec 17, 2020, 2:37:16 AM12/17/20
to JanusGraph users
Thank you very much, I'll try that.

Toom.

Reply all
Reply to author
Forward
0 new messages