Skip to content

Instantly share code, notes, and snippets.

View spmallette's full-sized avatar

stephen mallette spmallette

View GitHub Profile
gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> objects = [[name: "marko"], [name:"marko"]]
==>[name:marko]
==>[name:marko]
gremlin> g.inject(objects).
......1> unfold().as('m').
......2> coalesce(V().hasLabel("person").as('p').where('m',eq('p')).by('name'),
......3> addV("person").property("name", __.select("name"))).iterate()
gremlin> g.V()
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V(3).property('lang','ruby')
==>v[3]
gremlin> g.V().has("name","lop").values("lang").as("l").V().has("lang", __.select("l")).values('lang')
==>ruby
==>java
gremlin> g.V().has("name","lop").values("lang").as("l").V().has("lang", __.where(eq("l"))).values('lang')
==>ruby
[INFO] Reactor Summary for Apache TinkerPop 3.4.11-SNAPSHOT:
[INFO]
[INFO] Apache TinkerPop ................................... SUCCESS [ 2.630 s]
[INFO] Apache TinkerPop :: Gremlin Shaded ................. SUCCESS [ 1.208 s]
[INFO] Apache TinkerPop :: Gremlin Core ................... SUCCESS [ 19.539 s]
[INFO] Apache TinkerPop :: Gremlin Test ................... SUCCESS [ 3.165 s]
[INFO] Apache TinkerPop :: TinkerGraph Gremlin ............ SUCCESS [01:27 min]
[INFO] Apache TinkerPop :: Gremlin Groovy ................. SUCCESS [01:40 min]
[INFO] Apache TinkerPop :: Gremlin Driver ................. SUCCESS [ 22.363 s]
[INFO] Apache TinkerPop :: Neo4j Gremlin .................. SUCCESS [ 0.347 s]
:install com.amazonaws amazon-neptune-sigv4-signer 2.1.1
:install com.amazonaws aws-java-sdk-core 1.11.748
// above lines only need to be executed once to get the dependencies into the console
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.neptune.auth.NeptuneNettyHttpSigV4Signer
System.setProperty("aws.accessKeyId","<access-key>")
System.setProperty("aws.secretKey","<secret-key>")
cluster = Cluster.build("<cluster>").
host = "localhost"
requests = 10000
cluster = Cluster.open()
g = traversal().withRemote(DriverRemoteConnection.using(cluster))
println("vertices at start: " + g.V().count().next())
println("edges at start: " + g.E().count().next())
start = System.currentTimeMillis()
(0..<50000).each{
gremlin> class NeptuneTypeTranslator extends GroovyTranslator.DefaultTypeTranslator {
......1> protected String convertToString(Object object) {
......2> if (object instanceof Long)
......3> return object.toString();
......4> else
......5> return super.convertToString(object)
......6> }
......7> }
==>true
gremlin> translator = GroovyTranslator.of("g", new NeptuneTypeTranslator());
gremlin> [1,10,50,100,500,1000,5000,10000].collect {
......1> def binding = [a: RandomStringUtils.random(30), b: rand.nextDouble(), c: rand.nextInt(), d: rand.nextInt()]
......2> def longScript = (0..<it).collect{engine.createTemplate(baseScript).make(binding)}.join()
......3> def start = System.nanoTime()
......4> GremlinASTChecker.parse(longScript).getTimeout().get()
......5> [it, TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)]
......6> }
==>[1,1]
==>[10,1]
==>[50,4]
describe("#construct", function () {
it('should not hang if server not present', function() {
const g = traversal().withRemote(new DriverRemoteConnection('ws://localhost:9998/gremlin', {traversalSource: 'g'}));
return g.V().toList().then(function() {
assert.fail("that shouldn't have happened");
}).catch(function(err) {
if (err instanceof AssertionError) throw err;
assert.strictEqual(err, "connection error");
});
});
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@spmallette
spmallette / gremlin-merge.md
Last active July 12, 2023 13:50
Gremlin merge() API

Gremlin mergeV/E() API

mergeV/E(Map|Traversal search).
  option(Merge.onCreate, Map|Traversal).
  option(Merge.onMatch, Map|Traversal)

Examples