Skip to content

Instantly share code, notes, and snippets.

View spmallette's full-sized avatar

stephen mallette spmallette

View GitHub Profile
@spmallette
spmallette / console.txt
Created September 13, 2024 14:52
Streaming GraphSON
Type: LinkedHashMap Value: {id=1, label=person, name=[marko], age=[29]}
Type: LinkedHashMap Value: {id=2, label=person, name=[vadas], age=[27]}
Type: LinkedHashMap Value: {id=3, label=software, name=[lop], lang=[java]}
Type: LinkedHashMap Value: {id=4, label=person, name=[josh], age=[32]}
Type: LinkedHashMap Value: {id=5, label=software, name=[ripple], lang=[java]}
Type: LinkedHashMap Value: {id=6, label=person, name=[peter], age=[35]}
https://discord.com/events/838910279550238720/1264929259957518356
package org.apache.tinkerpop.gremlin.util;
import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.step.Configuring;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.FlatMapStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep;
gremlin> g.V().hasLabel('person').order().by('name').store('x').by('age').project('name','running').by('name').by(select('x').mean(local))
==>[name:josh,running:32.0]
==>[name:marko,running:30.5]
==>[name:peter,running:32.0]
==>[name:vadas,running:30.75]
gremlin> g.V().hasLabel('person').aggregate('results').profile('profile').cap('results','profile').next()
==>profile=Traversal Metrics
Step Count Traversers Time (ms) % Dur
=============================================================================================================
gremlin> g.V('1','2','3').aggregate('a').has(T.id,'1').
repeat(out().where(P.without('a')).aggregate('a')).emit().
select('a')
==>[v[1],v[2],v[3],v[4]]
==>[v[1],v[2],v[3],v[4],v[5]]
gremlin> g.V('1','2','3').aggregate('a').has(T.id,'1').
repeat(out().where(P.without('a')).aggregate(global,'a')).emit().
barrier().
g.mergeV([(T.label):'Dog', name:'Max']).option(onCreate, [alias: 'Maximus', city: 'Boston'], set)
// 3.7.2-SNAPSHOT
gremlin> g.mergeV([(T.label):'Dog', name:'Max']).option(onCreate, [alias: 'Maximus', city: 'Boston'], set)
==>v[0]
gremlin> g.V().valueMap()
==>[city:[Boston],name:[Max],alias:[Maximus]]
gremlin> g.V().properties()
==>vp[city->Boston]
==>vp[name->Max]
// * Improved performance of the application of `FilterRankingStrategy` for large traversals with deeply nested traversals by improving the cache operation.
g.V().as("n").
where(__.or(__.select("n").hasLabel("software"), __.select("n").hasLabel("person"))).
select("n").by("name")
before
FilterRankingStrategy [O] [GraphStep(vertex,[])@[n], TraversalFilterStep([OrStep([[SelectOneStep(last,n,null), HasStep([~label.eq(software)])], [SelectOneStep(last,n,null), HasStep([~label.eq(person)])]])]), SelectOneStep(last,n,value(name))]
after
https://discord.com/channels/838910279550238720/1191149924256071853/1191149924256071853
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().
......1> emit(__.loops().is(gte(1))).
......2> repeat(__.bothE().otherV()).times(2).as('x').
......3> emit(__.loops().is(gte(1))).
......4> repeat(__.inE().outV()).times(2).
......5> bothE().
......6> dedup().by(__.path()).
......7> otherV().
g.V('44').repeat(local(outE('route').sample(1).inV())).times(3).path().by('code').by('dist')