You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dk...@apache.org on 2015/06/05 20:46:55 UTC

[25/26] incubator-tinkerpop git commit: replaced static code blocks with dynamic code blocks

replaced static code blocks with dynamic code blocks


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/4487087f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/4487087f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/4487087f

Branch: refs/heads/preprocessor
Commit: 4487087fffb09eabe473603729023d0ce0a3a69a
Parents: d804444
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Fri Jun 5 20:45:14 2015 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri Jun 5 20:45:14 2015 +0200

----------------------------------------------------------------------
 docs/src/gremlin-applications.asciidoc | 111 +++++++++++-----------------
 docs/src/implementations.asciidoc      |  81 +++++---------------
 docs/src/the-graph.asciidoc            |  28 ++-----
 docs/src/the-traversal.asciidoc        |  14 ++--
 4 files changed, 76 insertions(+), 158 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4487087f/docs/src/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/gremlin-applications.asciidoc b/docs/src/gremlin-applications.asciidoc
index ea3742a..70b6113 100644
--- a/docs/src/gremlin-applications.asciidoc
+++ b/docs/src/gremlin-applications.asciidoc
@@ -123,29 +123,12 @@ In addition to the standard commands of the link:http://groovy.codehaus.org/Groo
 
 Gremlin Console adds a special `max-iteration` preference that can be configured with the standard `:set` command from the Groovy Shell.  Use this setting to control the maximum number of results that the Console will display. Consider the following usage:
 
-[source, groovy]
-----
-gremlin> :set max-iteration 10
-gremlin> (0..200)
-==>0
-==>1
-==>2
-==>3
-==>4
-==>5
-==>6
-==>7
-==>8
-==>9
-...
-gremlin> :set max-iteration 5
-gremlin> (0..200)
-==>0
-==>1
-==>2
-==>3
-==>4
-...
+[gremlin-groovy]
+----
+:set max-iteration 10
+(0..200)
+:set max-iteration 5
+(0..200)
 ----
 
 If this setting is not present, the console will default the maximum to 100 results.
@@ -276,60 +259,38 @@ gremlin>
 
 The console has the notion of a "remote", which represents a place a script will be sent from the console to be evaluated elsewhere in some other context (e.g. Gremlin Server, Hadoop, etc.).  To create a remote in the console, do the following:
 
-[source,groovy]
+[gremlin-groovy]
 ----
-gremlin> :remote connect tinkerpop.server conf/remote.yaml
-==>Connected - localhost/127.0.0.1:8182
+:remote connect tinkerpop.server conf/remote.yaml
 ----
 
 The `:remote` command shown above displays the current status of the remote connection.  This command can also be used to configure a new connection and change other related settings.  To actually send a script to the server a different command is required:
 
-[source,groovy]
+[gremlin-groovy]
 ----
-gremlin> :> g.V().values('name')
-==>marko
-==>vadas
-==>lop
-==>josh
-==>ripple
-==>peter
-gremlin> :> g.V().has('name','marko').out('created').values('name')
-==>lop
-gremlin> :> g.E().label().groupCount()
-==>{created=4, knows=2}
-gremlin> result
-==>result{object={created=4, knows=2} class=java.lang.String}
-gremlin> :remote close
-==>Removed - gremlin server - [localhost/127.0.0.1:8182]
+:> g.V().values('name')
+:> g.V().has('name','marko').out('created').values('name')
+:> g.E().label().groupCount()
+result
+:remote close
 ----
 
 The `:>` command, which is a shorthand for `:submit`, sends the script to the server to execute there.  Results are wrapped in an `Result` object which is a just a holder for each individual result.  The `class` shows the data type for the containing value.  Note that the last script sent was supposed to return a `Map`, but its `class` is `java.lang.String`.  By default, the connection is configured to only return text results.  In other words, Gremlin Server is using `toString` to serialize all results back to the console.  This enables virtually any object on the server to be returned to the console, but it doesn't allow the opportunity to work with this data in any way in the console itself.  A different configuration of the `:remote` is required to get the results back as "objects":
 
-[source,groovy]
+[gremlin-groovy]
 ----
-gremlin> :remote connect tinkerpop.server conf/remote-objects.yaml <1>
-==>connected - localhost/127.0.0.1:8182
-gremlin> :remote list <2>
-==>0 - Gremlin Server - [localhost/127.0.0.1:8182]
-==>*1 - Gremlin Server - [localhost/127.0.0.1:8182]
-gremlin> :> g.E().label().groupCount() <3>
-==>[created:4, knows:2]
-gremlin> m = result[0].object <4>
-==>created=4
-==>knows=2
-gremlin> m.sort{it.value}
-==>knows=2
-==>created=4
-gremlin> script = """
-                  matthias = graph.addVertex('name','matthias')
-                  matthias.addEdge('co-creator',g.V().has('name','marko').next())
-                  """
-gremlin> :> @script   <5>
-==>e[14][12-co-creator->1]
-gremlin> :> g.V().has('name','matthias').out('co-creator').values('name')
-==>marko
-gremlin> :remote close
-==>Removed - gremlin server - [localhost/127.0.0.1:8182]
+:remote connect tinkerpop.server conf/remote-objects.yaml <1>
+:remote list <2>
+:> g.E().label().groupCount() <3>
+m = result[0].object <4>
+m.sort {it.value}
+script = """
+         matthias = graph.addVertex('name','matthias')
+         matthias.addEdge('co-creator',g.V().has('name','marko').next())
+         """
+:> @script   <5>
+:> g.V().has('name','matthias').out('co-creator').values('name')
+:remote close
 ----
 
 <1> This configuration file specifies that results should be deserialized back into an `Object` in the console with the caveat being that the server and console both know how to serialize and deserialize the result to be returned.
@@ -960,8 +921,10 @@ image:gremlin-sugar.png[width=120,float=left] In previous versions of Gremlin-Gr
 IMPORTANT: It is important that the sugar plugin is loaded in a Gremlin Console session prior to any manipulations of the respective TinkerPop3 objects as Groovy will cache unavailable methods and properties.
 
 [source,groovy]
+----
 gremlin> :plugin use tinkerpop.sugar
 ==>tinkerpop.sugar activated
+----
 
 Graph Traversal Methods
 ^^^^^^^^^^^^^^^^^^^^^^^
@@ -969,6 +932,7 @@ Graph Traversal Methods
 If a `GraphTraversal` property is unknown and there is a corresponding method with said name off of `GraphTraversal` then the property is assumed to be a method call. This enables the user to omit `( )` from the method name. However, if the property does not reference a `GraphTraversal` method, then it is assumed to be a call to `values(property)`.
 
 [source,groovy]
+----
 gremlin> g.V ////<1>
 ==>v[1]
 ==>v[2]
@@ -990,6 +954,7 @@ gremlin> g.V.outE.weight ////<3>
 ==>1.0
 ==>0.4
 ==>0.2
+----
 
 <1> There is no need for the parentheses in `g.V()`.
 <2> The traversal is interpreted as `g.V().values('name')`.
@@ -1001,6 +966,7 @@ Range Queries
 The `[x]` and `[x..y]` range operators in Groovy translate to `RangeStep` calls.
 
 [source,groovy]
+----
 gremlin> g.V[0..2]
 ==>v[1]
 ==>v[2]
@@ -1008,6 +974,7 @@ gremlin> g.V[0..<2]
 ==>v[1]
 gremlin> g.V[2]
 ==>v[3]
+----
 
 Logical Operators
 ^^^^^^^^^^^^^^^^^
@@ -1015,6 +982,7 @@ Logical Operators
 The `&` and `|` operator are overloaded in `SugarGremlinPlugin`. When used, they introduce the `AndStep.AndMarker` and `OrStep.OrStep` markers into the traversal. See <<and-step,`and()`>> and <<or-step,`or()`>> for more information.
 
 [source,groovy]
+----
 gremlin> g.V.has(outE('knows') & outE('created')).name ////<1>
 ==>marko
 gremlin> t = g.V.has(outE('knows') | inE('created')).name; null ////<2>
@@ -1027,6 +995,7 @@ gremlin> t
 ==>ripple
 gremlin> t.toString()
 ==>[TinkerGraphStep(vertex), HasTraversalStep([OrStep([[VertexStep(OUT,[knows],edge)], [VertexStep(IN,[created],edge)]])]), PropertiesStep([name],value)]
+----
 
 <1> Introducing the `AndStep` with the `&` operator.
 <2> Introducing the `OrStep` with the `|` operator.
@@ -1037,11 +1006,12 @@ Comparators
 Unfortunately, Groovy does not support comparator overloading -- `>`, `<=`, `==`, etc. However, the `Compare` enums are available as methods in `SugarGremlinPlugin`.
 
 [source,groovy]
-gremlin> g.V.has(outE('created').count.gt(1) | __.age.lt(30)).name ////<1>
+----
+gremlin> g.V.has(outE('created').count.gt(1l) | __.age.lt(30)).name ////<1>
 ==>marko
 ==>vadas
 ==>josh
-gremlin> t = g.V.has(outE('created').count.gt(1) | __.age.lt(30) & outE('knows')).name; null ////<2>
+gremlin> t = g.V.has(outE('created').count.gt(1l) | __.age.lt(30) & outE('knows')).name; null ////<2>
 ==>null
 gremlin> t.toString()
 ==>[GraphStep(vertex), HasTraversalStep([VertexStep(OUT,[created],edge), CountStep, IsStep(gt,1), OrMarker, PropertiesStep([age],value), IsStep(lt,30), AndMarker, VertexStep(OUT,[knows],edge)]), PropertiesStep([name],value)]
@@ -1050,6 +1020,7 @@ gremlin> t
 ==>josh
 gremlin> t.toString()
 ==>[TinkerGraphStep(vertex), HasTraversalStep([OrStep([[VertexStep(OUT,[created],edge), CountStep, IsStep(gt,1)], [AndStep([[PropertiesStep([age],value), IsStep(lt,30)], [VertexStep(OUT,[knows],edge)]])]])]), PropertiesStep([name],value)]
+----
 
 <1> Using `gt(x)` in place of `is(gt,x)`.
 <2> A complex and/or chain with `IsStep` substitutions.
@@ -1060,6 +1031,9 @@ Traverser Methods
 It is rare that a user will ever interact with a `Traverser` directly. However, if they do, some method redirects exist to make it easy.
 
 [source,groovy]
+----
+
+
 gremlin> g.V().map{it.get().value('name')}  // conventional
 ==>marko
 ==>vadas
@@ -1074,6 +1048,7 @@ gremlin> g.V.map{it.name}  // sugar
 ==>josh
 ==>ripple
 ==>peter
+----
 
 [[utilities-plugin]]
 Utilities Plugin

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4487087f/docs/src/implementations.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/implementations.asciidoc b/docs/src/implementations.asciidoc
index 37f53ae..3c624e4 100644
--- a/docs/src/implementations.asciidoc
+++ b/docs/src/implementations.asciidoc
@@ -827,33 +827,16 @@ g.V().out().out().values('name')
 
 IMPORTANT: The examples above do not use lambdas (i.e. closures in Gremlin-Groovy). This makes the traversal serializable and thus, able to be distributed to all machines in the Hadoop cluster. If a lambda is required in a traversal, then the traversal must be sent as a `String` and compiled locally at each machine in the cluster. The following example demonstrates the `:remote` command which allows for submitting Gremlin traversals as a `String`.
 
-[source,text]
-gremlin> graph = GraphFactory.open('../../../hadoop-gremlin/conf/hadoop-gryo.properties')
-==>hadoopgraph[gryoinputformat->gryooutputformat]
-gremlin> :remote connect tinkerpop.hadoop graph
-==>useTraversalSource=graphtraversalsource[hadoopgraph[gryoinputformat->gryooutputformat], giraphgraphcomputer]
-==>useSugar=false
-gremlin> :> g.V().group().by{it.value('name')[1]}.by('name')
-INFO  org.apache.tinkerpop.gremlin.hadoop.process.computer.giraph.GiraphGraphComputer  - HadoopGremlin(Giraph): TraversalVertexProgram[GraphStep(vertex), GroupStep(lambda,value(name)), ComputerResultStep]
-INFO  org.apache.hadoop.mapred.JobClient  - Running job: job_201407281259_0039
-INFO  org.apache.hadoop.mapred.JobClient  -  map 0% reduce 0%
-...
-INFO  org.apache.tinkerpop.gremlin.hadoop.structure.HadoopGraph  - HadoopGremlin: GroupMapReduce[~reducing]
-INFO  org.apache.hadoop.mapred.JobClient  - Running job: job_201407281259_0040
-INFO  org.apache.hadoop.mapred.JobClient  -  map 0% reduce 0%
-...
-==>[a:[marko, vadas], e:[peter], i:[ripple], o:[lop, josh]]
-gremlin> result
-==>result[hadoopgraph[gryoinputformat->gryooutputformat],memory[size:1]]
-gremlin> result.memory.runtime
-==>20356
-gremlin> result.memory.keys()
-==>~reducing
-gremlin> result.memory.get('~reducing')
-==>a={marko=1, vadas=1}
-==>e={peter=1}
-==>i={ripple=1}
-==>o={lop=1, josh=1}
+[gremlin-groovy]
+----
+graph = GraphFactory.open('conf/hadoop/hadoop-gryo.properties')
+:remote connect tinkerpop.hadoop graph
+:> g.V().group().by{it.value('name')[1]}.by('name')
+result
+result.memory.runtime
+result.memory.keys()
+result.memory.get('~reducing')
+----
 
 [[sparkgraphcomputer]]
 SparkGraphComputer
@@ -871,17 +854,6 @@ g.V().out().out().values('name')
 
 For using lambdas in Gremlin-Groovy, simply provide `:remote connect` a `TraversalSource` which leverages SparkGraphComputer.
 
-[source,test]
-gremlin> graph = GraphFactory.open('../../../hadoop-gremlin/conf/hadoop-gryo.properties')
-==>hadoopgraph[gryoinputformat->gryooutputformat]
-gremlin> g = graph.traversal(computer(SparkGraphComputer))
-==>graphtraversalsource[hadoopgraph[gryoinputformat->gryooutputformat], sparkgraphcomputer]
-gremlin> :remote connect tinkerpop.hadoop graph g
-==>useTraversalSource=graphtraversalsource[hadoopgraph[gryoinputformat->gryooutputformat], sparkgraphcomputer]
-==>useSugar=false
-gremlin> :> g.V().group().by{it.value('name')[1]}.by('name')
-==>[a:[marko, vadas], e:[peter], i:[ripple], o:[lop, josh]]
-
 [gremlin-groovy]
 ----
 graph = GraphFactory.open('conf/hadoop/hadoop-gryo.properties')
@@ -1026,29 +998,16 @@ Interacting with HDFS
 
 The distributed file system of Hadoop is called link:http://en.wikipedia.org/wiki/Apache_Hadoop#Hadoop_distributed_file_system[HDFS]. The results of any OLAP operation are stored in HDFS accessible via `hdfs`.
 
-[source,text]
-gremlin> :remote connect tinkerpop.hadoop ../../../hadoop-gremlin/conf/hadoop-gryo.properties
-==>hadoopgraph[gryoinputformat->gryooutputformat]
-gremlin> :> g.V().group().by{it.value('name')[1]}.by('name')
-...
-==>[a:[marko, vadas], e:[peter], i:[ripple], o:[lop, josh]]
-gremlin> hdfs.ls()
-==>rwxr-xr-x marko supergroup 0 (D) output
-==>rw-r--r-- marko supergroup 1439 tinkerpop-modern-vertices.kryo
-gremlin> hdfs.ls('output')
-==>rwxr-xr-x marko supergroup 0 (D) a
-gremlin> hdfs.ls('output/a')
-==>rw-r--r-- marko supergroup 0 _SUCCESS
-==>rwxr-xr-x marko supergroup 0 (D) _logs
-==>rw-r--r-- marko supergroup 140 part-r-00000
-==>rw-r--r-- marko supergroup 1109 part-r-00001
-==>rw-r--r-- marko supergroup 140 part-r-00002
-==>rw-r--r-- marko supergroup 468 part-r-00003
-gremlin> hdfs.head('output/a',ObjectWritable.class)
-==>a	{marko=1, vadas=1}
-==>e	{peter=1}
-==>i	{ripple=1}
-==>o	{lop=1, josh=1}
+[gremlin-groovy]
+----
+graph = GraphFactory.open('conf/hadoop/hadoop-gryo.properties')
+:remote connect tinkerpop.hadoop graph
+:> g.V().group().by{it.value('name')[1]}.by('name')
+hdfs.ls()
+hdfs.ls('output')
+hdfs.ls('output/a')
+hdfs.head('output/a',ObjectWritable.class)
+----
 
 A list of the HDFS methods available are itemized below. Note that these methods are also available for the 'local' variable:
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4487087f/docs/src/the-graph.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/the-graph.asciidoc b/docs/src/the-graph.asciidoc
index a7e86d2..8c5cbc9 100644
--- a/docs/src/the-graph.asciidoc
+++ b/docs/src/the-graph.asciidoc
@@ -30,22 +30,10 @@ A `Feature` implementation describes the capabilities of a `Graph` instance. Thi
 
 The following example in the Gremlin Console shows how to print all the features of a `Graph`:
 
-[source,groovy]
+[gremlin-groovy]
 ----
-gremlin> graph = TinkerGraph.open()
-==>tinkergraph[vertices:0 edges:0]
-gremlin> graph.features()
-==>FEATURES
-> GraphFeatures
->-- Persistence: false
->-- ThreadedTransactions: false
->-- Computer: true
->-- Transactions: false
-> VariableFeatures
->-- Variables: true
->-- IntegerArrayValues: true
->-- BooleanValues: true
-...
+graph = TinkerGraph.open()
+graph.features()
 ----
 
 A common pattern for using features is to check their support prior to performing an operation:
@@ -227,12 +215,12 @@ gremlin> graph.tx().commit()
 
 The `Transaction` object also exposes a method for executing automatic transaction retries:
 
-[source,groovy]
+[gremlin-groovy]
 ----
-gremlin> graph.tx().submit {it.addVertex("name","josh")}.retry(10)
-==>v[2]
-gremlin> graph.tx().submit {it.addVertex("name","daniel")}.exponentialBackoff(10)
-==>v[3]
+graph = Neo4jGraph.open('/tmp/neo4j')
+graph.tx().submit {it.addVertex("name","josh")}.retry(10)
+graph.tx().submit {it.addVertex("name","daniel")}.exponentialBackoff(10)
+graph.close()
 ----
 
 As shown above, the `submit` method takes a `Function<Graph, R>` which is the unit of work to execute and possibly retry on failure.  The method returns a `Transaction.Workload` object which has a number of default methods for common retry strategies.  It is also possible to supply a custom retry function if a default one does not suit the required purpose.

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4487087f/docs/src/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/the-traversal.asciidoc b/docs/src/the-traversal.asciidoc
index 2ec129d..ca573a9 100644
--- a/docs/src/the-traversal.asciidoc
+++ b/docs/src/the-traversal.asciidoc
@@ -1676,16 +1676,12 @@ g.V('42a')
 
 Other `Graph` implementations, such as Neo4j, generate element identifiers automatically and cannot be assigned.  As a helper, `ElementIdStrategy` can be used to make identifier assignment possible by using vertex and edge indicies under the hood.
 
-[source,groovy]
+[gremlin-groovy]
 ----
-gremlin> graph = Neo4jGraph.open('/tmp/neo4j')
-==>neo4jgraph[EmbeddedGraphDatabase [/tmp/neo4j]]
-gremlin> strategy = ElementIdStrategy.build().create()
-==>ElementIdStrategy
-gremlin> g = GraphTraversalSource.build().with(strategy).create(graph)
-==>graphtraversalsource[neo4jgraph[EmbeddedGraphDatabase [/tmp/neo4j]], standard]
-gremlin> g.addV(id, '42a').id()
-==>42a
+graph = Neo4jGraph.open('/tmp/neo4j')
+strategy = ElementIdStrategy.build().create()
+g = GraphTraversalSource.build().with(strategy).create(graph)
+g.addV(id, '42a').id()
 ----
 
 IMPORTANT: The key that is used to store the assigned identifier should be indexed in the underlying graph database. If it is not indexed, then lookups for the elements that use these identifiers will perform a linear scan.