gremlin-python drop multiple vertices and edges in one transaction
My context:
- gremlin-python
- AWS Neptune
My question is:
1) Can I drop vertices and edges recursively in one transaction given that I have all the specific ids of the vertices and edges I want to drop? The aim is to write python function that evaluates each edge, and determine whether it needs to be dropped, and chain a gremlin query to drop it.
For instance:
vertex ids to delete:
'vertex1', 'vertex2', 'vertex3'
edge ids to delete:
'edge1', 'edge2', 'edge3'
An example of the python function to chain on to g would be like:
def chain_drop(g, vertex_id):
g = g.V(vertex_id).drop()
return g
The chained query i would like to execute as one transaction would ideally look something like:
g.E('edge1').drop()
.V('vertex1').drop()
.E('edge3').drop()
.V('vertex3').drop()
.iterate() # execute all these queries as one transaction
The above doesn't work... And it seems I cannot .E('someid') in the middle of my gremlin query.
Slightly off topic but my best try (non-recursive) would be something like below:
g.E('edge1', 'edge2', 'edge3').as_('edges')
.V('vertex1', 'vertex2', 'vertex3').as_('vertices')
.union(__.select('edges'),
__.select('vertices'))
.drop()
.iterate()
Any help much appreciated!
python gremlin amazon-neptune
add a comment |
My context:
- gremlin-python
- AWS Neptune
My question is:
1) Can I drop vertices and edges recursively in one transaction given that I have all the specific ids of the vertices and edges I want to drop? The aim is to write python function that evaluates each edge, and determine whether it needs to be dropped, and chain a gremlin query to drop it.
For instance:
vertex ids to delete:
'vertex1', 'vertex2', 'vertex3'
edge ids to delete:
'edge1', 'edge2', 'edge3'
An example of the python function to chain on to g would be like:
def chain_drop(g, vertex_id):
g = g.V(vertex_id).drop()
return g
The chained query i would like to execute as one transaction would ideally look something like:
g.E('edge1').drop()
.V('vertex1').drop()
.E('edge3').drop()
.V('vertex3').drop()
.iterate() # execute all these queries as one transaction
The above doesn't work... And it seems I cannot .E('someid') in the middle of my gremlin query.
Slightly off topic but my best try (non-recursive) would be something like below:
g.E('edge1', 'edge2', 'edge3').as_('edges')
.V('vertex1', 'vertex2', 'vertex3').as_('vertices')
.union(__.select('edges'),
__.select('vertices'))
.drop()
.iterate()
Any help much appreciated!
python gremlin amazon-neptune
add a comment |
My context:
- gremlin-python
- AWS Neptune
My question is:
1) Can I drop vertices and edges recursively in one transaction given that I have all the specific ids of the vertices and edges I want to drop? The aim is to write python function that evaluates each edge, and determine whether it needs to be dropped, and chain a gremlin query to drop it.
For instance:
vertex ids to delete:
'vertex1', 'vertex2', 'vertex3'
edge ids to delete:
'edge1', 'edge2', 'edge3'
An example of the python function to chain on to g would be like:
def chain_drop(g, vertex_id):
g = g.V(vertex_id).drop()
return g
The chained query i would like to execute as one transaction would ideally look something like:
g.E('edge1').drop()
.V('vertex1').drop()
.E('edge3').drop()
.V('vertex3').drop()
.iterate() # execute all these queries as one transaction
The above doesn't work... And it seems I cannot .E('someid') in the middle of my gremlin query.
Slightly off topic but my best try (non-recursive) would be something like below:
g.E('edge1', 'edge2', 'edge3').as_('edges')
.V('vertex1', 'vertex2', 'vertex3').as_('vertices')
.union(__.select('edges'),
__.select('vertices'))
.drop()
.iterate()
Any help much appreciated!
python gremlin amazon-neptune
My context:
- gremlin-python
- AWS Neptune
My question is:
1) Can I drop vertices and edges recursively in one transaction given that I have all the specific ids of the vertices and edges I want to drop? The aim is to write python function that evaluates each edge, and determine whether it needs to be dropped, and chain a gremlin query to drop it.
For instance:
vertex ids to delete:
'vertex1', 'vertex2', 'vertex3'
edge ids to delete:
'edge1', 'edge2', 'edge3'
An example of the python function to chain on to g would be like:
def chain_drop(g, vertex_id):
g = g.V(vertex_id).drop()
return g
The chained query i would like to execute as one transaction would ideally look something like:
g.E('edge1').drop()
.V('vertex1').drop()
.E('edge3').drop()
.V('vertex3').drop()
.iterate() # execute all these queries as one transaction
The above doesn't work... And it seems I cannot .E('someid') in the middle of my gremlin query.
Slightly off topic but my best try (non-recursive) would be something like below:
g.E('edge1', 'edge2', 'edge3').as_('edges')
.V('vertex1', 'vertex2', 'vertex3').as_('vertices')
.union(__.select('edges'),
__.select('vertices'))
.drop()
.iterate()
Any help much appreciated!
python gremlin amazon-neptune
python gremlin amazon-neptune
asked Nov 22 '18 at 14:21
Matthew TanMatthew Tan
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can't do what you want to do exactly for two reasons:
- There is no mid-traversal
E()
as it is a start step only.
drop()
is kills all traversers so the mid-traversalV()
following it won't ever get executed.
You can take a different approach however and simply gather all of your elements to remove and then then drop those...something like:
g.V(1).aggregate('x').V(2).aggregate('x').select('x').unfold().drop()
Note that dropping vertices will also drop edges so if those edges you want to drop are connected to the vertices you want to drop you don't need to drop them explicitly.
Thank you Stephen for the clarification and the pointers! I've gotten around dropping Edges and Vertices in the same query by doing so:g.E('edge1, 'edge2', 'edge3').aggregate('x').fold() .V(1).aggregate('x').V(2).aggregate('x') .select('x').unfold().drop()
– Matthew Tan
Nov 23 '18 at 15:05
do you need tofold()
? i wouldn't think so.aggregate()
is greedy step so it should collect all edges without need tofold()
anything
– stephen mallette
Nov 23 '18 at 17:40
I did the fold() as a trick to reduce 3 traversers to one. Then subsequent chained steps only get called on the one traverser. But you're right, it doesn't change the result I think...
– Matthew Tan
Nov 24 '18 at 9:26
you're right. i'd forgotten that the mid-traversalV()
will get called once per traverser.
– stephen mallette
Nov 24 '18 at 12:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432985%2fgremlin-python-drop-multiple-vertices-and-edges-in-one-transaction%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't do what you want to do exactly for two reasons:
- There is no mid-traversal
E()
as it is a start step only.
drop()
is kills all traversers so the mid-traversalV()
following it won't ever get executed.
You can take a different approach however and simply gather all of your elements to remove and then then drop those...something like:
g.V(1).aggregate('x').V(2).aggregate('x').select('x').unfold().drop()
Note that dropping vertices will also drop edges so if those edges you want to drop are connected to the vertices you want to drop you don't need to drop them explicitly.
Thank you Stephen for the clarification and the pointers! I've gotten around dropping Edges and Vertices in the same query by doing so:g.E('edge1, 'edge2', 'edge3').aggregate('x').fold() .V(1).aggregate('x').V(2).aggregate('x') .select('x').unfold().drop()
– Matthew Tan
Nov 23 '18 at 15:05
do you need tofold()
? i wouldn't think so.aggregate()
is greedy step so it should collect all edges without need tofold()
anything
– stephen mallette
Nov 23 '18 at 17:40
I did the fold() as a trick to reduce 3 traversers to one. Then subsequent chained steps only get called on the one traverser. But you're right, it doesn't change the result I think...
– Matthew Tan
Nov 24 '18 at 9:26
you're right. i'd forgotten that the mid-traversalV()
will get called once per traverser.
– stephen mallette
Nov 24 '18 at 12:51
add a comment |
You can't do what you want to do exactly for two reasons:
- There is no mid-traversal
E()
as it is a start step only.
drop()
is kills all traversers so the mid-traversalV()
following it won't ever get executed.
You can take a different approach however and simply gather all of your elements to remove and then then drop those...something like:
g.V(1).aggregate('x').V(2).aggregate('x').select('x').unfold().drop()
Note that dropping vertices will also drop edges so if those edges you want to drop are connected to the vertices you want to drop you don't need to drop them explicitly.
Thank you Stephen for the clarification and the pointers! I've gotten around dropping Edges and Vertices in the same query by doing so:g.E('edge1, 'edge2', 'edge3').aggregate('x').fold() .V(1).aggregate('x').V(2).aggregate('x') .select('x').unfold().drop()
– Matthew Tan
Nov 23 '18 at 15:05
do you need tofold()
? i wouldn't think so.aggregate()
is greedy step so it should collect all edges without need tofold()
anything
– stephen mallette
Nov 23 '18 at 17:40
I did the fold() as a trick to reduce 3 traversers to one. Then subsequent chained steps only get called on the one traverser. But you're right, it doesn't change the result I think...
– Matthew Tan
Nov 24 '18 at 9:26
you're right. i'd forgotten that the mid-traversalV()
will get called once per traverser.
– stephen mallette
Nov 24 '18 at 12:51
add a comment |
You can't do what you want to do exactly for two reasons:
- There is no mid-traversal
E()
as it is a start step only.
drop()
is kills all traversers so the mid-traversalV()
following it won't ever get executed.
You can take a different approach however and simply gather all of your elements to remove and then then drop those...something like:
g.V(1).aggregate('x').V(2).aggregate('x').select('x').unfold().drop()
Note that dropping vertices will also drop edges so if those edges you want to drop are connected to the vertices you want to drop you don't need to drop them explicitly.
You can't do what you want to do exactly for two reasons:
- There is no mid-traversal
E()
as it is a start step only.
drop()
is kills all traversers so the mid-traversalV()
following it won't ever get executed.
You can take a different approach however and simply gather all of your elements to remove and then then drop those...something like:
g.V(1).aggregate('x').V(2).aggregate('x').select('x').unfold().drop()
Note that dropping vertices will also drop edges so if those edges you want to drop are connected to the vertices you want to drop you don't need to drop them explicitly.
answered Nov 22 '18 at 14:45
stephen mallettestephen mallette
25.4k32776
25.4k32776
Thank you Stephen for the clarification and the pointers! I've gotten around dropping Edges and Vertices in the same query by doing so:g.E('edge1, 'edge2', 'edge3').aggregate('x').fold() .V(1).aggregate('x').V(2).aggregate('x') .select('x').unfold().drop()
– Matthew Tan
Nov 23 '18 at 15:05
do you need tofold()
? i wouldn't think so.aggregate()
is greedy step so it should collect all edges without need tofold()
anything
– stephen mallette
Nov 23 '18 at 17:40
I did the fold() as a trick to reduce 3 traversers to one. Then subsequent chained steps only get called on the one traverser. But you're right, it doesn't change the result I think...
– Matthew Tan
Nov 24 '18 at 9:26
you're right. i'd forgotten that the mid-traversalV()
will get called once per traverser.
– stephen mallette
Nov 24 '18 at 12:51
add a comment |
Thank you Stephen for the clarification and the pointers! I've gotten around dropping Edges and Vertices in the same query by doing so:g.E('edge1, 'edge2', 'edge3').aggregate('x').fold() .V(1).aggregate('x').V(2).aggregate('x') .select('x').unfold().drop()
– Matthew Tan
Nov 23 '18 at 15:05
do you need tofold()
? i wouldn't think so.aggregate()
is greedy step so it should collect all edges without need tofold()
anything
– stephen mallette
Nov 23 '18 at 17:40
I did the fold() as a trick to reduce 3 traversers to one. Then subsequent chained steps only get called on the one traverser. But you're right, it doesn't change the result I think...
– Matthew Tan
Nov 24 '18 at 9:26
you're right. i'd forgotten that the mid-traversalV()
will get called once per traverser.
– stephen mallette
Nov 24 '18 at 12:51
Thank you Stephen for the clarification and the pointers! I've gotten around dropping Edges and Vertices in the same query by doing so:
g.E('edge1, 'edge2', 'edge3').aggregate('x').fold() .V(1).aggregate('x').V(2).aggregate('x') .select('x').unfold().drop()
– Matthew Tan
Nov 23 '18 at 15:05
Thank you Stephen for the clarification and the pointers! I've gotten around dropping Edges and Vertices in the same query by doing so:
g.E('edge1, 'edge2', 'edge3').aggregate('x').fold() .V(1).aggregate('x').V(2).aggregate('x') .select('x').unfold().drop()
– Matthew Tan
Nov 23 '18 at 15:05
do you need to
fold()
? i wouldn't think so. aggregate()
is greedy step so it should collect all edges without need to fold()
anything– stephen mallette
Nov 23 '18 at 17:40
do you need to
fold()
? i wouldn't think so. aggregate()
is greedy step so it should collect all edges without need to fold()
anything– stephen mallette
Nov 23 '18 at 17:40
I did the fold() as a trick to reduce 3 traversers to one. Then subsequent chained steps only get called on the one traverser. But you're right, it doesn't change the result I think...
– Matthew Tan
Nov 24 '18 at 9:26
I did the fold() as a trick to reduce 3 traversers to one. Then subsequent chained steps only get called on the one traverser. But you're right, it doesn't change the result I think...
– Matthew Tan
Nov 24 '18 at 9:26
you're right. i'd forgotten that the mid-traversal
V()
will get called once per traverser.– stephen mallette
Nov 24 '18 at 12:51
you're right. i'd forgotten that the mid-traversal
V()
will get called once per traverser.– stephen mallette
Nov 24 '18 at 12:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432985%2fgremlin-python-drop-multiple-vertices-and-edges-in-one-transaction%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown