[英]Gremlin - extracting T.id and T.label from valueMap
這個問題與 Kelvin Lawrence 非常有幫助地回答的這個帖子有關,想將它作為一個單獨的問題發布,因為第一個問題已經得到很好的回答。
從這個查詢:
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)
我得到這個結果:
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'}
我想將響應中的 T.id 和 T.label 值轉換為簡單的“id”和“label”。 Kelvin,如果你正在閱讀這篇文章,我嘗試將以下內容附加到上面的查詢中,但它返回 0 個結果:
.select('id', 'label', 'username', 'name', 'avatarUrl')
.by(T.id)
.by(T.label)
.by('username')
.by('name')
.by('avatarUrl')
.toList()
我可以使用更多的幫助來解決這個問題,但沒有取得太大的成功。 提前致謝。
不可能在查詢中執行select(T.id)
。 在代碼中,如果您返回map
,則可以訪問T.id
字段。 對於這種情況,最好延遲獲取屬性,直到您最終需要它們。 您可以嘗試像這樣重寫查詢。
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.