From cef11f9b0694ca0025f08381ab5e804bbe9a8855 Mon Sep 17 00:00:00 2001 From: Stephen Mallette Date: Tue, 5 Dec 2023 11:59:39 -0500 Subject: [PATCH] Coverage for anonymous traversals and anonymous traversal source The anonymous traversal source with() syntax is in 4.x now and is a bit more streamlined than what was there before. There may yet be some spots that were missed, but most should be covered. This also covers a lot of Graph API removal. #265 #259 --- book/Practical-Gremlin.adoc | 2 +- book/Section-Getting-Started.adoc | 5 +- book/Section-Introducing-Gremlin-Server.adoc | 28 +-- book/Section-Janus-Graph.adoc | 2 +- book/Section-Moving-Beyond.adoc | 2 +- book/Section-Writing-Gremlin-Queries.adoc | 183 ++++++++++++++++-- sample-code/dotnet/RemoteTests.cs | 2 +- sample-code/golang/go-basic.go | 2 +- sample-code/groovy/CreateGraph.groovy | 6 +- sample-code/groovy/GraphRegion.groovy | 8 +- sample-code/groovy/ShortestRoutes.groovy | 8 +- sample-code/groovy/TinkerGraphTest.groovy | 2 +- sample-code/groovy/janus-cassandra.groovy | 16 +- .../groovy/janus-composite-2key.groovy | 4 +- sample-code/groovy/janus-inmemory.groovy | 13 +- sample-code/groovy/nested-repeat.groovy | 2 +- sample-code/groovy/quick-airmap.groovy | 2 +- sample-code/groovy/quick-btree.groovy | 2 +- sample-code/groovy/quick-btree2.groovy | 2 +- sample-code/groovy/quick-social.groovy | 2 +- sample-code/groovy/quick-social2.groovy | 2 +- sample-code/java/RemoteAddBatch.java | 2 +- sample-code/java/RemoteBulkSetTest.java | 2 +- sample-code/java/RemoteClient.java | 2 +- sample-code/java/RemotePartitionStrategy.java | 2 +- sample-code/java/RemoteReadOnlyStrategy.java | 2 +- sample-code/java/RemoteSimpleClient.java | 2 +- sample-code/java/RemoteStats.java | 2 +- sample-code/java/RemoteSubgraphStrategy.java | 2 +- sample-code/java/RemoteVerticesFromMap.java | 2 +- sample-code/java/RemoteWriteText.java | 2 +- sample-code/javascript/glv-client.js | 3 +- sample-code/python/bootstrap-console.py | 6 +- sample-code/python/glv-client-2.py | 4 +- sample-code/python/glv-client.py | 4 +- sample-code/python/strategies.py | 4 +- 36 files changed, 254 insertions(+), 82 deletions(-) diff --git a/book/Practical-Gremlin.adoc b/book/Practical-Gremlin.adoc index b343edaf..629d951b 100755 --- a/book/Practical-Gremlin.adoc +++ b/book/Practical-Gremlin.adoc @@ -17,7 +17,7 @@ v2-001-preview, October 1st 2023 :icons: font //:pdf-page-size: Letter :draftdate: October 1st, 2023 -:tpvercheck: 3.7.0 +:tpvercheck: 4.0.0 // // Some notes about the Asciidoc files and processor // ------------------------------------------------- diff --git a/book/Section-Getting-Started.adoc b/book/Section-Getting-Started.adoc index 06eb28d4..21fc2f00 100644 --- a/book/Section-Getting-Started.adoc +++ b/book/Section-Getting-Started.adoc @@ -243,7 +243,7 @@ the following command from inside the Gremlin console. ---- // What version of Gremlin console am I running? gremlin> Gremlin.version() -==>3.7.0 +==>4.0.0 ---- One thing that is not at all obvious or apparent is that the Gremlin console quietly @@ -411,10 +411,11 @@ g = TinkerGraph.open().traversal() ---- which is shorthand for + [source,groovy] ---- graph = TinkerGraph.open() -g = graph.traversal() +g = traversal().with(graph) ---- In general you will not need access to the 'graph' object, and most operations can be diff --git a/book/Section-Introducing-Gremlin-Server.adoc b/book/Section-Introducing-Gremlin-Server.adoc index 2f13a521..b284d183 100644 --- a/book/Section-Introducing-Gremlin-Server.adoc +++ b/book/Section-Introducing-Gremlin-Server.adoc @@ -528,15 +528,15 @@ We have included examples of the different types of JSON result that you are lik to have to process in the "<>" section that is coming up soon. [[javagsclient]] -Connecting to a Gremlin Server from Java using 'withRemote' -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Connecting to a Gremlin Server from Java using 'with' +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ While it is perfectly possible to work directly with the JSON returned from a Gremlin Server it is often more desirable to have the results placed directly into variables of the appropriate type. If the appropriate Gremlin language driver exists for the programming language that you are using, this is quite easy to setup. In this section we will look at connecting to a Gremlin Server from a Java application and taking -advantage of the 'withRemote' capability that TinkerPop provides. +advantage of the remote connection capability that TinkerPop provides. NOTE: The source code in this section comes from the 'RemoteClient.java' sample located at https://github.com/krlawrence/graph/tree/main/sample-code/java. @@ -592,20 +592,22 @@ Once the 'Cluster.Builder' instance has been setup we can use it to create our Lastly, we need to setup a 'GraphTraversalSource' object for the Gremlin Server hosted graph that we will be working with. This object is often named "g" by convention and is typically created using the statically imported 'traversal()' -method which in turn allows the call to 'withRemote()' which is called to establish -the remote connection. Note that the cluster instance that we just created is passed -in as a parameter. While this looks a little complicated it is really not a lot -different than when we connect to a local graph using the Gremlin Console. The only -difference is that by setting up the remote connection this way, when we start to -issue queries against the graph, rather than getting JSON objects back, the results -will automatically be serialized into Java variables for us. This makes our code a -lot easier to write and essentially is the same code from this point onwards that -would also work with a local graph that we are directly connected to. +method which in turn allows the call to 'with()' to bind the traversal source to a +graph. We've seen 'with()' take a graph instance before, but this time we will use it +with a reference to a remote connection to a graph in Gremlin Server. Note that the +cluster instance that we just created is passed in as a parameter. While this looks a +little complicated it is really not a lot different than when we connect to a local +graph using the Gremlin Console. The only difference is that by setting up the remote +connection this way, when we start to issue queries against the graph, rather than +getting JSON objects back, the results will automatically be serialized into Java +variables for us. This makes our code a lot easier to write and essentially is the +same code from this point onwards that would also work with a local graph that we are +directly connected to. [source,groovy] ---- GraphTraversalSource g = traversal(). - withRemote(DriverRemoteConnection.using(cluster)); + with(DriverRemoteConnection.using(cluster)); ---- We can now use our new 'GraphTraversalSource' object to issue a Gremlin query. The diff --git a/book/Section-Janus-Graph.adoc b/book/Section-Janus-Graph.adoc index 59903ff7..e46da6b5 100644 --- a/book/Section-Janus-Graph.adoc +++ b/book/Section-Janus-Graph.adoc @@ -337,7 +337,7 @@ otherwise configuring a graph. [[janusmgmt]] The JanusGraph management API -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ JanusGraph includes a management API that is made available via the ManagementSystem class. You can use the management API to perform various important functions that diff --git a/book/Section-Moving-Beyond.adoc b/book/Section-Moving-Beyond.adoc index b7e4cb28..769eb7f7 100644 --- a/book/Section-Moving-Beyond.adoc +++ b/book/Section-Moving-Beyond.adoc @@ -1090,7 +1090,7 @@ And here is the sort of output we should get back. [source,groovy] ---- -Gremlin version is 3.7.0 +Gremlin version is 4.0.0 Loading the air-routes graph... [country:[US], code:[AUS], longest:[12250], city:[Austin], elev:[542], icao:[KAUS], lon:[-97.6698989868164], type:[airport], region:[US-TX], runways:[2], lat:[30.1944999694824], desc:[Austin Bergstrom International Airport]] diff --git a/book/Section-Writing-Gremlin-Queries.adoc b/book/Section-Writing-Gremlin-Queries.adoc index e0fd9f0e..7505b0f5 100644 --- a/book/Section-Writing-Gremlin-Queries.adoc +++ b/book/Section-Writing-Gremlin-Queries.adoc @@ -797,17 +797,14 @@ representing the number of runways the second airport has. ---- It is also possible to use a traversal inside of a 'by' modulator. Such traversals -are known as '"anonymous traversals"' as they do not include a beginning 'V' or 'E' -step. - -NOTE: Traversals that do not start with a 'V' or 'E' step are referred to as -'"anonymous traversals"'. +are known as '"anonymous traversals"' and they are discussed in greater details in +the <> section. -This capability allows us to do things like combine multiple values together as part -of a path result. The example below finds five routes that start in Austin and -creates a path result containing the airport code and city name for both the source -and destination airports. In this case, the anonymous traversal contained within the -'by' modulator is applied to each element in the path. +For now, it is enough to know that they allow us to do things like combine multiple +values together as part of a path result. The example below finds five routes that +start in Austin and creates a path result containing the airport code and city name +for both the source and destination airports. In this case, the anonymous traversal +contained within the 'by' modulator is applied to each element in the path. [source,groovy] ---- @@ -826,7 +823,7 @@ source and destination airports as part of generating the 'path' result. [source,groovy] ---- -g.V(3).out().limit(5).path().by(out().count()) +g.V(3).out().limit(5).path().by(outE().count()) [59,181] [59,191] @@ -1388,6 +1385,7 @@ such as 'outE', 'inE', 'outV' and 'inV'. [[limit]] Limiting the amount of data returned ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + It is sometimes useful, especially when dealing with large graphs, to limit the amount of data that is returned from a query. As shown in the examples below, this can be done using the 'limit' and 'tail' steps. A little later in @@ -1987,7 +1985,6 @@ IN={id=47, label=airport} OUT={id=3, label=airport} ---- - [[var]] Assigning query results to a variable with a terminal step ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -2206,6 +2203,168 @@ println s [2, 7, 5, 3, 4, 1] ---- +[[deepdivetraversals]] +Deep dive on traversal terminology +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In Gremlin, we use the word "traversal" often and there is a fair bit of terminology +associated with it. Understanding that terminology will greatly help with your +understanding of Gremlin. To get started in this learning, let's return to how we +create "g", known as the 'GraphTraversalSource', which is the connection to the graph +from which we can write Gremlin to query our data. + +[source,groovy] +---- +// create the Graph object which in this case is a TinkerGraph +graph = TinkerGraph.open() + +// create the GraphTraversalSource object +g = traversal().with(graph) +---- + +In looking at the above code, you might wonder where the 'traversal()' method comes +from. This function is a member of the 'AnonymousTraversalSource' class and it is +considered good form to statically import it so that it can be called without the +class. Calling 'traversal()' constructs an anonymous traversal source which is like +having a graph traversal source without a connection to a graph. Calling 'with()' on +this object binds it to a particular graph data source and then "g" is ready for you +to write your queries. + +You may see examples in this book, blog posts, or other documentation that shorthand +the creation of 'g' like + +[source,groovy] +---- +g = TinkerGraph.open().traversal() +---- + +While you can take this approach, it does preclude you from having reference to the +'Graph' object. While this is typically not a problem for TinkerGraph, it can be +an issue for other TinkerPop-enabled graphs that might require that reference to +release resources or access provider specific APIs. You will find this the case later +in this book when you read the "<>" +section. + +Another tempting shorthand is to skip the creation of "g" like + +[source,groovy] +---- +graph = TinkerGraph.open() +graph.traversal().V() +---- + +If you take this approach, you unnecessarily create 'GraphTraversalSource' objects +which will just end up in garbage collection. Typically, you create 'g' once and then +reuse it. One of the other benefits to creating 'g' once is that it allows you to set +configurations on the graph traversal source once rather than for each traversal you +execute. + +Configuration steps are used to setup options on the graph traversal source. These +steps are prefixed with 'with' and work in a builder pattern style as follows + +[source,groovy] +---- +graph = TinkerGraph.open() +g = traversal().with(graph) + +// construct a GraphTraversalSource configured with ReadOnlyStrategy and a +// List side-effect named "d" +g = g.withStrategies(ReadOnlyStrategy.instance()). + withSideEffect('d', [1,2,3]) +---- + +Once 'g' is configured you can then use start steps to spawn a 'Traversal'. In +TinkerPop, a "traversal" is a term we consider synonymous with "query". In the +context of querying graphs, the word "traversal" implies movement which aligns with +the visual image of traversing about the vertices and edges of a graph to get the +data that you need. + +While Gremlin has dozens of steps, not all of them can be used to spawn a +'Traversal'. Only those found on the 'GraphTraversalSource' can be used to do that. +The most commonly used start step is 'V', but there are a number of others, like +'E' to start by traversing edges or 'addV' to add a new vertex to the graph. It is +important to realize that a 'Traversal' object spawned from 'g' does not do much on +its own and requires that a terminal step be added to get the query results. This +point was introduced in the "<>" section but it is worth revisiting again as it is a common mistake +made by new Gremlin users. It is easy to illustrate this point clearly with an +example in Java. + +[source,java] +---- +// create the Traversal object - "t" is just a reference to the traversal and is +// not the result of "g.V()" being executed +Traversal t = g.V(); + +// to get the result we need a terminal step, in this case toList() +List l1 = t.toList(); + +// more commonly the traversal has the terminal step added right when it is spawned +List l2 = g.V().toList(); +---- + +There is one more piece of terminology to consider and we've touched on them earlier. +Anonymous traversals were first introduced in the "<>" section, where they were used to modify +'Path' objects returned from the 'path' step. One of those examples demonstrated how +a 'by' modulator could be given an anonymous traversal to convert vertices in the +returned path into a count of the number of outgoing routes from airports. + +[source,groovy] +---- +g.V(3).out().limit(5).path().by(outE().count()) + +[59,181] +[59,191] +[59,272] +[59,105] +[59,54] +---- + +We often see anonymous traversals used with 'by' but they can actually be used as an +argument for a great many Gremlin steps making them an integral part of the language. +Let's take a step back from usage and examine anonymous traversals as a concept. +Like the anonymous traversal source, an anonymous traversal is one that is not bound +to a graph. Instead of spawning from 'g', an anonymous traversal spawns from a class +named with a double-underscore. + +[source,groovy] +---- +// spawns a traversal bound to a graph +g.V().out() + +// spawns an anonymous traversal without binding to a graph +__.V().out() + +// the preferred approach is to statically import V() so that you can omit "__." +// the following anonymous traversal is the same as the one above +V().out() +---- + +As shown earlier with 'by', an anonymous traversal can be used as an argument for +many different traversal steps. + +[source,groovy] +---- +g.V().has('airport','code','AUS'). + repeat(timeLimit(10).out()).until(has('code','LHR')).path().by('code') +---- + +Without driving too deeply into the details of the example above, note that we've +used an anonymous traversal inside of both 'repeat' and 'until'. + +In this section, we learned about Gremlin terminology. In summary, here are the key +points to remember: + +* A 'Traversal' is a graph query. +* A 'GraphTraversalSource' is usually named "g" by convention and spawns 'Traversal' +objects. +* When either of these objects are referred to as "anonymous" they are not connected +to any graph. + +Now that you've learned all of this important Gremlin terminology you are well +prepared for the more advanced topics to come. + [[wid]] Working with IDs ~~~~~~~~~~~~~~~~ diff --git a/sample-code/dotnet/RemoteTests.cs b/sample-code/dotnet/RemoteTests.cs index c7f71ac4..aad58996 100644 --- a/sample-code/dotnet/RemoteTests.cs +++ b/sample-code/dotnet/RemoteTests.cs @@ -103,7 +103,7 @@ static void Main(string[] args) gremlinClient = new GremlinClient(gremlinServer, connectionPoolSettings:cpSettings); var remoteConnection = new DriverRemoteConnection(gremlinClient, "g"); - g = Traversal().WithRemote(remoteConnection); + g = Traversal().With(remoteConnection); } catch( Exception e) { diff --git a/sample-code/golang/go-basic.go b/sample-code/golang/go-basic.go index 14c45f08..dd881133 100644 --- a/sample-code/golang/go-basic.go +++ b/sample-code/golang/go-basic.go @@ -59,7 +59,7 @@ func createConnection(host string, port int) (*GraphTraversalSource, *DriverRemo if err != nil { log.Fatalln(err) } else { - g = Traversal().WithRemote(drc) + g = Traversal().With(drc) } return g, drc, err } diff --git a/sample-code/groovy/CreateGraph.groovy b/sample-code/groovy/CreateGraph.groovy index 64af33f0..ec7fcbc7 100644 --- a/sample-code/groovy/CreateGraph.groovy +++ b/sample-code/groovy/CreateGraph.groovy @@ -16,11 +16,13 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSo import org.apache.tinkerpop.gremlin.structure.T import org.apache.tinkerpop.gremlin.tinkergraph.structure.* +import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal; + // Create a new (empty) TinkerGrap -TinkerGraph tg = TinkerGraph.open() +TinkerGraph graph = TinkerGraph.open() // Create a Traversal source object -GraphTraversalSource g = tg.traversal() +GraphTraversalSource g = traversal().with(graph) // Add some nodes and vertices - Note the use of "iterate". g.addV("airport").property("code", "AUS").as("aus"). diff --git a/sample-code/groovy/GraphRegion.groovy b/sample-code/groovy/GraphRegion.groovy index 4d84983c..592f250a 100644 --- a/sample-code/groovy/GraphRegion.groovy +++ b/sample-code/groovy/GraphRegion.groovy @@ -17,16 +17,18 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ import org.apache.tinkerpop.gremlin.tinkergraph.structure.* import org.apache.tinkerpop.gremlin.util.Gremlin +import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal; + import java.io.IOException class RegionTest { - private TinkerGraph tg + private TinkerGraph graph private GraphTraversalSource g // Try to create a new graph and load the specified GraphML file def loadGraph(name) { - tg = TinkerGraph.open() - g = tg.traversal() + graph = TinkerGraph.open() + g = traversal().with(graph) try { g.io(name).read().iterate() diff --git a/sample-code/groovy/ShortestRoutes.groovy b/sample-code/groovy/ShortestRoutes.groovy index 57abf3ba..adf97533 100644 --- a/sample-code/groovy/ShortestRoutes.groovy +++ b/sample-code/groovy/ShortestRoutes.groovy @@ -15,16 +15,18 @@ import org.apache.tinkerpop.gremlin.process.traversal.* import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource import org.apache.tinkerpop.gremlin.tinkergraph.structure.* +import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal; + import java.io.IOException class Routes { - private TinkerGraph tg + private TinkerGraph graph private GraphTraversalSource g // Try to create a new graph and load the specified GraphML file def loadGraph(name) { - tg = TinkerGraph.open() - g = tg.traversal() + graph = TinkerGraph.open() + g = traversal().with(graph) try { g.io(name).read().iterate() diff --git a/sample-code/groovy/TinkerGraphTest.groovy b/sample-code/groovy/TinkerGraphTest.groovy index 055bf472..5cc71cf8 100644 --- a/sample-code/groovy/TinkerGraphTest.groovy +++ b/sample-code/groovy/TinkerGraphTest.groovy @@ -23,7 +23,7 @@ println "Gremlin version is ${Gremlin.version()}" def graph = TinkerGraph.open() // Create our graph traversal source -def g = graph.traversal() +def g = traversal().with(graph) // Try to load the air routes data println "Loading the air-routes graph...\n" diff --git a/sample-code/groovy/janus-cassandra.groovy b/sample-code/groovy/janus-cassandra.groovy index dd24d01e..cd5977ef 100644 --- a/sample-code/groovy/janus-cassandra.groovy +++ b/sample-code/groovy/janus-cassandra.groovy @@ -12,6 +12,12 @@ println "==============================================\n"; [] [] // Use the following line to use CQL graph = JanusGraphFactory.open('conf/janusgraph-cql.properties') +println "\n=========================="; [] +println "Acquiring traversal source"; [] +println "==========================\n"; [] +[] // Setup our traversal source object +g = traversal().with(graph) + println "\n==============="; [] println "Defining labels"; [] println "===============\n"; [] @@ -117,14 +123,8 @@ mgmt.awaitGraphIndexStatus(graph, 'distIndex'). println "\n========================"; [] println "Loading air-routes graph"; [] println "========================\n"; [] -graph.io(graphml()).readGraph('air-routes.graphml') -graph.tx().commit() - -println "\n=========================="; [] -println "Acquiring traversal source"; [] -println "==========================\n"; [] -[] // Setup our traversal source object -g = graph.traversal() +g.io('air-routes.graphml').read().iterate() +g.tx().commit() println "\n=========================="; [] println "Preparing graph statistics"; [] diff --git a/sample-code/groovy/janus-composite-2key.groovy b/sample-code/groovy/janus-composite-2key.groovy index 5ed13b1c..c0a259a7 100644 --- a/sample-code/groovy/janus-composite-2key.groovy +++ b/sample-code/groovy/janus-composite-2key.groovy @@ -9,7 +9,7 @@ [] // output from the Gremlin Console. [] // Make sure no other transactions are active -graph.tx().rollback() +g.tx().rollback() [] // Start a new management transaction mgmt = graph.openManagement() @@ -35,4 +35,4 @@ mgmt.commit() [] // Test out our new index. The profile step will show us which index was used g.V().has('city', 'London').has('country', 'CA').profile() -graph.tx().commit() +g.tx().commit() diff --git a/sample-code/groovy/janus-inmemory.groovy b/sample-code/groovy/janus-inmemory.groovy index 42146962..79530fd7 100644 --- a/sample-code/groovy/janus-inmemory.groovy +++ b/sample-code/groovy/janus-inmemory.groovy @@ -154,16 +154,19 @@ mgmt.updateIndex(mgmt.getGraphIndex('distIndex'), SchemaAction.REINDEX).get() mgmt.commit() +println "\n=========================="; [] +println "Acquiring traversal source"; [] +println "==========================\n"; [] +[] // Setup our traversal source object +g = traversal().with(graph) + [] // Load the air-routes graph and display a few statistics. [] // Not all of these steps use the index so Janus Graph will give us some warnings. println "\n========================"; [] println "Loading air-routes graph"; [] println "========================\n"; [] -graph.io(graphml()).readGraph('air-routes.graphml') -graph.tx().commit(); [] - -[] // Setup our traversal source object -g = graph.traversal() +g.io('air-routes.graphml').read().iterate() +g.tx().commit(); [] [] // Display a few statistics apt = g.V().has('type', 'airport').count().next(); [] diff --git a/sample-code/groovy/nested-repeat.groovy b/sample-code/groovy/nested-repeat.groovy index 9e06c8dd..d5b2b4eb 100644 --- a/sample-code/groovy/nested-repeat.groovy +++ b/sample-code/groovy/nested-repeat.groovy @@ -13,7 +13,7 @@ conf.setProperty("gremlin.tinkergraph.edgeIdManager", "LONG") conf.setProperty("gremlin.tinkergraph.vertexPropertyIdManager", "LONG") graph = TinkerGraph.open(conf) -g = graph.traversal() +g = traversal().with(graph) g.addV('person').property('name', 'Amy').as('amy'). addV('person').property('name', 'Bill').as('bill'). diff --git a/sample-code/groovy/quick-airmap.groovy b/sample-code/groovy/quick-airmap.groovy index ddc776af..aab31410 100644 --- a/sample-code/groovy/quick-airmap.groovy +++ b/sample-code/groovy/quick-airmap.groovy @@ -1,5 +1,5 @@ graph = TinkerGraph.open() -g = graph.traversal() +g = traversal().with(graph) g.addV('airport').property('code', 'AUS').as('aus'). addV('airport').property('code', 'DFW').as('dfw'). addV('airport').property('code', 'LAX').as('lax'). diff --git a/sample-code/groovy/quick-btree.groovy b/sample-code/groovy/quick-btree.groovy index e7763515..b6d3303b 100644 --- a/sample-code/groovy/quick-btree.groovy +++ b/sample-code/groovy/quick-btree.groovy @@ -4,7 +4,7 @@ [] // output from the Gremlin Console. graph = TinkerGraph.open() -g = graph.traversal() +g = traversal().with(graph) [] // Create the vertices and edges. Note how this is done in a single query [] // by chaining all of the steps together. diff --git a/sample-code/groovy/quick-btree2.groovy b/sample-code/groovy/quick-btree2.groovy index 60cbb6f3..172450ad 100644 --- a/sample-code/groovy/quick-btree2.groovy +++ b/sample-code/groovy/quick-btree2.groovy @@ -4,7 +4,7 @@ [] // output from the Gremlin Console. graph = TinkerGraph.open() -g = graph.traversal() +g = traversal().with(graph) g.addV('root').property('data', 9).as('root'). addV('node').property('data', 5).as('b'). diff --git a/sample-code/groovy/quick-social.groovy b/sample-code/groovy/quick-social.groovy index eab15dfc..bf280437 100644 --- a/sample-code/groovy/quick-social.groovy +++ b/sample-code/groovy/quick-social.groovy @@ -1,5 +1,5 @@ graph = TinkerGraph.open() -g = graph.traversal() +g = traversal().with(graph) g.addV("A").as("a"). addV("B").as("b"). diff --git a/sample-code/groovy/quick-social2.groovy b/sample-code/groovy/quick-social2.groovy index 8f91687b..a65a0bd8 100644 --- a/sample-code/groovy/quick-social2.groovy +++ b/sample-code/groovy/quick-social2.groovy @@ -11,7 +11,7 @@ [] // Remove these two lines if using a graph db other than TinkerGraph. graph = TinkerGraph.open() -g = graph.traversal() +g = traversal().with(graph) g.addV("person").property("name", "Albert").as("albert"). addV("person").property("name", "Bill").as("bill"). diff --git a/sample-code/java/RemoteAddBatch.java b/sample-code/java/RemoteAddBatch.java index 7b92db0c..9df66ec7 100644 --- a/sample-code/java/RemoteAddBatch.java +++ b/sample-code/java/RemoteAddBatch.java @@ -33,7 +33,7 @@ public static void main(String[] args) { Cluster cluster = builder.create(); GraphTraversalSource g = traversal(). - withRemote(DriverRemoteConnection.using(cluster)); + with(DriverRemoteConnection.using(cluster)); // Instead of building the traversal all in one go, the example // below shows how to create a traversal and incrementally add to it. diff --git a/sample-code/java/RemoteBulkSetTest.java b/sample-code/java/RemoteBulkSetTest.java index 1e987c71..7d34a381 100755 --- a/sample-code/java/RemoteBulkSetTest.java +++ b/sample-code/java/RemoteBulkSetTest.java @@ -45,7 +45,7 @@ public static void main(String[] args) { // Create a new traversal source object GraphTraversalSource g = traversal(). - withRemote(DriverRemoteConnection.using(cluster)); + with(DriverRemoteConnection.using(cluster)); // Find all cities with names that start with "Lon" // and return the results as a BulkSet. diff --git a/sample-code/java/RemoteClient.java b/sample-code/java/RemoteClient.java index 83d3da54..10816aae 100644 --- a/sample-code/java/RemoteClient.java +++ b/sample-code/java/RemoteClient.java @@ -29,7 +29,7 @@ public static void main(String[] args) { Cluster cluster = builder.create(); GraphTraversalSource g = traversal(). - withRemote(DriverRemoteConnection.using(cluster)); + with(DriverRemoteConnection.using(cluster)); List> vmaps = g.V().has("airport", "region", "GB-ENG").limit(10).valueMap().toList(); diff --git a/sample-code/java/RemotePartitionStrategy.java b/sample-code/java/RemotePartitionStrategy.java index 025d2965..dc52968d 100644 --- a/sample-code/java/RemotePartitionStrategy.java +++ b/sample-code/java/RemotePartitionStrategy.java @@ -36,7 +36,7 @@ public static void main(String[] args) { // Create a new traversal source object GraphTraversalSource g = traversal(). - withRemote(DriverRemoteConnection.using(cluster)); + with(DriverRemoteConnection.using(cluster)); // Make sure our connection is working. System.out.println(g.V().count().next()); diff --git a/sample-code/java/RemoteReadOnlyStrategy.java b/sample-code/java/RemoteReadOnlyStrategy.java index a3abb6d6..785e2797 100644 --- a/sample-code/java/RemoteReadOnlyStrategy.java +++ b/sample-code/java/RemoteReadOnlyStrategy.java @@ -35,7 +35,7 @@ public static void main(String[] args) { Cluster cluster = builder.create(); GraphTraversalSource g = traversal(). - withRemote(DriverRemoteConnection.using(cluster)); + with(DriverRemoteConnection.using(cluster)); // Create a new traversal source object GraphTraversalSource g2; diff --git a/sample-code/java/RemoteSimpleClient.java b/sample-code/java/RemoteSimpleClient.java index 7f0a0b35..d1334b0b 100644 --- a/sample-code/java/RemoteSimpleClient.java +++ b/sample-code/java/RemoteSimpleClient.java @@ -43,7 +43,7 @@ public static void runTests() { Cluster cluster = builder.create(); GraphTraversalSource g = - traversal().withRemote(DriverRemoteConnection.using(cluster)); + traversal().with(DriverRemoteConnection.using(cluster)); List> inTexas = g.V().has("airport", "region", "US-TX"). diff --git a/sample-code/java/RemoteStats.java b/sample-code/java/RemoteStats.java index 04759540..b77e871f 100644 --- a/sample-code/java/RemoteStats.java +++ b/sample-code/java/RemoteStats.java @@ -40,7 +40,7 @@ public static void main(String[] args) { Cluster cluster = builder.create(); GraphTraversalSource g = traversal(). - withRemote(DriverRemoteConnection.using(cluster)); + with(DriverRemoteConnection.using(cluster)); // Run some queries and display a few statistics diff --git a/sample-code/java/RemoteSubgraphStrategy.java b/sample-code/java/RemoteSubgraphStrategy.java index 5e08fe4f..b5d8c748 100644 --- a/sample-code/java/RemoteSubgraphStrategy.java +++ b/sample-code/java/RemoteSubgraphStrategy.java @@ -34,7 +34,7 @@ public static void main(String[] args) { Cluster cluster = builder.create(); GraphTraversalSource g = traversal(). - withRemote(DriverRemoteConnection.using(cluster)); + with(DriverRemoteConnection.using(cluster)); // Create a new traversal source object GraphTraversalSource g2; diff --git a/sample-code/java/RemoteVerticesFromMap.java b/sample-code/java/RemoteVerticesFromMap.java index e98e7669..34e1f3db 100644 --- a/sample-code/java/RemoteVerticesFromMap.java +++ b/sample-code/java/RemoteVerticesFromMap.java @@ -125,7 +125,7 @@ public GraphTraversalSource createConnection() { this.cluster = builder.create(); this.drc = DriverRemoteConnection.using(cluster); - this.gts = traversal().withRemote(drc); + this.gts = traversal().with(drc); return (gts); } diff --git a/sample-code/java/RemoteWriteText.java b/sample-code/java/RemoteWriteText.java index 78674704..bb2fb7b6 100644 --- a/sample-code/java/RemoteWriteText.java +++ b/sample-code/java/RemoteWriteText.java @@ -55,7 +55,7 @@ public static void runTests() { Cluster cluster = builder.create(); GraphTraversalSource g = - traversal().withRemote(DriverRemoteConnection.using(cluster)); + traversal().with(DriverRemoteConnection.using(cluster)); // Simple traversal we can use for testing a few things diff --git a/sample-code/javascript/glv-client.js b/sample-code/javascript/glv-client.js index 8de0d518..b2b81e00 100644 --- a/sample-code/javascript/glv-client.js +++ b/sample-code/javascript/glv-client.js @@ -12,6 +12,7 @@ const gremlin = require('gremlin'); const Graph = gremlin.structure.Graph; const __ = gremlin.process.statics; const { t,order,cardinality,column,scope,pop,operator,P } = gremlin.process; +const traversal = gremlin.process.AnonymousTraversalSource.traversal; // Note that if we just wanted to import 'decr' rather than all of order we could do: // const { order: { decr } } = gremlin.process; @@ -27,7 +28,7 @@ const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection; const connection = new DriverRemoteConnection(wspath,{}); const graph = new Graph(); console.log("Connecting to :" + wspath); -const g = graph.traversal().withRemote(connection); +const g = traversal().with_(connection); console.log("Connection created"); // Run a few tests that use the objects we imported above diff --git a/sample-code/python/bootstrap-console.py b/sample-code/python/bootstrap-console.py index 653650b4..6e704182 100644 --- a/sample-code/python/bootstrap-console.py +++ b/sample-code/python/bootstrap-console.py @@ -9,7 +9,8 @@ from gremlin_python.process.graph_traversal import __ from gremlin_python.process.strategies import * from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection -from gremlin_python.process.traversal import * +from gremlin_python.process.traversal import * +from gremlin_python.process.anonymous_traversal import traversal import os # This script assumes that two environment variables have been defined @@ -24,6 +25,5 @@ endpoint = 'ws://' + server + ':' + port + '/gremlin' print(endpoint) -graph=Graph() connection = DriverRemoteConnection(endpoint,'g') -g = graph.traversal().withRemote(connection) +g = traversal().with_(connection) diff --git a/sample-code/python/glv-client-2.py b/sample-code/python/glv-client-2.py index 756bb9c0..0f15f6d7 100644 --- a/sample-code/python/glv-client-2.py +++ b/sample-code/python/glv-client-2.py @@ -19,15 +19,15 @@ from gremlin_python.process.graph_traversal import __ from gremlin_python.process.strategies import * from gremlin_python.process.traversal import * +from gremlin_python.process.anonymous_traversal import traversal # Path to our graph (this assumes a locally running Gremlin Server) # Note how the path is a Web Socket (ws) connection. endpoint = 'ws://localhost:8182/gremlin' # Obtain a graph traversal source using a remote connection -graph=Graph() connection = DriverRemoteConnection(endpoint,'g') -g = graph.traversal().withRemote(connection) +g = traversal().with_(connection) # Helper method to pretty print some headings. def heading(s): diff --git a/sample-code/python/glv-client.py b/sample-code/python/glv-client.py index d4f10e03..d76688df 100644 --- a/sample-code/python/glv-client.py +++ b/sample-code/python/glv-client.py @@ -17,15 +17,15 @@ from gremlin_python.process.graph_traversal import __ from gremlin_python.process.strategies import * from gremlin_python.process.traversal import * +from gremlin_python.process.anonymous_traversal import traversal # Path to our graph (this assumes a locally running Gremlin Server) # Note how the path is a Web Socket (ws) connection. endpoint = 'ws://localhost:8182/gremlin' # Obtain a graph traversal source using a remote connection -graph=Graph() connection = DriverRemoteConnection(endpoint,'g') -g = graph.traversal().withRemote(connection) +g = traversal().with_(connection) # Sample 30 airports and return their code and city values. # The returned values will be packaged as a list containing 30 small lists. diff --git a/sample-code/python/strategies.py b/sample-code/python/strategies.py index a61a73a3..9093ea13 100644 --- a/sample-code/python/strategies.py +++ b/sample-code/python/strategies.py @@ -23,6 +23,7 @@ from gremlin_python.process.graph_traversal import __ from gremlin_python.process.strategies import * from gremlin_python.process.traversal import * +from gremlin_python.process.anonymous_traversal import traversal import sys # Path to our graph (this assumes a locally running Gremlin Server) @@ -30,9 +31,8 @@ endpoint = 'ws://localhost:8182/gremlin' # Obtain a graph traversal source using a remote connection -graph=Graph() connection = DriverRemoteConnection(endpoint,'g') -g = graph.traversal().withRemote(connection) +g = traversal().with_(connection) # Helper method to pretty print some headings. def heading(s):