### Install Kerberos Development Libraries (Python) Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Install the necessary libraries for Python's Kerberos testing. This is a prerequisite for Python environment setup. ```bash sudo apt install libkrb5-dev krb5-user ``` -------------------------------- ### Build and Install Project with Maven Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Use this command for a simple build and installation of the project using Maven. Ensure you have Maven installed and configured. ```bash mvn clean install ``` -------------------------------- ### Java Client Example for Traversal OpProcessor Source: https://tinkerpop.apache.org/docs/3.8.1/dev/provider A Java client-side example demonstrating the initialization of a Gremlin cluster connection and the submission of a traversal using the Traversal OpProcessor. This code mirrors the Groovy example, showing the equivalent setup and traversal submission. ```java cluster = Cluster.open() client = cluster.connect() aliased = client.alias("g") g = traversal().with(org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph.instance()) //// **(1)** rs = aliased.submit(g.V().both().barrier().both().barrier()).all().get() //// **(2)** aliased.submit(g.V().both().barrier().both().barrier().count()).all().get().get(0).getInt() //// **(3)** rs.collect{[value: it.getObject().get(), bulk: it.getObject().bulk()]} //**4** ``` -------------------------------- ### Install Cassandra Driver and Connect to Cassandra Source: https://tinkerpop.apache.org/docs/3.8.1/tutorials/the-gremlin-console Use the :install command to add the Cassandra driver to the console's classpath. Then, import necessary classes and establish a connection to a Cassandra instance. ```groovy gremlin> :install com.datastax.cassandra cassandra-driver-core 2.1.9 ==>Loaded: [com.datastax.cassandra, cassandra-driver-core, 2.1.9] gremlin> import com.datastax.driver.core.* ==>groovy.grape.Grape, org.apache.commons.configuration2.*, ..., com.datastax.driver.core.* gremlin> import static com.datastax.driver.core.querybuilder.QueryBuilder.* ==>groovy.grape.Grape, org.apache.commons.configuration2.*, ..., static com.datastax.driver.core.querybuilder.QueryBuilder.* gremlin> cluster = com.datastax.driver.core.Cluster.builder().addContactPoint("localhost").build() ==>com.datastax.driver.core.Cluster@3e1624c7 gremlin> session = cluster.connect() ==>com.datastax.driver.core.SessionManager@35764bef gremlin> session.execute("CREATE KEYSPACE crew WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 }") gremlin> session.execute("USE crew") gremlin> session.execute("CREATE TABLE locations ( name varchar, location varchar, year int, PRIMARY KEY (name, year))") ``` -------------------------------- ### Gremlin Graph Creation and Traversal Example Source: https://tinkerpop.apache.org/docs/3.8.1/recipes This snippet shows a basic Gremlin graph setup, including adding vertices and edges with properties. It then demonstrates a traversal starting from a specific vertex, filtering edges by tag, and projecting intermediate results using sacks. ```gremlin addE('rates').from('cindy').to('david').property('tag','ruby').property('value',7). addE('rates').from('david').to('eliza').property('tag','ruby').property('value',6). addE('rates').from('alice').to('eliza').property('tag','java').property('value',9).iterate() gremlin> g.withSack(1.0).V().has("name","alice"). repeat(outE("rates").has("tag","ruby"). project("a","b","c"). by(inV()). by(sack()). by("value").as("x"). select("a"). sack(mult).by(constant(0.5))). times(3).emit(). select(all, "x"). project("name","score"). by(tail(local, 1).unfold().select("a").values("name")), by(unfold(). sack(assign).by(select("b")), sack(mult).by(select("c")), sack().sum()) ``` -------------------------------- ### Install gperfutils Benchmarking Tools Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Use the :install command in the Gremlin Console to add gperfutils benchmarking and profiling tools. This is an alternative to manually managing dependencies. ```gremlin gremlin> :install org.gperfutils gbench ``` ```gremlin gremlin> :install org.gperfutils gprof ``` -------------------------------- ### Match Step Consistency - Initial Example Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Illustrates the initial behavior of the `match()` step where output might be unexpected without awareness of underlying optimizations. This example shows the output without explicit label selection. ```gremlin gremlin> g.V().match(__.as("a").out("knows").as("b")) ==>[a:v[1],b:v[2]] ==>[a:v[1],b:v[4]] gremlin> g.V().match(__.as("a").out("knows").as("b")).unfold() gremlin> g.V().match(__.as("a").out("knows").as("b")).identity() ==>[] ==>[] ``` -------------------------------- ### Start Gremlin Console Source: https://tinkerpop.apache.org/docs/3.8.1/tutorials/getting-started Unzip and start the Gremlin Console. Use `bin/gremlin.sh` on Unix-like systems or `bin/gremlin.bat` on Windows. ```bash $ unzip apache-tinkerpop-gremlin-console-3.8.1-bin.zip $ cd apache-tinkerpop-gremlin-console-3.8.1 $ bin/gremlin.sh ``` -------------------------------- ### Run GLV Examples Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Execute the script to compile and run all Gremlin Language Variant examples with the latest image and dependencies. ```bash bin/run-examples.sh ``` -------------------------------- ### Install and Use Neo4j Gremlin Plugin Source: https://tinkerpop.apache.org/docs/3.8.1/dev/provider These commands demonstrate how to install the Neo4j Gremlin plugin and activate it in the Gremlin Console. It shows the process of opening a Neo4j graph instance after the plugin is active. ```gremlin gremlin> :install org.apache.tinkerpop neo4j-gremlin 3.8.1 ``` ```gremlin gremlin> :plugin use tinkerpop.neo4j ``` ```gremlin gremlin> g = Neo4jGraph.open('/tmp/neo4j') ``` -------------------------------- ### Start Gremlin Server with Transactional Configuration Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Start the Gremlin Server using the provided transactional configuration file to enable remote transaction capabilities. ```bash bin/gremlin-server.sh conf/gremlin-server-transaction.yaml ``` -------------------------------- ### mergeV onCreate Validation Example Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Shows an example of mergeV syntax that allows the onCreate option to contain input that would override search criteria, which is now prevented by validation. ```gremlin g.mergeV([name: 'april']). option(Merge.onCreate, [name: 'bill']) ``` -------------------------------- ### Start Gremlin Server with Docker Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Start the Docker-based Gremlin Server for integration tests. The '-n' flag enables Neo4j for transaction-based tests. ```bash docker/gremlin-server.sh -n ``` -------------------------------- ### Build gremlin-go Module with Maven Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Compile and install the gremlin-go module using Maven. This command requires Go to be installed. ```bash mvn clean install -pl gremlin-go ``` -------------------------------- ### Start Gremlin Server with Docker Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Launch Gremlin Server using Docker with the standard test configuration. ```bash docker/gremlin-server.sh ``` -------------------------------- ### Auto-promotion of Numbers Example Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade This example demonstrates the auto-promotion of numbers in mathematical operations. Previously, this could lead to overflow exceptions or unexpected wrap-around behavior. The updated behavior ensures results are promoted to larger numeric types when necessary, preventing such issues. ```gremlin g.withSack(32767s).inject(1s).sack(sum).sack() ``` -------------------------------- ### Configure GLV Session in C# Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Example of configuring a Gremlin Language Variant (GLV) session in C#. ```csharp var gremlinServer = new GremlinServer("localhost", 8182); var client = new GremlinClient(gremlinServer, sessionId: Guid.NewGuid().ToString())) ``` -------------------------------- ### Get Help on a Specific Gremlin Console Command Source: https://tinkerpop.apache.org/docs/3.8.1/tutorials/the-gremlin-console To get detailed usage information for a specific command, append the command name to :help. For example, :help :remote provides details on the :remote command. ```groovy gremlin> :help :remote ``` ```groovy :help :remote ``` -------------------------------- ### GroupStep Migration Example Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Demonstrates migrating from the old `group()` methods to `groupV3d0()` for immediate upgrade, or to the new `group()` methods with updated syntax. ```gremlin group() ``` ```gremlin groupV3d0() ``` ```gremlin group().by('age').by(outE()).by(sum(local)) ``` ```gremlin group().by('age').by(outE().sum()) ``` -------------------------------- ### Build and Deploy SNAPSHOT Version Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Build the project and deploy the SNAPSHOT version to the repository. Ensure the project is built first to use the correct console version for documentation. ```bash mvn clean install -DskipTests ``` ```bash mvn deploy -DskipTests ``` -------------------------------- ### Get All Vertices with Gremlin Source: https://tinkerpop.apache.org/docs/3.8.1/tutorials/gremlins-anatomy The `g.V()` step is a common starting point for traversals, returning all vertices in the graph. The `g` variable represents a GraphTraversalSource. ```groovy gremlin> g.V() ==>v[1] ==>v[2] ==>v[3] ==>v[4] ==>v[5] ==>v[6] ``` ```groovy g.V() ``` -------------------------------- ### Get or Create Edge with coalesce() Source: https://tinkerpop.apache.org/docs/3.8.1/recipes Apply the `coalesce()` pattern to edges. This example checks for an existing 'created' edge between two vertices and creates it with a weight if it doesn't exist. ```groovy gremlin> g.V().has('person','name','vadas').as('v'). V().has('software','name','ripple'). coalesce(__.inE('created').where(outV().as('v')), addE('created').from('v').property('weight',0.5)) ``` ```groovy g.V().has('person','name','vadas').as('v'). V().has('software','name','ripple'). coalesce(__.inE('created').where(outV().as('v')), addE('created').from('v').property('weight',0.5)) ``` -------------------------------- ### Gremlin Server Default Serializers (GraphSON 3.0) Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Example configuration for Gremlin Server's `serializers` section, showing the default setup for GraphSON 3.0 with `application/json`. ```yaml serializers: - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3d0] }} # application/vnd.gremlin-v3.0+gryo - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v3.0+gryo-stringd - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV1d0] }} # application/json ``` -------------------------------- ### Build and Install Project with Integration Tests Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Execute this command to perform a full build including integration tests. Set '-DskipIntegrationTests=false' to enable integration tests and '-DincludeNeo4j' to include Neo4j integration tests. ```bash mvn clean install -DskipIntegrationTests=false -DincludeNeo4j ``` -------------------------------- ### Ad-hoc Analysis with Gremlin Source: https://tinkerpop.apache.org/docs/3.8.1/tutorials/the-gremlin-console Perform ad-hoc analysis by traversing and manipulating graph data. This example demonstrates finding the earliest start year and then generating a list of years for each person. ```groovy firstYear = g.V().hasLabel('person'). local(properties('location').values('startTime').min()). max().next() l = g.V().hasLabel('person').as('person'). properties('location').or(has('endTime',gt(firstYear)),hasNot('endTime')).as('location'). valueMap().as('times'). select('person','location','times').by('name').by(value).by().toList() l.collect{ row->((Math.max(row.times.startTime,firstYear))..((row.times.endTime?:2017)-1)).collect{ year->[person:row.person,location:row.location,year:year]}}.flatten() ``` -------------------------------- ### Propagate and Calculate Values with Sack in Gremlin Source: https://tinkerpop.apache.org/docs/3.8.1/recipes This example demonstrates using `sack()` to carry and manipulate values through a traversal. It initializes a sack with a starting amount, then iteratively multiplies it by edge factors to calculate amounts for subsequent vertices. ```gremlin g.addV('tank').property('name', 'a').property('amount', 100.0).as('a'). addV('tank').property('name', 'b').property('amount', 0.0).as('b'). addV('tank').property('name', 'c').property('amount', 0.0).as('c'). addE('drain').property('factor', 0.5).from('a').to('b'). addE('drain').property('factor', 0.1).from('b').to('c').iterate() ``` ```gremlin vA = g.V().has('name','a').next() ``` ```gremlin g.withSack(vA.value('amount')). V(vA).repeat(outE('drain').sack(mult).by('factor'). inV().property('amount', sack())). until(__.outE('drain').count().is(0)).iterate() ``` ```gremlin g.V().elementMap() ``` -------------------------------- ### GraphTraversalSource Configuration Examples Source: https://tinkerpop.apache.org/docs/3.8.1/tutorials/gremlins-anatomy Demonstrates how to configure a GraphTraversalSource with strategies, initial sack values, or GraphComputer for OLAP traversals. ```groovy g.withStrategies(SubgraphStrategy.build().vertices(hasLabel('person')).create()). //**1** V().has('name','marko').out().values('name') g.withSack(1.0f).V().sack() //**2** g.withComputer().V().pageRank() //**3** ``` -------------------------------- ### Create Graph and Find Shortest Path (OLTP) Source: https://tinkerpop.apache.org/docs/3.8.1/recipes This snippet first creates a sample graph with vertices and edges, then finds the shortest path between vertex '1' and vertex '5' using `repeat`, `simplePath`, and `limit`. It also shows how to count paths and group them by length. ```groovy gremlin> g.addV().property(id, 1).as('1'). addV().property(id, 2).as('2'). addV().property(id, 3).as('3'). addV().property(id, 4).as('4'). addV().property(id, 5).as('5'). addE('knows').from('1').to('2'). addE('knows').from('2').to('4'). addE('knows').from('4').to('5'). addE('knows').from('2').to('3'). addE('knows').from('3').to('4').iterate() gremlin> g.V(1).repeat(out().simplePath()).until(hasId(5)).path().limit(1) //// **(1)** ==>[v[1],v[2],v[4],v[5]] gremlin> g.V(1).repeat(out().simplePath()).until(hasId(5)).path().count(local) //// **(2)** ==>4 ==>5 gremlin> g.V(1).repeat(out().simplePath()).until(hasId(5)).path(). group().by(count(local)).next() //// **(3)** ==>4=[path[v[1], v[2], v[4], v[5]]] ==>5=[path[v[1], v[2], v[3], v[4], v[5]]] ``` ```groovy g.addV().property(id, 1).as('1'). addV().property(id, 2).as('2'). addV().property(id, 3).as('3'). addV().property(id, 4).as('4'). addV().property(id, 5).as('5'). addE('knows').from('1').to('2'). addE('knows').from('2').to('4'). addE('knows').from('4').to('5'). addE('knows').from('2').to('3'). addE('knows').from('3').to('4').iterate() g.V(1).repeat(out().simplePath()).until(hasId(5)).path().limit(1) //// **(1)** g.V(1).repeat(out().simplePath()).until(hasId(5)).path().count(local) //// **(2)** g.V(1).repeat(out().simplePath()).until(hasId(5)).path(). group().by(count(local)).next() //**3** ``` -------------------------------- ### GraphBinary Date Format Examples Source: https://tinkerpop.apache.org/docs/3.8.1/dev/io Examples of encoding Date values in GraphBinary, representing the Unix epoch and the moment just before it. ```plaintext 00 00 00 00 00 00 00 00: The moment in time 1970-01-01T00:00:00.000Z. ff ff ff ff ff ff ff ff: The moment in time 1969-12-31T23:59:59.999Z. ``` -------------------------------- ### GraphBinary 32-bit Integer Example (256) Source: https://tinkerpop.apache.org/docs/3.8.1/dev/io Example of a 32-bit integer representing the decimal number 256 in GraphBinary. ```plaintext 01 00 00 00 00 ff ``` -------------------------------- ### Process and Publish Documentation Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Process documentation, validate the SNAPSHOT documentation locally, and then publish it. Requires the project to be built first. ```bash bin/process-docs.sh ``` ```bash bin/publish-docs.sh ``` -------------------------------- ### String replace() and split() with Standard Steps Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Shows how to use the standard replace() and split() steps for string manipulation, replacing the need for closures in these cases. ```gremlin gremlin> g.V().hasLabel("software").values("name").replace("p", "g") ==>log ==>riggle ``` ```gremlin gremlin> g.V().hasLabel("person").values("name").split("a") ==>[m,rko] ==>[v,d,s] ==>[josh] ==>[peter] ``` -------------------------------- ### Install groovy-sql Plugin in Gremlin Server Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Use this command to install the groovy-sql dependency in Gremlin Server if your project relies on it. ```bash bin/gremlin-server.sh install org.codehaus.groovy groovy-sql 2.5.2 ``` -------------------------------- ### Install groovy-sql Plugin in Gremlin Console Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Use this command to install the groovy-sql dependency in the Gremlin Console if your project relies on it. ```groovy :install org.codehaus.groovy groovy-sql 2.5.2 ``` -------------------------------- ### Generate Local Website Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Navigate to the 'site' directory and run the script to generate the project website locally. ```bash cd site bin/generate-home.sh ``` -------------------------------- ### Publish Website Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Navigate to the 'site' directory and run the script to publish the project website, requiring a username. ```bash cd site bin/publish-home.sh ``` -------------------------------- ### Gremlin Prototyping with Unspecified Keys/Labels Source: https://tinkerpop.apache.org/docs/3.8.1/recipes Use these examples for initial graph exploration and prototyping when keys and labels are not yet critical. Be aware that this can lead to unexpected results if the schema changes. ```groovy gremlin> g.V().has("person","name","marko").out() ==>v[3] ==>v[2] ==>v[4] gremlin> g.V().has("person","name","marko").out("created").elementMap() ==>[id:3,label:software,name:lop,lang:java] gremlin> g.V().has("software","name","ripple").inE().has("weight", gte(0.5)).outV().properties() ==>vp[name->josh] ==>vp[age->32] ``` ```groovy g.V().has("person","name","marko").out() g.V().has("person","name","marko").out("created").elementMap() g.V().has("software","name","ripple").inE().has("weight", gte(0.5)).outV().properties() ``` -------------------------------- ### GraphBinary 64-bit Integer Format Examples Source: https://tinkerpop.apache.org/docs/3.8.1/dev/io Examples demonstrating the encoding of positive and negative values for 64-bit integers in GraphBinary. ```plaintext 00 00 00 00 00 00 00 01: 64-bit integer number 1. ff ff ff ff ff ff ff fe: 64-bit integer number -2. ``` -------------------------------- ### Gremlin Production Queries with Specified Keys/Labels Source: https://tinkerpop.apache.org/docs/3.8.1/recipes These examples demonstrate best practices for production code by explicitly defining keys and labels. This improves query readability and prevents breakage due to schema changes. ```groovy gremlin> g.V().has("person","name","marko").out("created","knows") ==>v[3] ==>v[2] ==>v[4] gremlin> g.V().has("person","name","marko").out("created").elementMap("name","lang") ==>[id:3,label:software,name:lop,lang:java] gremlin> g.V().has("software","name","ripple").inE("created").has("weight", gte(0.5)).outV(). properties("name","age") ==>vp[name->josh] ==>vp[age->32] ``` ```groovy g.V().has("person","name","marko").out("created","knows") g.V().has("person","name","marko").out("created").elementMap("name","lang") g.V().has("software","name","ripple").inE("created").has("weight", gte(0.5)).outV(). properties("name","age") ``` -------------------------------- ### Install gremlin-python Dependencies Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Install all gremlin-python dependencies using pip within a virtual environment. This command should be run from the 'gremlin-python/scr/main/python' directory. ```bash venv/bin/pip3 install -e . ``` -------------------------------- ### Branch Steps with Predicates and Traversals Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Demonstrates how branch steps now accept predicates and traversals, in addition to constant values and Pick tokens. This example shows grouping by name and then applying conditional logic based on age. ```gremlin gremlin> g = TinkerFactory.createModern().traversal() ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard] gremlin> g.V().hasLabel("person"). ......1> group(). ......2> by("name"). ......3> by(branch(values("age")). ......4> option(29, constant("almost old")), ......5> option(__.is(32), constant("looks like josh")), ......6> option(lt(29), constant("pretty young")), ......7> option(lt(35), constant("younger than peter")), ......8> option(gte(30), constant("pretty old")), ......9> option(none, constant("mysterious")).fold()). .....10> unfold() ==>peter=[pretty old] ==>vadas=[pretty young, younger than peter] ==>josh=[looks like josh, younger than peter, pretty old] ==>marko=[almost old, younger than peter] ``` -------------------------------- ### GraphBinary 32-bit Integer Format Examples Source: https://tinkerpop.apache.org/docs/3.8.1/dev/io Examples demonstrating the encoding of positive, negative, and zero values for 32-bit integers in GraphBinary. ```plaintext 00 00 00 01: 32-bit integer number 1. 00 00 01 01: 32-bit integer number 256. ff ff ff ff: 32-bit integer number -1. ff ff ff fe: 32-bit integer number -2. ``` -------------------------------- ### Mid-traversal E() Step Example Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade This example demonstrates the use of the E()-step in the middle of a traversal, allowing for conditional edge creation or retrieval. ```gremlin g.inject(1).coalesce(E().hasLabel("knows"), addE("knows").from(V().has("name","josh")).to(V().has("name","vadas"))) ``` -------------------------------- ### GraphBinary String Format Example Source: https://tinkerpop.apache.org/docs/3.8.1/dev/io Example of encoding the string 'abc' in GraphBinary, showing the length prefix followed by the UTF8 encoded text. ```plaintext 00 00 00 03 61 62 63: the string 'abc'. 00 00 00 04 61 62 63 64: the string 'abcd'. 00 00 00 00: the empty string ''. ``` -------------------------------- ### Build and Test with Docker Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Utilize Docker for simplifying the build and testing process. The '-t' flag builds images, '-i' runs integration tests, and '-n' includes Neo4j. ```bash docker/build.sh -t -i -n ``` -------------------------------- ### GraphBinary Null 32-bit Integer Example Source: https://tinkerpop.apache.org/docs/3.8.1/dev/io Example of a null value for a 32-bit integer in GraphBinary, using the type code and the null flag. ```plaintext 01 01 ``` -------------------------------- ### New String Steps: asString(), length(), toLower(), toUpper() Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Demonstrates the direct usage of the new string manipulation steps: asString(), length(), toLower(), and toUpper(). These steps provide a more concise way to perform these operations compared to using closures. ```gremlin gremlin> g.V().hasLabel("person").values("age").asString() ==>29 ==>27 ==>32 ==>35 gremlin> g.V().values("name").length() ==>5 ==>5 ==>3 ==>4 ==>6 ==>5 gremlin> g.inject("TO", "LoWeR", "cAsE").toLower() ==>to ==>lower ==>case gremlin> g.V().values("name").toUpper() ==>MARKO ==>VADAS ==>LOP ==>JOSH ==>RIPPLE ==>PETER ``` -------------------------------- ### Connect to Gremlin Server with Go Driver Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Demonstrates how to establish a connection to a Gremlin server using the Go driver, including configuration options and error handling. Ensure your Golang version is 1.20 or greater. ```go package main import ( "fmt" "github.com/apache/tinkerpop/gremlin-go/v3/driver" ) func main() { // Creating the connection to the server driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin", func(settings *gremlingo.DriverRemoteConnectionSettings) { // Configure optional settings settings.LogVerbosity = gremlingo.Info settings.InitialConcurrentConnections = 2 } ) // Handle error if err != nil { fmt.Println(err) return } // Cleanup defer driverRemoteConnection.Close() // Creating graph traversal g := gremlingo.Traversal_().WithRemote(driverRemoteConnection) // Perform traversal result, err := g.V().Count().ToList() if err != nil { fmt.Println(err) return } fmt.Println(result[0].GetString()) } ``` -------------------------------- ### Find Shortest Path by Edge Weight (OLTP) Source: https://tinkerpop.apache.org/docs/3.8.1/recipes This example extends the shortest path concept to consider edge weights. It first creates a graph with weighted edges, then demonstrates finding paths and calculating their total cost using different methods for mapping and summing edge weights. ```groovy gremlin> g.addV().property(id, 1).as('1'). addV().property(id, 2).as('2'). addV().property(id, 3).as('3'). addV().property(id, 4).as('4'). addV().property(id, 5).as('5'). addE('knows').from('1').to('2').property('weight', 1.25). addE('knows').from('2').to('4').property('weight', 1.5). addE('knows').from('4').to('5').property('weight', 0.25). addE('knows').from('2').to('3').property('weight', 0.25). addE('knows').from('3').to('4').property('weight', 0.25).iterate() gremlin> g.V(1).repeat(out().simplePath()).until(hasId(5)).path(). group().by(count(local)).next() //// **(1)** ==>4=[path[v[1], v[2], v[4], v[5]]] ==>5=[path[v[1], v[2], v[3], v[4], v[5]]] gremlin> g.V(1).repeat(outE().inV().simplePath()).until(hasId(5)). path().by(coalesce(values('weight'), constant(0.0))). map(unfold().sum()) //// **(2)** ==>3.00 ==>2.00 gremlin> g.V(1).repeat(outE().inV().simplePath()).until(hasId(5)). path().by(constant(0.0)).by('weight').map(unfold().sum()) //// **(3)** ==>3.00 ==>2.00 gremlin> g.V(1).repeat(outE().inV().simplePath()).until(hasId(5)). path().as('p'). map(unfold().coalesce(values('weight'), constant(0.0)).sum()).as('cost'). select('cost','p') //// **(4)** ==>[cost:3.00,p:[v[1],e[0][1-knows->2],v[2],e[1][2-knows->4],v[4],e[2][4-knows->5],v[5]]] ``` -------------------------------- ### Generate Test Coverage Report Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Generate a test coverage report by running 'mvn clean install -Dcoverage'. The 'install' phase is required for report aggregation. ```bash mvn clean install -Dcoverage ``` -------------------------------- ### Start Standalone Gremlin Server Source: https://tinkerpop.apache.org/docs/3.8.1/dev/developer Start a standalone Gremlin Server using the Docker script. This is useful for testing Gremlin Language Variants without Maven. ```bash ./docker/gremlin-server.sh ``` -------------------------------- ### Initialize Credential DSL in Java Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Use this approach to initialize the Credential DSL as a standard Java-based Gremlin DSL. Prefer this over the deprecated graph wrapping style. ```java CredentialTraversalSource credentials = graph.traversal(CredentialTraversalSource.class) credentials.user("stephen","password").iterate() credentials.users("stephen").valueMap().next() credentials.users().count().next() credentials.users("stephen").drop().iterate() ``` -------------------------------- ### Demonstrate Changed Infix Behavior for and() and or() Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Observe the simplified output of chained 'and()' and 'or()' steps using infix notation, which now supports an arbitrary number of traversals. ```gremlin Input: a.or.b.and.c.or.d.and.e.or.f.and.g.and.h.or.i *BEFORE* Output: or(a, or(and(b, c), or(and(d, e), or(and(and(f, g), h), i)))) *NOW* Output: or(a, and(b, c), and(d, e), and(f, g, h), i) ``` ```gremlin gremlin> g.V().has("name","marko").and().has("age", lt(30)).or().has("name","josh").and().has("age", gt(30)).and().out("created") ==>v[1] ==>v[4] ``` -------------------------------- ### Add Edge with Label Source: https://tinkerpop.apache.org/docs/3.8.1/dev/provider Adds an edge with a specified label. Can be used as a start or mid-traversal step. When used as a start step, both source and target must be specified using `from()` and `to()`. ```gremlin g.addE(edgeLabel) ``` -------------------------------- ### Construct Lambda Instance in Gremlin Console Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Example of constructing a `Lambda` instance in the Gremlin console. Note that this specific example encountered an error due to a Groovy version issue. ```groovy gremlin> org.apache.tinkerpop.gremlin.util.function.Lambda.function("{ it.get() }") (class: org/apache/tinkerpop/gremlin/util/function/Lambda$function, method: callStatic signature: (Ljava/lang/Class;[Ljava/lang/Object;)Ljava/lang/Object;) Illegal type in constant pool Type ':help' or ':h' for help. Display stack trace? [yN]n ``` -------------------------------- ### Java Implementation of SubgraphStrategy.create(Configuration) Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Demonstrates the Java implementation for creating a SubgraphStrategy from a Configuration object, allowing for dynamic strategy configuration. ```java public static SubgraphStrategy create(final Configuration configuration) { final Builder builder = SubgraphStrategy.build(); if (configuration.containsKey(VERTICES)) builder.vertices((Traversal) configuration.getProperty(VERTICES)); if (configuration.containsKey(EDGES)) builder.edges((Traversal) configuration.getProperty(EDGES)); if (configuration.containsKey(VERTEX_PROPERTIES)) builder.vertexProperties((Traversal) configuration.getProperty(VERTEX_PROPERTIES)); return builder.create(); } ``` -------------------------------- ### Explain Traversal with Default Barrier Injection Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade This example shows the traversal explanation when default barrier injection strategies are active. Observe the 'NoOpBarrierStep' instances added by LazyBarrierStrategy. ```gremlin gremlin> g.V().repeat(out()).times(2).in().explain() ==>Traversal Explanation ==================================================================================================================================================================================== Original Traversal [GraphStep(vertex,[]), RepeatStep([VertexStep(OUT,vertex), RepeatEndStep],until(loops(2)),emit(false)), VertexStep(IN,vertex)] ConnectiveStrategy [D] [GraphStep(vertex,[]), RepeatStep([VertexStep(OUT,vertex), RepeatEndStep],until(loops(2)),emit(false)), VertexStep(IN,vertex)] RepeatUnrollStrategy [O] [GraphStep(vertex,[]), VertexStep(OUT,vertex), VertexStep(OUT,vertex), VertexStep(IN,vertex)] IncidentToAdjacentStrategy [O] [GraphStep(vertex,[]), VertexStep(OUT,vertex), VertexStep(OUT,vertex), VertexStep(IN,vertex)] MatchPredicateStrategy [O] [GraphStep(vertex,[]), VertexStep(OUT,vertex), VertexStep(OUT,vertex), VertexStep(IN,vertex)] PathRetractionStrategy [O] [GraphStep(vertex,[]), VertexStep(OUT,vertex), VertexStep(OUT,vertex), VertexStep(IN,vertex)] FilterRankingStrategy [O] [GraphStep(vertex,[]), VertexStep(OUT,vertex), VertexStep(OUT,vertex), VertexStep(IN,vertex)] InlineFilterStrategy [O] [GraphStep(vertex,[]), VertexStep(OUT,vertex), VertexStep(OUT,vertex), VertexStep(IN,vertex)] AdjacentToIncidentStrategy [O] [GraphStep(vertex,[]), VertexStep(OUT,vertex), VertexStep(OUT,vertex), VertexStep(IN,vertex)] CountStrategy [O] [GraphStep(vertex,[]), VertexStep(OUT,vertex), VertexStep(OUT,vertex), VertexStep(IN,vertex)] EarlyLimitStrategy [O] [GraphStep(vertex,[]), VertexStep(OUT,vertex), VertexStep(OUT,vertex), VertexStep(IN,vertex)] LazyBarrierStrategy [O] [GraphStep(vertex,[]), VertexStep(OUT,vertex), NoOpBarrierStep(2500), VertexStep(OUT,vertex), NoOpBarrierStep(2500), VertexStep(IN,vertex)] TinkerGraphCountStrategy [P] [GraphStep(vertex,[]), VertexStep(OUT,vertex), NoOpBarrierStep(2500), VertexStep(OUT,vertex), NoOpBarrierStep(2500), VertexStep(IN,vertex)] TinkerGraphStepStrategy [P] [TinkerGraphStep(vertex,[]), VertexStep(OUT,vertex), NoOpBarrierStep(2500), VertexStep(OUT,vertex), NoOpBarrierStep(2500), VertexStep(IN,vertex)] ProfileStrategy [F] [TinkerGraphStep(vertex,[]), VertexStep(OUT,vertex), NoOpBarrierStep(2500), VertexStep(OUT,vertex), NoOpBarrierStep(2500), VertexStep(IN,vertex)] StandardVerificationStrategy [V] [TinkerGraphStep(vertex,[]), VertexStep(OUT,vertex), NoOpBarrierStep(2500), VertexStep(OUT,vertex), NoOpBarrierStep(2500), VertexStep(IN,vertex)] Final Traversal [TinkerGraphStep(vertex,[]), VertexStep(OUT,vertex), NoOpBarrierStep(2500), VertexStep(OUT,vertex), NoOpBarrierStep(2500), VertexStep(IN,vertex)] ``` -------------------------------- ### GraphBinary 64-bit Integer Example Source: https://tinkerpop.apache.org/docs/3.8.1/dev/io Example of a 64-bit integer representing the decimal number 1 in GraphBinary. It includes the type code, empty flags, and eight bytes for the value. ```plaintext 02 00 00 00 00 00 00 00 01 ``` -------------------------------- ### Using `withoutStrategies()` Source: https://tinkerpop.apache.org/docs/3.8.1/upgrade Shows the usage of the `withoutStrategies()` configuration step, which allows for fine-grained control over traversal execution by excluding specific strategies. ```gremlin g.V().withoutStrategies(CountStrategy) ``` -------------------------------- ### GraphBinary 32-bit Integer Example Source: https://tinkerpop.apache.org/docs/3.8.1/dev/io Example of a 32-bit integer representing the decimal number 1 in GraphBinary. It includes the type code, an empty flag, and four bytes for the value. ```plaintext 01 00 00 00 00 01 ```