Select 如果到顶点的边具有 属性 值,则为顶点,否则选择具有不同边 属性 值的另一个顶点

Select a vertex if the edge to the vertex has a property value, otherwise choose another vertex with a different edge property value

我正在尝试获取将 Request 顶点连接到每个 Card 顶点的顶点。卡片与请求的关系是一对多的(每张卡片有很多请求)。

如果正在使用卡片,卡片可能会连接到带有 属性 "Status" 的请求:"In Use"。每张卡片还将连接到许多具有属性 "Status" 的请求:"Future Use""Past Use".

我正在尝试创建一个 table 来显示每张卡的最近使用情况。

因此,我想 return 如果连接到卡片的边具有 属性 "Status" 的请求:"In Use".

如果该卡当前未被使用,我将查找最近使用该卡的请求 ("Status": "Past Use")。

如果该卡从未被使用过,我会寻找即将使用该卡的最近请求("Status""Future 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')

但这只是 return 一条记录(使用中)。另一个版本:

.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')

这只 return 了两条记录(都在使用中)。

我刚才 choose 试过,但也无法正常工作(不记得具体发生了什么)。

预期:

取回具有 属性 "Status" 边的单个顶点:"In Use"

如果此边不存在,则获取具有 属性 "Status" 边的最近顶点:"Past Use".

如果没有符合条件的边,则获取具有 属性 "Status" 边的最快即将到来的顶点:"Future Use".

我不确定你的查询出了什么问题,因为你没有完全post,但这应该有效:

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")