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

[tinkerpop] branch TINKERPOP-2020 created (now 30ce71a)

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a change to branch TINKERPOP-2020
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git.


      at 30ce71a  TINKERPOP-2020 Added withComputer() in javascript.

This branch includes the following new commits:

     new 30ce71a  TINKERPOP-2020 Added withComputer() in javascript.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[tinkerpop] 01/01: TINKERPOP-2020 Added withComputer() in javascript.

Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch TINKERPOP-2020
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 30ce71a38c4aaefbba64f5d063ee2f0db05586ed
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Thu Jun 27 16:08:17 2019 -0400

    TINKERPOP-2020 Added withComputer() in javascript.
---
 CHANGELOG.asciidoc                                 |  1 +
 docs/src/upgrade/release-3.3.x.asciidoc            |  8 +++++++
 .../glv/GraphTraversalSource.template              | 16 ++++++++++++-
 .../lib/process/graph-traversal.js                 | 16 ++++++++++++-
 .../lib/process/traversal-strategy.js              | 28 +++++++++++++++++++++-
 .../lib/structure/io/graph-serializer.js           |  2 ++
 .../lib/structure/io/type-serializers.js           | 16 +++++++++++++
 .../test/cucumber/feature-steps.js                 | 13 ----------
 8 files changed, 84 insertions(+), 16 deletions(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 88e8a44..151b06d 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 [[release-3-3-8]]
 === TinkerPop 3.3.8 (Release Date: NOT OFFICIALLY RELEASED YET)
 
+* Provided support for `withComputer()` in gremlin-javascript.
 * Bump to Groovy 2.4.17.
 * Bump to Jackson 2.9.9.
 * Improved error messaging when an attempt is made to serialize multi-properties to GraphML.
diff --git a/docs/src/upgrade/release-3.3.x.asciidoc b/docs/src/upgrade/release-3.3.x.asciidoc
index 51da497..26de75f 100644
--- a/docs/src/upgrade/release-3.3.x.asciidoc
+++ b/docs/src/upgrade/release-3.3.x.asciidoc
@@ -27,6 +27,14 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 
 Please see the link:https://github.com/apache/tinkerpop/blob/3.3.8/CHANGELOG.asciidoc#release-3-3-8[changelog] for a complete list of all the modifications that are part of this release.
 
+== Upgrading for Users
+
+==== JavaScript withComputer()
+
+Gremlin-Javascript now supports `withComputer()` syntax, which means that it is now possible in Javascript to utilize
+Gremlin steps that require a `GraphComputer` to execute (e.g. `pageRank()` and `peerPressure()`).
+
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-2251[TINKERPOP-2251]
 
 == TinkerPop 3.3.7
 
diff --git a/gremlin-javascript/glv/GraphTraversalSource.template b/gremlin-javascript/glv/GraphTraversalSource.template
index 9f94828..a684693 100644
--- a/gremlin-javascript/glv/GraphTraversalSource.template
+++ b/gremlin-javascript/glv/GraphTraversalSource.template
@@ -26,7 +26,7 @@ const { Traversal } = require('./traversal');
 const remote = require('../driver/remote-connection');
 const utils = require('../utils');
 const Bytecode = require('./bytecode');
-const { TraversalStrategies } = require('./traversal-strategy');
+const { TraversalStrategies, VertexProgramStrategy } = require('./traversal-strategy');
 
 
 /**
@@ -61,6 +61,20 @@ class GraphTraversalSource {
   }
 
   /**
+   * @param graphComputer
+   * @param workers
+   * @param result
+   * @param persist
+   * @param vertices
+   * @param edges
+   * @param configuration
+   * @returns {GraphTraversalSource}
+   */
+  withComputer(graphComputer, workers, result, persist, vertices, edges, configuration) {
+    return this.withStrategies(new VertexProgramStrategy(graphComputer, workers, result, persist, vertices, edges, configuration));
+  }
+
+  /**
    * Returns the string representation of the GraphTraversalSource.
    * @returns {string}
    */
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/graph-traversal.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/graph-traversal.js
index 34e06db..6e61bdf 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/graph-traversal.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/graph-traversal.js
@@ -26,7 +26,7 @@ const { Traversal } = require('./traversal');
 const remote = require('../driver/remote-connection');
 const utils = require('../utils');
 const Bytecode = require('./bytecode');
-const { TraversalStrategies } = require('./traversal-strategy');
+const { TraversalStrategies, VertexProgramStrategy } = require('./traversal-strategy');
 
 
 /**
@@ -61,6 +61,20 @@ class GraphTraversalSource {
   }
 
   /**
+   * @param graphComputer
+   * @param workers
+   * @param result
+   * @param persist
+   * @param vertices
+   * @param edges
+   * @param configuration
+   * @returns {GraphTraversalSource}
+   */
+  withComputer(graphComputer, workers, result, persist, vertices, edges, configuration) {
+    return this.withStrategies(new VertexProgramStrategy(graphComputer, workers, result, persist, vertices, edges, configuration));
+  }
+
+  /**
    * Returns the string representation of the GraphTraversalSource.
    * @returns {string}
    */
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal-strategy.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal-strategy.js
index 1037f57..98723df 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal-strategy.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal-strategy.js
@@ -59,6 +59,7 @@ class TraversalStrategies {
 
 /** @abstract */
 class TraversalStrategy {
+
   /**
    * @abstract
    * @param {Traversal} traversal
@@ -69,7 +70,32 @@ class TraversalStrategy {
   }
 }
 
+class VertexProgramStrategy extends TraversalStrategy {
+
+  constructor(graphComputer, workers, persist, result, vertices, edges, configuration) {
+    super();
+    this.configuration = new Map();
+    if (graphComputer !== undefined)
+      this.configuration.set("graphComputer", graphComputer);
+    if (graphComputer !== undefined)
+      this.configuration.set("workers", workers);
+    if (graphComputer !== undefined)
+      this.configuration.set("persist", persist);
+    if (graphComputer !== undefined)
+      this.configuration.set("result", result);
+    if (graphComputer !== undefined)
+      this.configuration.set("vertices", vertices);
+    if (graphComputer !== undefined)
+      this.configuration.set("edges", edges);
+    if (configuration !== undefined)
+      configuration.forEach(function(k,v) {
+        this.configuration.set(k, v);
+      });
+  }
+}
+
 module.exports = {
   TraversalStrategies: TraversalStrategies,
-  TraversalStrategy: TraversalStrategy
+  TraversalStrategy: TraversalStrategy,
+  VertexProgramStrategy: VertexProgramStrategy
 };
\ No newline at end of file
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js
index 94386df..4a7fdf2 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js
@@ -157,6 +157,7 @@ class GraphSONReader {
 
 const deserializers = {
   'g:Traverser': typeSerializers.TraverserSerializer,
+  'g:TraversalStrategy': typeSerializers.TraversalStrategySerializer,
   'g:Int32':  typeSerializers.NumberSerializer,
   'g:Int64':  typeSerializers.NumberSerializer,
   'g:Float':  typeSerializers.NumberSerializer,
@@ -178,6 +179,7 @@ const serializers = [
   typeSerializers.DateSerializer,
   typeSerializers.BytecodeSerializer,
   typeSerializers.TraverserSerializer,
+  typeSerializers.TraversalStrategySerializer,
   typeSerializers.PSerializer,
   typeSerializers.LambdaSerializer,
   typeSerializers.EnumSerializer,
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js
index fc78c0c..c553b47 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/type-serializers.js
@@ -23,6 +23,7 @@
 'use strict';
 
 const t = require('../../process/traversal');
+const ts = require('../../process/traversal-strategy');
 const Bytecode = require('../../process/bytecode');
 const g = require('../graph');
 const utils = require('../../utils');
@@ -230,6 +231,20 @@ class TraverserSerializer extends TypeSerializer {
   }
 }
 
+class TraversalStrategySerializer extends TypeSerializer {
+  /** @param {TraversalStrategy} item */
+  serialize(item) {
+    return {
+      [typeKey]: 'g:' + item.constructor.name,
+      [valueKey]: item.configuration
+    };
+  }
+
+  canBeUsedFor(value) {
+    return (value instanceof ts.TraversalStrategy);
+  }
+}
+
 class VertexSerializer extends TypeSerializer {
   deserialize(obj) {
     const value = obj[valueKey];
@@ -413,6 +428,7 @@ module.exports = {
   SetSerializer,
   TSerializer,
   TraverserSerializer,
+  TraversalStrategySerializer,
   typeKey,
   valueKey,
   VertexPropertySerializer,
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js
index 9bf9977..651a6ea 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js
@@ -57,24 +57,11 @@ const parsers = [
 
 const ignoreReason = {
   lambdaNotSupported: 'Lambdas are not supported on gremlin-javascript',
-  computerNotSupported: "withComputer() is not supported on gremlin-javascript",
   needsFurtherInvestigation: '',
 };
 
 const ignoredScenarios = {
   // An associative array containing the scenario name as key, for example:
-  'g_V_pageRank_hasXpageRankX': new IgnoreError(ignoreReason.computerNotSupported),
-  'g_V_outXcreatedX_pageRank_byXbothEX_byXprojectRankX_timesX0X_valueMapXname_projectRankX': new IgnoreError(ignoreReason.computerNotSupported),
-  'g_V_pageRank_order_byXpageRank_decrX_byXnameX_name': new IgnoreError(ignoreReason.computerNotSupported),
-  'g_V_pageRank_order_byXpageRank_decrX_name_limitX2X': new IgnoreError(ignoreReason.computerNotSupported),
-  'g_V_pageRank_byXoutEXknowsXX_byXfriendRankX_project_byXnameX_byXvaluesXfriendRankX_mathX': new IgnoreError(ignoreReason.computerNotSupported),
-  'g_V_hasLabelXpersonX_pageRank_byXpageRankX_project_byXnameX_byXvaluesXpageRankX_mathX': new IgnoreError(ignoreReason.computerNotSupported),
-  'g_V_pageRank_byXpageRankX_asXaX_outXknowsX_pageRank_asXbX_selectXa_bX_by_byXmathX': new IgnoreError(ignoreReason.computerNotSupported),
-  'g_V_hasLabelXsoftwareX_hasXname_rippleX_pageRankX1X_byXinEXcreatedXX_timesX1X_byXpriorsX_inXcreatedX_unionXboth__identityX_valueMapXname_priorsX': new IgnoreError(ignoreReason.computerNotSupported),
-  'g_V_outXcreatedX_groupXmX_byXlabelX_pageRankX1X_byXpageRankX_byXinEX_timesX1X_inXcreatedX_groupXmX_byXpageRankX_capXmX': new IgnoreError(ignoreReason.computerNotSupported),
-  'g_V_peerPressure_hasXclusterX': new IgnoreError(ignoreReason.computerNotSupported),
-  'g_V_peerPressure_byXclusterX_byXoutEXknowsXX_pageRankX1X_byXrankX_byXoutEXknowsXX_timesX2X_group_byXclusterX_byXrank_sumX_limitX100X': new IgnoreError(ignoreReason.computerNotSupported),
-  'g_V_hasXname_rippleX_inXcreatedX_peerPressure_byXoutEX_byXclusterX_repeatXunionXidentity__bothX_timesX2X_dedup_valueMapXname_clusterX': new IgnoreError(ignoreReason.computerNotSupported),
   'g_withSideEffectXa_setX_V_both_name_storeXaX_capXaX': new IgnoreError(ignoreReason.needsFurtherInvestigation),
   'g_V_both_groupCountXaX_out_capXaX_selectXkeysX_unfold_both_groupCountXaX_capXaX': new IgnoreError(ignoreReason.needsFurtherInvestigation),
   'g_V_group_byXoutE_countX_byXnameX': new IgnoreError(ignoreReason.needsFurtherInvestigation),