isohrab
isohrab
ATApache TinkerPop
Created by isohrab on 7/21/2023 in #questions
Deleting X nodes when there is no incoming Y nodes to them
Hello, In my case, a team has many Member and each member works only for one company. a company can also works for another company. I want to delete all companies that no member of team works for them. In the following example company W and Z must be deleted but company Y should not. because member A works for X and X works for Y.
g.addV('team').property('name', 'backend').as('t').
addV('person').property('name', 'A').as('a').
addV('company').property('name', 'X').as('x').
addV('company').property('name', 'Y').as('y').
addV('company').property('name', 'Z').as('z').
addV('company').property('name', 'W').as('w').
addE('member').from('t').to('a').
addE('cooperate').from('t').to('y').
addE('cooperate').from('t').to('x').
addE('cooperate').from('t').to('z').
addE('cooperate').from('t').to('w').
addE('work').from('a').to('x').
addE('work').from('x').to('y').
addE('work').from('z').to('y').
addE('work').from('w').to('z').
next()
g.addV('team').property('name', 'backend').as('t').
addV('person').property('name', 'A').as('a').
addV('company').property('name', 'X').as('x').
addV('company').property('name', 'Y').as('y').
addV('company').property('name', 'Z').as('z').
addV('company').property('name', 'W').as('w').
addE('member').from('t').to('a').
addE('cooperate').from('t').to('y').
addE('cooperate').from('t').to('x').
addE('cooperate').from('t').to('z').
addE('cooperate').from('t').to('w').
addE('work').from('a').to('x').
addE('work').from('x').to('y').
addE('work').from('z').to('y').
addE('work').from('w').to('z').
next()
I wrote following query (and tried many other queries) but It delete all companies that does not have any direct member.
g.V().has('team', 'name', 'backend').
outE("cooperate").inV().not_(__.inE("work")).emit().repeat(__.out()).times(3).
dedup().fold().coalesce(__.unfold().drop()).toList()
g.V().has('team', 'name', 'backend').
outE("cooperate").inV().not_(__.inE("work")).emit().repeat(__.out()).times(3).
dedup().fold().coalesce(__.unfold().drop()).toList()
3 is the maximum depth of companies that can work with other companies. I really appreciate your help
3 replies
ATApache TinkerPop
Created by isohrab on 7/17/2023 in #questions
Pass label to coalesce
When I want to pass a label to a coalesce step I get follwoing error:
"addE(occupied) failed because the from() traversal (which should give a Vertex) failed with: The provided traverser does not map to a value: v[10190][TinkerVertex]->[SelectOneStep(last,u,null)
"addE(occupied) failed because the from() traversal (which should give a Vertex) failed with: The provided traverser does not map to a value: v[10190][TinkerVertex]->[SelectOneStep(last,u,null)
this is my code:
g.addV('user').property('name', 'mari').as('u').
out().has('location','name', "Z").fold().
coalesce(
__.unfold(),
__.addV('location').property('name', "Z").as("loc").
addE('occupied').from('u').to('loc')
)
g.addV('user').property('name', 'mari').as('u').
out().has('location','name', "Z").fold().
coalesce(
__.unfold(),
__.addV('location').property('name', "Z").as("loc").
addE('occupied').from('u').to('loc')
)
Appreciate your help
5 replies