You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/06/17 19:31:43 UTC

tinkerpop git commit: wow. awk hell -- got docuentation on 2-tuple bindings for Gremlin-Python out and got all the WARNINGS from awk script gone -- thanks @dkuppitz.

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1278 96c834b9f -> d4dde2632


wow. awk hell -- got docuentation on 2-tuple bindings for Gremlin-Python out and got all the WARNINGS from awk script gone  -- thanks @dkuppitz.


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

Branch: refs/heads/TINKERPOP-1278
Commit: d4dde263204fec4af645ab514bf7f805a3366d59
Parents: 96c834b
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Jun 17 13:31:39 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Jun 17 13:31:39 2016 -0600

----------------------------------------------------------------------
 docs/preprocessor/awk/init-code-blocks.awk      |  4 ++--
 docs/preprocessor/awk/language-variants.awk     |  3 ++-
 docs/preprocessor/awk/prepare.awk               |  4 ++--
 docs/preprocessor/awk/progressbar.awk           |  4 ++--
 docs/src/reference/gremlin-variants.asciidoc    | 22 ++++++++++++++++++--
 .../python/GremlinPythonGenerator.groovy        | 10 +++++++++
 6 files changed, 38 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d4dde263/docs/preprocessor/awk/init-code-blocks.awk
----------------------------------------------------------------------
diff --git a/docs/preprocessor/awk/init-code-blocks.awk b/docs/preprocessor/awk/init-code-blocks.awk
index d5a1de8..d9b9dc3 100644
--- a/docs/preprocessor/awk/init-code-blocks.awk
+++ b/docs/preprocessor/awk/init-code-blocks.awk
@@ -29,7 +29,7 @@ BEGIN {
 /^pb\([0-9]*\); '\[gremlin-/ {
   delimiter = 1
   split($0, a, "-")
-  b = gensub(/]'/, "", "", a[2])
+  b = gensub(/]'/, "", "g", a[2])
   split(b, c, ",")
   split(a[1], d, ";")
   lang = c[1]
@@ -101,7 +101,7 @@ BEGIN {
   if (delimiter == 2 && !($0 ~ /^pb\([0-9]*\); '----'/)) {
     switch (lang) {
       case "python":
-        print "groovy.eval jython.eval(\"\"\"" $0 "\"\"\").toString()"
+        print "groovy.eval jython.eval(\"\"\"" gensub("\\('id',([0-9]+)\\)", "\\1", "g") "\"\"\").toString()"
         break
       default:
         print

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d4dde263/docs/preprocessor/awk/language-variants.awk
----------------------------------------------------------------------
diff --git a/docs/preprocessor/awk/language-variants.awk b/docs/preprocessor/awk/language-variants.awk
index 1d69c48..9f9a6ee 100644
--- a/docs/preprocessor/awk/language-variants.awk
+++ b/docs/preprocessor/awk/language-variants.awk
@@ -39,7 +39,8 @@ BEGIN {
       case "python":
         gsub(/^gremlin>/, ">>>")
         gsub(/^==>/, "")
-        print gensub(/groovy.eval jython.eval\("""(.*)"""\).toString\(\)/, "\\1", 1)
+        $0 = gensub(/groovy.eval jython.eval\("""(.*)"""\).toString\(\)/, "\\1", 1)
+        print gensub("g\\.V\\(([^\\)]+)", "g.V(('id',\\1)", "g")
         break
       default:
         print

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d4dde263/docs/preprocessor/awk/prepare.awk
----------------------------------------------------------------------
diff --git a/docs/preprocessor/awk/prepare.awk b/docs/preprocessor/awk/prepare.awk
index 46960be..d880270 100644
--- a/docs/preprocessor/awk/prepare.awk
+++ b/docs/preprocessor/awk/prepare.awk
@@ -32,11 +32,11 @@ function print_string(string) {
 }
 
 function transform_callouts(code) {
-  return gensub(/\s*((<[0-9]+>\s*)*<[0-9]+>)\s*$/, " //// \\1", "", code)
+  return gensub(/\s*((<[0-9]+>\s*)*<[0-9]+>)\s*$/, " //// \\1", "g", code)
 }
 
 function remove_callouts(code) {
-  return gensub(/\s*((<[0-9]+>\s*)*<[0-9]+>)\s*$/, "", "", code)
+  return gensub(/\s*((<[0-9]+>\s*)*<[0-9]+>)\s*$/, "", "g", code)
 }
 
 /^----$/ {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d4dde263/docs/preprocessor/awk/progressbar.awk
----------------------------------------------------------------------
diff --git a/docs/preprocessor/awk/progressbar.awk b/docs/preprocessor/awk/progressbar.awk
index b927ba0..2a24d76 100644
--- a/docs/preprocessor/awk/progressbar.awk
+++ b/docs/preprocessor/awk/progressbar.awk
@@ -24,13 +24,13 @@ BEGIN {
 }
 
 /^pb\([0-9]*\); / {
-  max = gensub(/^pb\(([0-9]*)\); .*/, "\\1", "", $0)
+  max = gensub(/^pb\(([0-9]*)\); .*/, "\\1", "g", $0)
 }
 { content = content "\n" $0 }
 
 END {
   while ((getline line < tpl) > 0) {
-    print gensub(/TOTAL_LINES/, max, "", line)
+    print gensub(/TOTAL_LINES/, max, "g", line)
   }
   print content
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d4dde263/docs/src/reference/gremlin-variants.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc
index 8c6fd97..c375f8e 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -157,6 +157,24 @@ That is, without the `__.`-prefix.
 g.V().repeat(out()).times(2).name.fold()
 ----
 
+RemoteConnection Bindings
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+When a traversal script is sent to `RemoteConnection` (e.g. GremlinServer), it will be compiled and executed by the respective
+`ScriptEngine` accordingly. If the same traversal is sent again, it can simply be executed as the compiled version will typically
+be cached. Many traversals are unique up to some parameterization. For instance, `g.V(1).out('created').name` is considered different
+from `g.V(4).out('created').name'` as they are different scripts. However, `g.V(x).out('created').name` with bindings of `{x : 1}` and
+`{x : 4}` is the same. If a traversal is going to be run over and over again, but with different parameters, then bindings should be used.
+This can significantly speed up execution as compilation need only occur once. In Gremlin-Python, bindings are 2-tuples and used as follows.
+
+[gremlin-python,modern]
+----
+g.V(('id',1)).out('created').name
+g.V(('id',4)).out('created').name
+----
+
+In the two examples above, the remote compiler is only used once.
+
 Gremlin-Python Sugar
 ~~~~~~~~~~~~~~~~~~~~
 
@@ -192,8 +210,8 @@ below.
 >>> getsource(lambda traverser: len(traverser.get().values('name')))
 "lambda traverser: len(traverser.get().values('name'))\n"
 
-The important point is that the "lambda solution" is not universal and each `Translator` will specify have lambdas should be
-written in the lost language in order to be used effectively in the translated/execution language.
+IMPORTANT: The "lambda solution" is not universal in that each `Translator` will specify how lambdas should be
+used in the host language in order to be applied in the translated/execution language.
 
 RawExpressions in Gremlin-Python
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d4dde263/gremlin-variant/src/main/groovy/org/apache/tinkerpop/gremlin/python/GremlinPythonGenerator.groovy
----------------------------------------------------------------------
diff --git a/gremlin-variant/src/main/groovy/org/apache/tinkerpop/gremlin/python/GremlinPythonGenerator.groovy b/gremlin-variant/src/main/groovy/org/apache/tinkerpop/gremlin/python/GremlinPythonGenerator.groovy
index abc6fab..412edf2 100644
--- a/gremlin-variant/src/main/groovy/org/apache/tinkerpop/gremlin/python/GremlinPythonGenerator.groovy
+++ b/gremlin-variant/src/main/groovy/org/apache/tinkerpop/gremlin/python/GremlinPythonGenerator.groovy
@@ -109,6 +109,11 @@ globalTranslator = None
                             """  def ${method}(self, *args):
     traversal = PythonGraphTraversal(self.translator, self.remote_connection)
     traversal.translator.addSpawnStep(traversal, "${method}", *args)
+    for arg in args:
+      if isinstance(arg, tuple) and 2 == len(arg) and isinstance(arg[0], str):
+        self.bindings[arg[0]] = arg[1]
+      elif isinstance(arg, RawExpression):
+        self.bindings.update(arg.bindings)
     return traversal
 """)
                 } else if (TraversalSource.isAssignableFrom(returnType)) {
@@ -116,6 +121,11 @@ globalTranslator = None
                             """  def ${method}(self, *args):
     source = PythonGraphTraversalSource(self.translator, self.remote_connection)
     source.translator.addSource(source, "${method}", *args)
+    for arg in args:
+      if isinstance(arg, tuple) and 2 == len(arg) and isinstance(arg[0], str):
+        self.bindings[arg[0]] = arg[1]
+      elif isinstance(arg, RawExpression):
+        self.bindings.update(arg.bindings)
     return source
 """)
                 }