如何在 gremlin 中创建不匹配 属性 值的顶点?
how to create vertices without matching property values in gremlin?
My data model as below:
node:customer_entity
~id
telephone:String
Name
~label
c1
969874293
Tien
customer_entity
c1
987654145
Henry
customer_entity
c1
954682174
Bobby
customer_entity
node:membership_card
~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
I created phone_CDP node by using my query
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')
my output:
id
969874293
987654145
954682174
969874293
190019688
954682174
As you see i have two ids: 969874293 and 954682174 .So want to get one id value, how to do in my query?
result i want :
id
969874293
987654145
954682174
190019688
您可以使用以下方法创建示例图表:
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-alias->14]
==>e[22][4-alias->16]
==>e[23][6-alias->12]
==>e[24][8-alias->18]
==>e[25][10-alias->16]
My data model as below: node:customer_entity
~id | telephone:String | Name | ~label |
---|---|---|---|
c1 | 969874293 | Tien | customer_entity |
c1 | 987654145 | Henry | customer_entity |
c1 | 954682174 | Bobby | customer_entity |
node:membership_card
~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 |
I created phone_CDP node by using my query
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')
my output:
id |
---|
969874293 |
987654145 |
954682174 |
969874293 |
190019688 |
954682174 |
As you see i have two ids: 969874293 and 954682174 .So want to get one id value, how to do in my query?
result i want :
id |
---|
969874293 |
987654145 |
954682174 |
190019688 |
您可以使用以下方法创建示例图表:
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-alias->14]
==>e[22][4-alias->16]
==>e[23][6-alias->12]
==>e[24][8-alias->18]
==>e[25][10-alias->16]