Is the insertion order guaranteed with this example code?
Taking the following code which is found at https://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript-transactions, is the insertion order guaranteed for these two new vertices?
Solution:Jump to solution
right, there are no any guaranties with
Promise.all
if for some reason the insertion order is important, then you need to call sequentially
gtx.addV("person").property("name", "jorge").iterate();
gtx.addV("person").property("name", "josh").iterate();
...10 Replies
Note you can do addV twice in the same traversal I think. If you do it’s atomic and do not need to wrap in TX
Yes that's certainly true, for reasons of breaking up a series of several long .mergeV() and .mergeE()'s I want to use a transaction so that there's space in between.
i'm no javascript expert, but in that particular example, i dont think
Promise.all(...)
offers any guaranteed of execution order for each job given to it, so no, i dont think you can always expect "josh" to come after "jorge". maybe we should have a better example there cc/ @Valentyn KahamlykSolution
right, there are no any guaranties with
Promise.all
if for some reason the insertion order is important, then you need to call sequentially
gtx.addV("person").property("name", "jorge").iterate();
gtx.addV("person").property("name", "josh").iterate();
this is critical for mergeE/mergeV to avoid concurrent mergeV to add/update Vertex and mergeE which will use this VertexIs this an acceptable way of making sequential writes? I am using async.retry to retry the promise returned by tx.commit(), similar to this example from Amazon: https://docs.aws.amazon.com/neptune/latest/userguide/lambda-functions-examples.html#lambda-functions-examples-javascript
```
const tx = g.tx();
try {
// get the graph traversal source from the transaction
const gtx = tx.begin();
gtx.addV("owner").property(id, "1111").iterate() gtx.addV("laptop").property(id, "macbookAir2024").property("yearReleased", 2024).iterate() gtx.V() .hasLabel('laptop') .has(t.id, textP.startingWith(partialMacbookId)) .order() .by('yearReleased', desc) .limit(1) .as("mostRecentMacbook") .mergeE( new Map([ [t.label, 'hasOwner'], [direction.out, merge.outV], [direction.in, merge.inV]] ) ) .option(merge.outV, .select('mostRecentMacbook')) .option(merge.inV, .V(ownerId)) .iterate(); return tx.commit(); } catch (error) { logger.error(error); // roll back the transaction return tx.rollback(); }
gtx.addV("owner").property(id, "1111").iterate() gtx.addV("laptop").property(id, "macbookAir2024").property("yearReleased", 2024).iterate() gtx.V() .hasLabel('laptop') .has(t.id, textP.startingWith(partialMacbookId)) .order() .by('yearReleased', desc) .limit(1) .as("mostRecentMacbook") .mergeE( new Map([ [t.label, 'hasOwner'], [direction.out, merge.outV], [direction.in, merge.inV]] ) ) .option(merge.outV, .select('mostRecentMacbook')) .option(merge.inV, .V(ownerId)) .iterate(); return tx.commit(); } catch (error) { logger.error(error); // roll back the transaction return tx.rollback(); }
AWS Lambda function examples for Amazon Neptune - Amazon Neptune
The following example AWS Lambda functions, written in Java, JavaScript and Python, illustrate upserting a single vertex with a randomly generated ID using the fold().coalesce().unfold() idiom.
@Valentyn Kahamlyk does gtx....iterate() have a strategy for maintaining the order of these writes?
for TinkerPop 3.7.x data is updated in the order that it is received, but strictly speaking this is not documented
for 3.6.2 is this also the case?
when you call `iterate() that should be the trigger to make the request to the server within a session. the order in which those requests to the session are received by the server should be the order in which they are executed.
Ok thank you!!