简体   繁体   English

Gremlin - 从 valueMap 中提取 T.id 和 T.label

[英]Gremlin - extracting T.id and T.label from valueMap

This question is related to this post that Kelvin Lawrence answered very helpfully, wanted to post it as a separate question bec the first question was answered well already.这个问题与 Kelvin Lawrence 非常有帮助地回答的这个帖子有关,想将它作为一个单独的问题发布,因为第一个问题已经得到很好的回答。

From this query:从这个查询:

g.V('a2661f57-8aa7-4e5c-9c89-55cf9b7e4cf8').as('self')
.sideEffect(out('rated').store('movies')) 
.out('friended')
.group() 
.by(valueMap(true).by(unfold())) 
.by(out('rated').where(within('movies')).count()) 
.order(local) 
.by(values,desc) 
.unfold()
.select(keys)

i get this result:我得到这个结果:

1   {<T.id: 1>: 'fdc45bd3-be08-4716-b20f-b4f04987c5e0', <T.label: 4>: 'user', 'username': 'elin102dev', 'name': 'elin obrien', 'avatarUrl': 'public/avatars/fdc45bd3-be08-4716-b20f-b4f04987c5e0.jpg'}
2   {<T.id: 1>: 'bbf1b0db-68cc-41f1-8c7a-5fd77b698e39', <T.label: 4>: 'user', 'username': 'iris', 'name': 'Iris Ebert', 'avatarUrl': 'public/avatars/bbf1b0db-68cc-41f1-8c7a-5fd77b698e39.jpg'}
3   {<T.id: 1>: '34c2ea80-4f84-4652-a7c3-48ce43d9aea7', <T.label: 4>: 'user', 'username': 'iris103dev', 'name': 'iris obrien', 'avatarUrl': 'public/avatars/34c2ea80-4f84-4652-a7c3-48ce43d9aea7.jpg'}

I want to convert the T.id and T.label values in the response to simply "id" and "label".我想将响应中的 T.id 和 T.label 值转换为简单的“id”和“label”。 Kelvin, if you're reading this, ii tried appending the following to the query above but it returns 0 results: Kelvin,如果你正在阅读这篇文章,我尝试将以下内容附加到上面的查询中,但它返回 0 个结果:

.select('id', 'label', 'username', 'name', 'avatarUrl') 
    .by(T.id)
    .by(T.label)
    .by('username')
    .by('name')
    .by('avatarUrl')
    .toList()

I could use a little more help figuring this out, not having much success.我可以使用更多的帮助来解决这个问题,但没有取得太大的成功。 Thanks in advance.提前致谢。

It is not possible to do a select(T.id) inside a query.不可能在查询中执行select(T.id) In code if you get a map back you can access the T.id field.在代码中,如果您返回map ,则可以访问T.id字段。 For a case such as this, it is better to delay fetching the properties until you finally need them.对于这种情况,最好延迟获取属性,直到您最终需要它们。 You might try rewriting the query like this.您可以尝试像这样重写查询。

g.V('a2661f57-8aa7-4e5c-9c89-55cf9b7e4cf8').as('self').
  sideEffect(out('rated').store('movies')). 
  out('friended').
  group(). 
    by(). 
    by(out('rated').where(within('movies')).count()). 
  order(local). 
    by(values,desc). 
    unfold().
  select(keys).
  project('id','label','username').
    by(id).
    by(label).
    by('username')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM