I am trying to grab vertices connecting a Request vertex to each Card vertex. The card-to-request relationship is one-to-many (each card has many requests).
A card may be connected to a request with the property "Status"
: "In Use"
if the card is being used. Each card will also be connected to many requests with the properties "Status"
: "Future Use"
or "Past Use"
.
I am trying to create a table that displays the most recent use of each card.
Thus, I want to return a request if the edge connecting it to the card has the property "Status"
: "In Use"
.
If the card is not currently in use, I look for the request that most recently used the card ( "Status"
: "Past Use"
).
If the card has never been used, I look for the soonest upcoming request that will use the card ( "Status"
: "Future Use"
).
I have attempted to use coalesce
:
.coalesce(
select('request')
.outE().hasLabel('AssignedTo}').has('Status', 'In Use'),
select('request')
.outE().hasLabel('AssignedTo').has('Status', 'Past Use').order().by('Timestamp', decr).limit(1),
select('request')
.outE().hasLabel('AssignedTo').has('Status', 'Future Use').order().by('Timestamp', incr).limit(1)
).as('status')
But this only returns a single record (In Use). Another version:
.coalesce(
select('card')
.inE().hasLabel('AssignedTo}').has('Status', 'In Use'),
select('card')
.inE().hasLabel('AssignedTo').has('Status', 'Past Use').order().by('Timestamp', decr).limit(1),
select('card')
.inE().hasLabel('AssignedTo').has('Status', 'Future Use').order().by('Timestamp', incr).limit(1)
).as('status')
This only returned two records (both In Use).
I tried choose
awhile ago and couldn't get that to work either (don't recall what happened exactly).
Expected:
Get back a single vertex that has an edge with the property "Status"
: "In Use"
.
If this edge doesn't exist, get the most recent vertex that has an edge with the property "Status"
: "Past Use"
.
If there are no edges that qualify, get the soonest upcoming vertex that has an edge with the property "Status"
: "Future Use"
.
I'm not sure what went wrong with your query since you didn't post it entirely, but this should work:
g.V().hasLabel("Card").as("c").coalesce(
outE("assigned").has("status", "In Use"),
outE("assigned").has("status", "Past Use").order().by("Timestamp", desc).limit(1),
outE("assigned").has("status", "Future Use").order().by("Timestamp", asc).limit(1),
).as("s").inV().as("r")
.select("c","s","r").by("name").by("status").by("name")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.