danielcraig23
danielcraig23
ATApache TinkerPop
Created by danielcraig23 on 5/9/2024 in #questions
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?
const g = traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin'));
const tx = g.tx(); // create a Transaction

// spawn a new GraphTraversalSource binding all traversals established from it to tx
const gtx = tx.begin();

// execute traversals using gtx occur within the scope of the transaction held by tx. the
// tx is closed after calls to commit or rollback and cannot be re-used. simply spawn a
// new Transaction from g.tx() to create a new one as needed. the g context remains
// accessible through all this as a sessionless connection.
Promise.all([
gtx.addV("person").property("name", "jorge").iterate(),
gtx.addV("person").property("name", "josh").iterate()
]).then(() => {
return tx.commit();
}).catch(() => {
return tx.rollback();
});
const g = traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin'));
const tx = g.tx(); // create a Transaction

// spawn a new GraphTraversalSource binding all traversals established from it to tx
const gtx = tx.begin();

// execute traversals using gtx occur within the scope of the transaction held by tx. the
// tx is closed after calls to commit or rollback and cannot be re-used. simply spawn a
// new Transaction from g.tx() to create a new one as needed. the g context remains
// accessible through all this as a sessionless connection.
Promise.all([
gtx.addV("person").property("name", "jorge").iterate(),
gtx.addV("person").property("name", "josh").iterate()
]).then(() => {
return tx.commit();
}).catch(() => {
return tx.rollback();
});
13 replies
ATApache TinkerPop
Created by danielcraig23 on 5/9/2024 in #questions
Using mergeE to create an edge with an id that depends on a lookup
I want to use mergeE to produce an edge whose id is the concatenation of the ids of its inV and outV vertices. But the inV vertex has to be looked up, the exact id is not known without a lookup. Suppose that partialMacbookId === "macbookAir" and the result of the lookup is the vertex with id "macbookAir2024" And suppose that ownerId === "1111" I want to create a hasOwner edge with id "macbookAir20241111" Is this possible?
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();
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();
8 replies
ATApache TinkerPop
Created by danielcraig23 on 5/8/2024 in #questions
Is tx.close() necessary in Javascript?
I have read the following two pieces of documentation and I have the question, is tx.close() necessary in Javascript?
https://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript-transactions https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-transactions.html
6 replies
ATApache TinkerPop
Created by danielcraig23 on 4/18/2024 in #questions
.mergeV() with Javascript not working
Hi, I have a nodeJS 18 lambda which is closely modeled after this documentation: https://docs.aws.amazon.com/neptune/latest/userguide/lambda-functions-examples.html#lambda-functions-examples-javascript here is my async query function:
async function query(context) {
const { userId } = context;
return g
.mergeV(new Map([[t.id, userId]]))
.option(
merge.onCreate,
new Map([
[t.label, 'myLabel']
])
)
.next();
}
async function query(context) {
const { userId } = context;
return g
.mergeV(new Map([[t.id, userId]]))
.option(
merge.onCreate,
new Map([
[t.label, 'myLabel']
])
)
.next();
}
This code produces the following vertex, without using the userId or label which I provided:
gremlin> g.V().elementMap()
==>[id:84c77791-6b38-6c39-c63a-4f0a84d3058e,label:vertex]
gremlin> g.V().elementMap()
==>[id:84c77791-6b38-6c39-c63a-4f0a84d3058e,label:vertex]
How can I troubleshoot this function? I'm using Neptune 1.2.1.0 with a nodeJs 18 lambda and here is an excerpt from my package.json and yarn.lock which shows the gremlin versions which yarn resolved for my project
"dependencies": {
"date-fns": "^2.30.0",
"gremlin": "3.6.2",
"gremlin-aws-sigv4": "^3.6.1"
}
"dependencies": {
"date-fns": "^2.30.0",
"gremlin": "3.6.2",
"gremlin-aws-sigv4": "^3.6.1"
}
"gremlin-aws-sigv4@npm:^3.6.1":
version: 3.6.1
resolution: "gremlin-aws-sigv4@npm:3.6.1"
dependencies:
aws4: ^1.11.0
debug: ^4.3.4
gremlin: ^3.6.1
checksum: 51e574db25ecf7c046e257b30d2b43ef18ef09e7564558bc2b40452ac0db2ce85eee556074bd4cbe5d02f554e9c995264377498cfc78ff3b4713e0dd7bcd480d
languageName: node
linkType: hard

"gremlin@npm:3.6.2":
version: 3.6.2
resolution: "gremlin@npm:3.6.2"
dependencies:
ws: ^8.11.0
checksum: c70c08ee108e9437afc81d6a945f66f5756c5dc09dd2772026d41bced952d5564c6f61e87066f3c807fb0f8c8af290ac399962c866f2b4695c0953d4e9113428
languageName: node
linkType: hard

"gremlin@npm:^3.6.1":
version: 3.7.1
resolution: "gremlin@npm:3.7.1"
dependencies:
ws: ^8.11.0
checksum: e1a9cbf0bbcade9e66b9b9b5c3e51c15314e55fec5dba2dd8d3f309cff18b0ae4bffbfbf9e7c239054454b6060bc6aecb787e10af168f114722660d0ad049753
languageName: node
linkType: hard
"gremlin-aws-sigv4@npm:^3.6.1":
version: 3.6.1
resolution: "gremlin-aws-sigv4@npm:3.6.1"
dependencies:
aws4: ^1.11.0
debug: ^4.3.4
gremlin: ^3.6.1
checksum: 51e574db25ecf7c046e257b30d2b43ef18ef09e7564558bc2b40452ac0db2ce85eee556074bd4cbe5d02f554e9c995264377498cfc78ff3b4713e0dd7bcd480d
languageName: node
linkType: hard

"gremlin@npm:3.6.2":
version: 3.6.2
resolution: "gremlin@npm:3.6.2"
dependencies:
ws: ^8.11.0
checksum: c70c08ee108e9437afc81d6a945f66f5756c5dc09dd2772026d41bced952d5564c6f61e87066f3c807fb0f8c8af290ac399962c866f2b4695c0953d4e9113428
languageName: node
linkType: hard

"gremlin@npm:^3.6.1":
version: 3.7.1
resolution: "gremlin@npm:3.7.1"
dependencies:
ws: ^8.11.0
checksum: e1a9cbf0bbcade9e66b9b9b5c3e51c15314e55fec5dba2dd8d3f309cff18b0ae4bffbfbf9e7c239054454b6060bc6aecb787e10af168f114722660d0ad049753
languageName: node
linkType: hard
28 replies
ATApache TinkerPop
Created by danielcraig23 on 11/29/2023 in #questions
How can I use the .io("filename.json").write() pattern to append to an existing graphson file?
I have read about defining a custom GraphWriter using the builder, but wanted to ask first before spending more time Here is my example code:
private static Graph buildGraph() {
BaseConfiguration configuration = new BaseConfiguration();
configuration.setProperty("gremlin.tinkerGraph.vertexIdManager", "ANY");

return TinkerGraph.open(configuration);
}

@Test
public void test() {
Graph graph = buildGraph();
GraphTraversalSource g;
g = AnonymousTraversalSource.traversal().withEmbedded(graph);

g.addV("source").property(T.id, "firstSource")
.addV("sink").property(T.id, "firstSink")
.addE("edge").property(T.id, "firstEdge").from(__.V("firstSource")).to(__.V("firstSink"))
.iterate();

g.addV("source").property(T.id, "secondSource")
.addV("sink").property(T.id, "secondSink")
.addE("edge").property(T.id, "secondEdge").from(__.V("secondSource")).to(__.V("secondSink"))
.iterate();

final Graph firstResult = (Graph) g.E("firstEdge").subgraph("subgraph").cap("subgraph").next();

GraphTraversalSource firstGts = AnonymousTraversalSource.traversal().withEmbedded(firstResult);
firstGts.io("src/test/resources/example.json").write().iterate();

// Here the initial contents of the file are overwritten

final Graph secondResult = (Graph) g.E("secondEdge").subgraph("subgraph").cap("subgraph").next();

GraphTraversalSource secondGts = AnonymousTraversalSource.traversal().withEmbedded(secondResult);
secondGts.io("src/test/resources/example.json").write().iterate();


}
private static Graph buildGraph() {
BaseConfiguration configuration = new BaseConfiguration();
configuration.setProperty("gremlin.tinkerGraph.vertexIdManager", "ANY");

return TinkerGraph.open(configuration);
}

@Test
public void test() {
Graph graph = buildGraph();
GraphTraversalSource g;
g = AnonymousTraversalSource.traversal().withEmbedded(graph);

g.addV("source").property(T.id, "firstSource")
.addV("sink").property(T.id, "firstSink")
.addE("edge").property(T.id, "firstEdge").from(__.V("firstSource")).to(__.V("firstSink"))
.iterate();

g.addV("source").property(T.id, "secondSource")
.addV("sink").property(T.id, "secondSink")
.addE("edge").property(T.id, "secondEdge").from(__.V("secondSource")).to(__.V("secondSink"))
.iterate();

final Graph firstResult = (Graph) g.E("firstEdge").subgraph("subgraph").cap("subgraph").next();

GraphTraversalSource firstGts = AnonymousTraversalSource.traversal().withEmbedded(firstResult);
firstGts.io("src/test/resources/example.json").write().iterate();

// Here the initial contents of the file are overwritten

final Graph secondResult = (Graph) g.E("secondEdge").subgraph("subgraph").cap("subgraph").next();

GraphTraversalSource secondGts = AnonymousTraversalSource.traversal().withEmbedded(secondResult);
secondGts.io("src/test/resources/example.json").write().iterate();


}
, which gets results as follows:
{"id":"secondSink","label":"sink","inE":{"edge":[{"id":"secondEdge","outV":"secondSource"}]}}
{"id":"secondSource","label":"source","outE":{"edge":[{"id":"secondEdge","inV":"secondSink"}]}}
{"id":"secondSink","label":"sink","inE":{"edge":[{"id":"secondEdge","outV":"secondSource"}]}}
{"id":"secondSource","label":"source","outE":{"edge":[{"id":"secondEdge","inV":"secondSink"}]}}
7 replies
ATApache TinkerPop
Created by danielcraig23 on 11/7/2023 in #questions
Can I surpress gremlin console's warnings?
How can I surpress these WARNING messages? I've tried gremlin -l but can't seem to get the syntax right because it seems to have no effect when I do gremlin -l ERROR
% gremlin
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/local/apache-tinkerpop-gremlin-console-3.6.2/lib/groovy-2.5.15-indy.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

\,,,/
(o o)
-----oOOo-(3)-oOOo-----
plugin activated: tinkerpop.server
plugin activated: tinkerpop.utilities
plugin activated: tinkerpop.tinkergraph
% gremlin
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/local/apache-tinkerpop-gremlin-console-3.6.2/lib/groovy-2.5.15-indy.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

\,,,/
(o o)
-----oOOo-(3)-oOOo-----
plugin activated: tinkerpop.server
plugin activated: tinkerpop.utilities
plugin activated: tinkerpop.tinkergraph
5 replies
ATApache TinkerPop
Created by danielcraig23 on 10/16/2023 in #questions
Can I name the result of an anonymous traversal without moving the traverser?
I can currently do the following:
Graph graph = TinkerFactory.createModern();

GraphTraversalSource gts = AnonymousTraversalSource.traversal().withEmbedded(graph);

gts.V().hasLabel("person")
.has("name", "josh")
.where(__.out().has("name", "ripple"))
.project("rippleCreatorName", "rippleName", "rippleLang")
.by("name")
.by(__.out().has("name", "ripple").values("name"))
.by(__.out().has("name", "ripple").values("lang"))
.toList();
Graph graph = TinkerFactory.createModern();

GraphTraversalSource gts = AnonymousTraversalSource.traversal().withEmbedded(graph);

gts.V().hasLabel("person")
.has("name", "josh")
.where(__.out().has("name", "ripple"))
.project("rippleCreatorName", "rippleName", "rippleLang")
.by("name")
.by(__.out().has("name", "ripple").values("name"))
.by(__.out().has("name", "ripple").values("lang"))
.toList();
I wish I could do something like this instead:
Graph graph = TinkerFactory.createModern();

GraphTraversalSource gts = AnonymousTraversalSource.traversal().withEmbedded(graph);

gts.V().hasLabel("person").has("name", "josh")
.let("ripple", __.out().has("name", "ripple"))
.project("rippleCreatorName", "rippleName", "rippleLang")
.by("name")
.by(__.select("ripple").values("name"))
.by(__.select("ripple").values("lang"))
.toList()
Graph graph = TinkerFactory.createModern();

GraphTraversalSource gts = AnonymousTraversalSource.traversal().withEmbedded(graph);

gts.V().hasLabel("person").has("name", "josh")
.let("ripple", __.out().has("name", "ripple"))
.project("rippleCreatorName", "rippleName", "rippleLang")
.by("name")
.by(__.select("ripple").values("name"))
.by(__.select("ripple").values("lang"))
.toList()
What would you recommend to me? I only want to do __.out().has("name", "ripple") once, because in my project this filter is much longer so there is considerable repeated code.
7 replies
ATApache TinkerPop
Created by danielcraig23 on 8/24/2023 in #questions
Does .math() always return a Double?
I have the following query, how can I get the result as a Long instead of a Double? In context, I want this query to be unioned with a set of other numbers which are Longs and then I want to take the .max() of them. But I can't do that if I have a mix of Long and Double
Long tenHours = Long.valueOf(Duration.ofHours(10).toMillis());

g.withSideEffect("tenHours", tenHours).inject(1689570000000L).math("_ + tenHours").next().getClass()
Long tenHours = Long.valueOf(Duration.ofHours(10).toMillis());

g.withSideEffect("tenHours", tenHours).inject(1689570000000L).math("_ + tenHours").next().getClass()
6 replies
ATApache TinkerPop
Created by danielcraig23 on 7/21/2023 in #questions
How can I filter by property type
No description
9 replies
ATApache TinkerPop
Created by danielcraig23 on 7/19/2023 in #questions
How can I write a project using an inject that doesn't exhaust itself?
Take the following example query: g.inject("1", "2", "3").project("list").by(__.inject("b").fold()).toList() its result is [{list=[1, b]}, {list=[2]}, {list=[3]}] I'd like to see [{list=[1, b]}, {list=[2, b]}, {list=[3, b]}] instead How can I accomplish this?
8 replies
ATApache TinkerPop
Created by danielcraig23 on 7/14/2023 in #questions
Can I use a query to export data in the form of a query?
In the SQL world you can use SQL Developer to generate INSERT statements from the results of a query. I want to sample some of our Neptune data for use in a unit test that uses Tinkergraph - is it possible to capture the results of a query as something like g.addV() queries that allow me to export my real data into Tinkergraph?
15 replies
ATApache TinkerPop
Created by danielcraig23 on 6/16/2023 in #questions
Using the modern graph, how can I write a query that finds the name of the oldest person?
I want to take the graph produced by TinkerFactory.createModern() and write a query that finds the oldest person and returns their name. I want to learn to use the max() traversal step.
11 replies
ATApache TinkerPop
Created by danielcraig23 on 6/5/2023 in #questions
What's the status amazon-neptune-sigv4-signer?
amazon-neptune-sigv4-signer hasn't had a new release in 2 years, is it still part of the recommended set of tools for aws Neptune?
5 replies