【问题标题】:Returning multiple values from one step using 'select', 'by' in Gremline在 Gremlin 中使用 'select'、'by' 一步返回多个值
【发布时间】:2021-02-05 18:28:17
【问题描述】:

我的图表架构如下所示:

(Location)<-[:INVENTOR_LOCATED_IN]-(Inventor)-[:INVENTOR_OF]->(Patent)

我正在尝试从查询路径中的每个步骤返回多个值。这是我目前运行正确的查询:

g.V().and(has('Location', 'city', textContains('Bloomington')), has('Location','state',textContains('IN'))).as('a').
  bothE().bothV().hasLabel('Inventor').as('b').
  bothE().bothV().has('Patent', 'title', textContains('Lid')).as('c').
  select('a,', 'b', 'c').
  by('state').by('name_first').by('title').
  fold();

我想做的是为每个步骤返回两个节点属性。我尝试了以下但它返回一个错误:

g.V().and(has('Location', 'city', textContains('Bloomington')), has('Location', 'state',textContains('IN'))).as('a').
  bothE().bothV().hasLabel('Inventor').as('b').
  bothE().bothV().has('Patent', 'title', textContains('Lid')).as('c').
  select('a,', 'b', 'c').
  by('city', 'state').by('name_first', 'name_last').by('title', 'abstract').
  fold();

谁能建议允许我从路径中的每个节点返回多个属性的语法?

【问题讨论】:

    标签: gremlin janusgraph


    【解决方案1】:

    by(key)values(key) 的一种简写形式,这意味着如果你有多个值,你可以这样做:

    g.V().and(has('Location', 'city', textContains('Bloomington')), has('Location', 'state',textContains('IN'))).as('a').
      bothE().bothV().hasLabel('Inventor').as('b').
      bothE().bothV().has('Patent', 'title', textContains('Lid')).as('c').
      select('a,', 'b', 'c').
        by(values('city', 'state').fold()).
        by(values('name_first', 'name_last').fold()).
        by(values('title', 'abstract').fold()).
      fold()
    

    您也可以考虑使用elementMap()valueMap()project() 的形式作为替代方案。由于by() 采用Traversal,因此您拥有很大的灵活性。

    【讨论】:

      猜你喜欢
      • 2023-01-15
      • 2013-09-22
      • 2018-01-30
      • 1970-01-01
      • 2019-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多