【问题标题】:Gremlin, including vertices with zero edgesGremlin,包括零边的顶点
【发布时间】:2023-03-26 21:18:02
【问题描述】:

假设您有以下关系:

Author-----wrote---->Article

并且你想准备一份关于每个作者的报告,他写了多少篇文章以及他最后一篇文章的日期,当有作者没有写文章时出现问题,当你通过'写时他们将被丢弃' 管道,我想将它们包含在 'count' 列中的 '0' 和 'date' 列中的 'N/A' 中,所以我的问题是如何解决这个问题?

【问题讨论】:

    标签: orientdb gremlin


    【解决方案1】:

    鉴于您使用 OrientDB,我假设您仍在使用 TinkerPop 2.x,因此我将以这种方式回答。您需要执行以下操作:

    gremlin> g = new TinkerGraph()                        
    ==>tinkergraph[vertices:0 edges:0]
    gremlin> bill = g.addVertex([author:'bill',type:'author'])
    ==>v[0]
    gremlin> amy = g.addVertex([author:'amy',type:'author'])  
    ==>v[1]
    gremlin> book1 = g.addVertex([book:1,type:'book'])        
    ==>v[2]
    gremlin> book2 = g.addVertex([book:2,type:'book'])        
    ==>v[3]
    gremlin> bill.addEdge('wrote',book1)                      
    ==>e[4][0-wrote->2]
    gremlin> bill.addEdge('wrote',book2)
    ==>e[5][0-wrote->3]
    gremlin> g.V.has('type','author').transform{[it, it.outE('wrote').count()]}
    ==>[v[0], 2]
    ==>[v[1], 0]
    

    【讨论】:

    • 我找到了另一种解决方案,我使用'copySplit'管道将管道分成2个管道,一个获取没有边的顶点,另一个获取一个或多个顶点然后合并它们,但是我认为您的答案更好,因为我认为在复制拆分管道中,每个复制的管道都会重新访问每个顶点,我对这个假设是否正确?
    • 是的 - 没错,而且 copySplit 在 TinkerPop 2.x 中并不总是能正常工作。 union step in 3.x 效果更好但是:tinkerpop.incubator.apache.org/docs/3.0.0-incubating/…
    猜你喜欢
    • 1970-01-01
    • 2018-06-22
    • 2015-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    • 2019-01-06
    • 2015-02-27
    相关资源
    最近更新 更多