'sort by Property that's not part of the GroupBy statement
I have a graph with one start-node and two goal-vetices. Two paths lead to the first goal, another path to the second. I look for all paths to the goals vertices and collect the edge weights (sack(sum)). I add the sum of all paths leading to the same goal via group().by().
query so far:
g.withSack(1.0f).V('v0')
.repeat(
outE().sack(mult).by('weight')
.inV()
).until(hasLabel('goal'))
.group().by().by(sack())
.unfold()
.project('sack', 'map')
.by(select(values))
.by(select(keys).valueMap(true))
.order().by('sack', desc)
the result looks like this:
{'sack': 0.27999999999999997, 'map': {<T.id: 1>: 'v7', <T.label: 4>: 'goal', 'date': ['02-02-2022']}}
{'sack': 0.125, 'map': {<T.id: 1>: 'v3', <T.label: 4>: 'goal', 'date': ['02-02-2022']}}
now I want to also sort by date... However, using by('date', desc) results in an error:
"java.util.LinkedHashMap cannot be cast to java.lang.Comparable"
can I somehow access the date-value inside the map? or sort by date in some other way?
(fyi: by(sack(), desc) works just as well as by('sack', desc) )
data:
g.addV('start').property(id, 'v0')
.addV('road').property(id, 'v1')
.addV('road').property(id, 'v2')
.addV('goal').property(id, 'v3').property('date', '02-02-2022')
.addV('road').property(id, 'v4').
.addV('road').property(id, 'v5').
.addV('road').property(id, 'v6').
.addV('goal').property(id, 'v7').property('date', '22-02-2022')
.addE('link').property('weight', 0.4).from(V('v0')).to(V('v1'))
.addE('link').property('weight', 0.4).from(V('v1')).to(V('v2'))
.addE('link').property('weight', 0.4).from(V('v2')).to(V('v3'))
.addE('link').property('weight', 0.5).from(V('v0')).to(V('v5'))
.addE('link').property('weight', 0.5).from(V('v5')).to(V('v4'))
.addE('link').property('weight', 0.5).from(V('v4')).to(V('v3'))
.addE('link').property('weight', 0.7).from(V('v0')).to(V('v6'))
.addE('link').property('weight', 0.4).from(V('v6')).to(V('v7'))
(my code runs on Neptune with 'gremlin': {'version': 'tinkerpop-3.4.11'})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
