【问题标题】:how to create vertices without matching property values in gremlin?如何在 gremlin 中创建不匹配属性值的顶点?
【发布时间】:2021-11-06 18:46:13
【问题描述】:
我的数据模型如下:
节点:客户实体
~id telephone:String Name ~label
c1 969874293 Tien customer_entity
c1 987654145 Henry customer_entity
c1 954682174 Bobby customer_entity
节点:会员卡
~id Card_No_:String created_at ~label
c1 969874293 22/01/2014 membership_card
c1 190019688 14/08/2009 membership_card
c1 954682174 08/12/2019 membership_card
我使用我的查询创建了 phone_CDP 节点
    g.V().hasLabel('customer_entity').
    as('phone_m').values('telephone').
    as('value_phone').
    addV('phone_CDP').
    property('id',select('value_phone')).
    addE('alias').to('phone_m') `

    g.V().hasLabel('membership_card').
    as('phone_l').values('Card_No_').as('value_phone').
    addV('phone_CDP').property('id',select('value_phone')).
    addE('alias').to('phone_l')
 我的输出:
id
969874293
987654145
954682174
969874293
190019688
954682174
 如您所见,我有两个 id:969874293 和 954682174。所以想获得一个 id 值,如何在我的查询中执行? 
我想要的结果:
id
969874293
987654145
954682174
190019688

【问题讨论】:

    标签: gremlin graph-databases amazon-neptune


    【解决方案1】:

    您可以使用以下方法创建示例图:

    g = TinkerGraph.open().traversal()
    
    g.addV('customer_entity').property('telephone', '969874293').
        addV('customer_entity').property('telephone', '987654145').
        addV('customer_entity').property('telephone', '954682174')
    
    g.addV('membership_card').property('Card_No_', '969874293').
        addV('membership_card').property('Card_No_', '190019688').
        addV('membership_card').property('Card_No_', '954682174')
    

    您可以添加 phone_CDP 顶点:

    g.V().hasLabel('customer_entity', 'membership_card').
        coalesce(values('telephone'),values('Card_No_')).as('phid').dedup().
        addV('phone_CDP').property('phoneId', select('phid')).elementMap()
    

    ==>[id:12,label:phone_CDP,phoneId:969874293]
    ==>[id:14,label:phone_CDP,phoneId:987654145]
    ==>[id:16,label:phone_CDP,phoneId:954682174]
    ==>[id:18,label:phone_CDP,phoneId:190019688]

    您可以使用以下方法添加边:

    g.V().hasLabel('customer_entity', 'membership_card').as('vfrom').
        coalesce(values('telephone'),values('Card_No_')).as('phid').
      V().has('phoneId').as('vto').values('phoneId').where(eq('phid')).
      select('vfrom').addE('alias').to('vto')
    

    ==>e[20][0-alias->12]
    ==>e[21][2-别名->14]
    ==>e[22][4-别名->16]
    ==>e[23][6-别名->12]
    ==>e[24][8-别名->18]
    ==>e[25][10-别名->16]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多