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 2021/09/02 15:19:25 UTC
[tinkerpop] branch TINKERPOP-2605 updated (9de6b77 -> 4fec952)
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a change to branch TINKERPOP-2605
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git.
discard 9de6b77 TINKERPOP-2605 Fixed issues with null and inject()
discard 35592fb TINKERPOP-2605 Improved null handling in reducing math steps.
discard 9d120d1 TINKERPOP-2605 Added test for where() evaluated null equality
discard 84b51d4 TINKERPOP-2598 Addressed NullPointerException with P.within/out
discard b106785 TINKERPOP-2605 Added test for select() where by() produces null
discard f32f138 TINKERPOP-2605 Added project() test where by() returns null
discard deae874 TINKERPOP-2605 Added tests for path() where by() can produce null
discard 2f0a746 TINKERPOP-2605 Added test to validate dedup() grabbing the first item it encounters
discard 6dfcd34 TINKERPOP-2605 Added test/docs for order() when the by() produces null
discard 5d01cbf TINKERPOP-2605 hasLabel(null) filters results
omit e32822e Fixed io() processing in grammar
omit df17e8a Merge branch 'TINKERPOP-2585' into 3.5-dev
omit 6eec9a6 Merge branch 'TINKERPOP-2582' into 3.5-dev
omit e9bb610 TINKERPOP-2585 Strategies were being applied when unecessary
omit 26fe180 TINKERPOP-2585 Adjust strategy order for InlineFilterStrategy
omit b86569c TINKERPOP-2582 Construct traversals from gremlin-language
omit a381669 Merge branch 'dependabot/nuget/gremlin-dotnet/3.5-dev/gherkin-20.0.1' into 3.5-dev
omit 4d0af6b Added 3.5.2 io test files CTR
omit 347a8df Merge branch '3.4-dev' into 3.5-dev
omit 6cfc4aa Merge branch '3.4-dev' into 3.5-dev
omit ac46d92 TINKERPOP-2592 Pointed recipes style guide at gremlint style guide CTR
omit bcaaa08 Added gremlint and .NET templates to release announcment email template CTR
omit 2d7acdc TINKERPOP-2593 Deprecated JsonBuilder serialization CTR
omit 0c964d2 Updated versioning section of dev docs
omit a3805bc TINKERPOP-2504 retry start of kdc server
omit 3a64856 Minor dev doc updates given latest release CTR
omit 586619a Added gremlint release to npm to 3.5.1 upgrade docs.
omit e1d25fe Minor link fix in upgrade docs CTR
omit 2a0fb3a Merge branch '3.4-dev' into 3.5-dev
omit a5fc2f1 Merge branch 'release-lessons-learned-3.5-dev' into 3.5-dev
omit 5558945 Merge branch 'release-lessons-learned' into release-lessons-learned-3.5-dev
omit 9b8c053 Add gremlint to more places for releases
omit a424f4e Bump to 3.5.2-SNAPSHOT
omit b7eb437 Merge branch 'release-lessons-learned' into release-lessons-learned-3.5-dev
omit 322c666 Merge branch '3.4-dev' into 3.5-dev
omit 24673e7 Bump gherkin from 19.0.3 to 20.0.1 in /gremlin-dotnet
add c2397d2 Clarified docs around the default certs installed if a TrustManager isn't specified to the gremlin-driver CTR
add 610a18b TINKERPOP-2603 Added docs around data types in TinkerGraph CTR
add b66532b Merge branch '3.4-dev' into 3.5-dev-rebuild
add 4f09143 Bump to 3.5.2-SNAPSHOT
add 738ed56 Add gremlint to more places for releases
add b40924b Minor link fix in upgrade docs CTR
add f3ce3e7 Added gremlint release to npm to 3.5.1 upgrade docs.
add c7283f9 Minor dev doc updates given latest release CTR
add 0d06b65 TINKERPOP-2504 retry start of kdc server
add 84040ea Updated versioning section of dev docs
add 8e96ab5 TINKERPOP-2593 Deprecated JsonBuilder serialization CTR
add e564e21 Added gremlint and .NET templates to release announcment email template CTR
add 3eb3945 TINKERPOP-2592 Pointed recipes style guide at gremlint style guide CTR
add c2ff8fc Added 3.5.2 io test files CTR
add f6a13f7 TINKERPOP-2582 Construct traversals from gremlin-language
add 8759b5f TINKERPOP-2585 Adjust strategy order for InlineFilterStrategy
add eb3225f TINKERPOP-2585 Strategies were being applied when unecessary
add 1eec3e8 Fixed io() processing in grammar
add 9d378f1 Removed all references to store() in docs in favor of aggregate(local) CTR
add ecac064 Make administrative adjustments to gremlint site
add 6082d4b Updated the list of ByModulating steps in traversal docs CTR
add 6ebe798 Merge branch '3.4-dev' into 3.5-dev
add 2ba661b Improved documentation around hasKey() and hasValue() CTR
add 5519880 Merge branch '3.4-dev' into 3.5-dev
new 086f7fa TINKERPOP-2605 hasLabel(null) filters results
new 2838d79 TINKERPOP-2605 Added test/docs for order() when the by() produces null
new e9329eb TINKERPOP-2605 Added test to validate dedup() grabbing the first item it encounters
new c159c53 TINKERPOP-2605 Added tests for path() where by() can produce null
new 3ca209a TINKERPOP-2605 Added project() test where by() returns null
new 24c70cf TINKERPOP-2605 Added test for select() where by() produces null
new a0d4b30 TINKERPOP-2598 Addressed NullPointerException with P.within/out
new 5f77ae4 TINKERPOP-2605 Added test for where() evaluated null equality
new 89119c3 TINKERPOP-2605 Improved null handling in reducing math steps.
new 4fec952 TINKERPOP-2605 Fixed issues with null and inject()
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (9de6b77)
\
N -- N -- N refs/heads/TINKERPOP-2605 (4fec952)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 10 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.
Summary of changes:
.../{src/router.ts => config-overrides.js} | 13 ++--
docs/gremlint/package-lock.json | 79 ++++++++++++++++++++--
docs/gremlint/package.json | 8 ++-
docs/gremlint/src/App.tsx | 22 +++---
.../{Spacer.ts => CenteredContainer.tsx} | 7 +-
.../src/components/{Paragraph.tsx => Footer.tsx} | 33 +++++----
docs/gremlint/src/components/Navigator.tsx | 10 +--
docs/gremlint/src/components/StyleGuideRule.tsx | 2 -
.../src/components/{FadeIn.tsx => View.tsx} | 29 ++++----
docs/gremlint/src/views/StyleGuide/index.tsx | 10 ++-
docs/src/recipes/appendix.asciidoc | 2 +-
docs/src/recipes/centrality.asciidoc | 4 +-
docs/src/recipes/collections.asciidoc | 43 ++++++------
docs/src/recipes/connected-components.asciidoc | 10 +--
docs/src/recipes/shortest-path.asciidoc | 2 +-
docs/src/reference/gremlin-applications.asciidoc | 2 +-
docs/src/reference/gremlin-variants.asciidoc | 12 ++--
.../reference/implementations-tinkergraph.asciidoc | 27 ++++++++
docs/src/reference/the-traversal.asciidoc | 33 ++++-----
gremlin-console/pom.xml | 21 ------
.../traversal/dsl/graph/GraphTraversal.java | 16 +++--
.../Gremlin.Net.IntegrationTest.csproj | 2 +-
.../apache/tinkerpop/gremlin/driver/Cluster.java | 3 +-
gremlin-server/pom.xml | 21 ------
24 files changed, 237 insertions(+), 174 deletions(-)
copy docs/gremlint/{src/router.ts => config-overrides.js} (76%)
copy docs/gremlint/src/components/{Spacer.ts => CenteredContainer.tsx} (85%)
copy docs/gremlint/src/components/{Paragraph.tsx => Footer.tsx} (63%)
copy docs/gremlint/src/components/{FadeIn.tsx => View.tsx} (61%)
[tinkerpop] 05/10: TINKERPOP-2605 Added project() test where by()
returns null
Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2605
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 3ca209a7f3d4ad37a960488328467b8d3dac3969
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Tue Aug 24 12:36:41 2021 -0400
TINKERPOP-2605 Added project() test where by() returns null
---
.../Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs | 1 +
.../gremlin-javascript/test/cucumber/gremlin.js | 1 +
gremlin-python/src/main/python/radish/gremlin.py | 1 +
gremlin-test/features/map/Project.feature | 20 ++++++++++++++-
.../process/traversal/step/map/ProjectTest.java | 29 +++++++++++++++++++---
5 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
index cdebd15..fe23a6f 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
@@ -493,6 +493,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
{"g_V_hasLabelXpersonX_projectXa_bX_byXoutE_countX_byXageX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().HasLabel("person").Project<object>("a","b").By(__.OutE().Count()).By("age")}},
{"g_V_outXcreatedX_projectXa_bX_byXnameX_byXinXcreatedX_countX_order_byXselectXbX__descX_selectXaX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Out("created").Project<object>("a","b").By("name").By(__.In("created").Count()).Order().By(__.Select<object>("b"),Order.Desc).Select<object>("a")}},
{"g_V_valueMap_projectXxX_byXselectXnameXX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().ValueMap<object,object>().Project<object>("x").By(__.Select<object>("name"))}},
+ {"g_V_projectXa_bX_byXinE_countX_byXageX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Project<object>("a","b").By(__.InE().Count()).By("age")}},
{"g_V_hasXageX_propertiesXnameX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has("age").Properties<object>("name").Value<object>()}},
{"g_V_hasXageX_propertiesXname_ageX_value", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has("age").Properties<object>("name","age").Value<object>()}},
{"g_V_hasXageX_propertiesXage_nameX_value", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has("age").Properties<object>("age","name").Value<object>()}},
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
index fafe089..5bda6d9 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
@@ -482,6 +482,7 @@ const gremlins = {
g_V_hasLabelXpersonX_projectXa_bX_byXoutE_countX_byXageX: [function({g}) { return g.V().hasLabel("person").project("a","b").by(__.outE().count()).by("age") }],
g_V_outXcreatedX_projectXa_bX_byXnameX_byXinXcreatedX_countX_order_byXselectXbX__descX_selectXaX: [function({g}) { return g.V().out("created").project("a","b").by("name").by(__.in_("created").count()).order().by(__.select("b"),Order.desc).select("a") }],
g_V_valueMap_projectXxX_byXselectXnameXX: [function({g}) { return g.V().valueMap().project("x").by(__.select("name")) }],
+ g_V_projectXa_bX_byXinE_countX_byXageX: [function({g}) { return g.V().project("a","b").by(__.inE().count()).by("age") }],
g_V_hasXageX_propertiesXnameX: [function({g}) { return g.V().has("age").properties("name").value() }],
g_V_hasXageX_propertiesXname_ageX_value: [function({g}) { return g.V().has("age").properties("name","age").value() }],
g_V_hasXageX_propertiesXage_nameX_value: [function({g}) { return g.V().has("age").properties("age","name").value() }],
diff --git a/gremlin-python/src/main/python/radish/gremlin.py b/gremlin-python/src/main/python/radish/gremlin.py
index 2599b40..69379ec 100644
--- a/gremlin-python/src/main/python/radish/gremlin.py
+++ b/gremlin-python/src/main/python/radish/gremlin.py
@@ -467,6 +467,7 @@ world.gremlins = {
'g_V_hasLabelXpersonX_projectXa_bX_byXoutE_countX_byXageX': [(lambda g:g.V().hasLabel('person').project('a','b').by(__.outE().count()).by('age'))],
'g_V_outXcreatedX_projectXa_bX_byXnameX_byXinXcreatedX_countX_order_byXselectXbX__descX_selectXaX': [(lambda g:g.V().out('created').project('a','b').by('name').by(__.in_('created').count()).order().by(__.select('b'),Order.desc).select('a'))],
'g_V_valueMap_projectXxX_byXselectXnameXX': [(lambda g:g.V().valueMap().project('x').by(__.select('name')))],
+ 'g_V_projectXa_bX_byXinE_countX_byXageX': [(lambda g:g.V().project('a','b').by(__.inE().count()).by('age'))],
'g_V_hasXageX_propertiesXnameX': [(lambda g:g.V().has('age').properties('name').value())],
'g_V_hasXageX_propertiesXname_ageX_value': [(lambda g:g.V().has('age').properties('name','age').value())],
'g_V_hasXageX_propertiesXage_nameX_value': [(lambda g:g.V().has('age').properties('age','name').value())],
diff --git a/gremlin-test/features/map/Project.feature b/gremlin-test/features/map/Project.feature
index f3666b8..1749693 100644
--- a/gremlin-test/features/map/Project.feature
+++ b/gremlin-test/features/map/Project.feature
@@ -68,4 +68,22 @@ Feature: Step - project()
| m[{"x":["vadas"]}] |
| m[{"x":["peter"]}] |
| m[{"x":["lop"]}] |
- | m[{"x":["ripple"]}] |
\ No newline at end of file
+ | m[{"x":["ripple"]}] |
+
+ Scenario: g_V_projectXa_bX_byXinE_countX_byXageX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().project("a", "b").
+ by(__.inE().count()).
+ by("age")
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | m[{"a":"d[1].l", "b":null}] |
+ | m[{"a":"d[3].l", "b":null}] |
+ | m[{"a":"d[0].l", "b":"d[29].i"}] |
+ | m[{"a":"d[1].l", "b":"d[27].i"}] |
+ | m[{"a":"d[1].l", "b":"d[32].i"}] |
+ | m[{"a":"d[0].l", "b":"d[35].i"}] |
\ No newline at end of file
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ProjectTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ProjectTest.java
index af71500..c073eb1 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ProjectTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/ProjectTest.java
@@ -41,6 +41,8 @@ public abstract class ProjectTest extends AbstractGremlinProcessTest {
public abstract Traversal<Vertex, Map<String, Number>> get_g_V_hasLabelXpersonX_projectXa_bX_byXoutE_countX_byXageX();
+ public abstract Traversal<Vertex, Map<String, Number>> get_g_V_projectXa_bX_byXinE_countX_byXageX();
+
public abstract Traversal<Vertex, String> get_g_V_outXcreatedX_projectXa_bX_byXnameX_byXinXcreatedX_countX_order_byXselectXbX__descX_selectXaX();
public abstract Traversal<Vertex, Map<String, Object>> get_g_V_valueMap_projectXxX_byXselectXnameXX();
@@ -51,10 +53,24 @@ public abstract class ProjectTest extends AbstractGremlinProcessTest {
final Traversal<Vertex, Map<String, Number>> traversal = get_g_V_hasLabelXpersonX_projectXa_bX_byXoutE_countX_byXageX();
printTraversalForm(traversal);
checkResults(makeMapList(2,
- "a", 3l, "b", 29,
- "a", 0l, "b", 27,
- "a", 2l, "b", 32,
- "a", 1l, "b", 35), traversal);
+ "a", 3L, "b", 29,
+ "a", 0L, "b", 27,
+ "a", 2L, "b", 32,
+ "a", 1L, "b", 35), traversal);
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_projectXa_bX_byXinE_countX_byXageX() {
+ final Traversal<Vertex, Map<String, Number>> traversal = get_g_V_projectXa_bX_byXinE_countX_byXageX();
+ printTraversalForm(traversal);
+ checkResults(makeMapList(2,
+ "a", 3l, "b", null,
+ "a", 1L, "b", null,
+ "a", 0L, "b", 29,
+ "a", 1L, "b", 27,
+ "a", 1L, "b", 32,
+ "a", 0L, "b", 35), traversal);
}
@Test
@@ -92,6 +108,11 @@ public abstract class ProjectTest extends AbstractGremlinProcessTest {
}
@Override
+ public Traversal<Vertex, Map<String, Number>> get_g_V_projectXa_bX_byXinE_countX_byXageX() {
+ return g.V().<Number>project("a", "b").by(__.inE().count()).by("age");
+ }
+
+ @Override
public Traversal<Vertex, String> get_g_V_outXcreatedX_projectXa_bX_byXnameX_byXinXcreatedX_countX_order_byXselectXbX__descX_selectXaX() {
return g.V().out("created").project("a", "b").by("name").by(__.in("created").count()).order().by(__.select("b"), Order.desc).select("a");
}
[tinkerpop] 10/10: TINKERPOP-2605 Fixed issues with null and
inject()
Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2605
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 4fec95253f4fcadd34d19e22834aba5605a3c777
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Mon Aug 30 15:10:11 2021 -0400
TINKERPOP-2605 Fixed issues with null and inject()
---
CHANGELOG.asciidoc | 3 +
.../traversal/dsl/graph/GraphTraversal.java | 6 +-
.../traversal/dsl/graph/GraphTraversalSource.java | 6 +-
.../traversal/translator/DotNetTranslator.java | 9 +-
.../traversal/translator/GroovyTranslator.java | 25 ++++--
.../gremlin/structure/util/StringFactory.java | 6 +-
.../gremlin/util/iterator/ArrayIterator.java | 5 +-
.../traversal/translator/DotNetTranslatorTest.java | 14 +++-
.../translator/JavascriptTranslatorTest.java | 5 ++
.../gremlin/util/iterator/ArrayIteratorTest.java | 32 +++++++
gremlin-dotnet/build/generate.groovy | 98 ++++++++++++----------
.../Process/Traversal/GraphTraversal.cs | 15 +++-
.../Process/Traversal/GraphTraversalSource.cs | 16 +++-
.../Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs | 6 ++
gremlin-javascript/build/generate.groovy | 52 +++++++-----
.../gremlin-javascript/test/cucumber/gremlin.js | 6 ++
gremlin-python/build/generate.groovy | 55 +++++++-----
gremlin-python/src/main/python/radish/gremlin.py | 6 ++
gremlin-test/features/sideEffect/Inject.feature | 75 ++++++++++++++++-
.../traversal/step/sideEffect/InjectTest.java | 88 +++++++++++++++++++
20 files changed, 417 insertions(+), 111 deletions(-)
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 6557c8b..0155cfc 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -33,6 +33,9 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
* Improved handling of `null` when passed to `P` predicates.
* Handled `null` for mathematical reducing operations of `sum()`, `mean()`, `max()` and `min()`.
* Allowed `null` values in `Memory` for `GraphComputer`.
+* Fixed problems with `inject(null)` variations where `null` was the only value being submitted.
+* Fixed problem with `GroovyTranslator` and `inject(null,null)` which could be interpreted as the Groovy JDK extension `inject(Object,Closure).
+* Fixed error where certain variants of `inject()` with `null` might not properly construct a traversal in .NET.
* Refined `DotNetTranslator` to be more explicit with `null` arguments to ensure that the right overloads are called.
* Created `GremlinParser` to construct `Traversal` objects from `gremlin-language`.
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index 63a394e..f52c30f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -1284,8 +1284,10 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* @since 3.0.0-incubating
*/
public default GraphTraversal<S, E> inject(final E... injections) {
- this.asAdmin().getBytecode().addStep(Symbols.inject, injections);
- return this.asAdmin().addStep(new InjectStep<>(this.asAdmin(), injections));
+ // a single null is [null]
+ final E[] s = null == injections ? (E[]) new Object[] { null } : injections;
+ this.asAdmin().getBytecode().addStep(Symbols.inject, s);
+ return this.asAdmin().addStep(new InjectStep<>(this.asAdmin(), s));
}
/**
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
index 64fff5d..b7471b1 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
@@ -352,10 +352,12 @@ public class GraphTraversalSource implements TraversalSource {
* Spawns a {@link GraphTraversal} starting it with arbitrary values.
*/
public <S> GraphTraversal<S, S> inject(S... starts) {
+ // a single null is [null]
+ final S[] s = null == starts ? (S[]) new Object[] { null } : starts;
final GraphTraversalSource clone = this.clone();
- clone.bytecode.addStep(GraphTraversal.Symbols.inject, starts);
+ clone.bytecode.addStep(GraphTraversal.Symbols.inject, s);
final GraphTraversal.Admin<S, S> traversal = new DefaultGraphTraversal<>(clone);
- return traversal.addStep(new InjectStep<S>(traversal, starts));
+ return traversal.addStep(new InjectStep<S>(traversal, s));
}
/**
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslator.java
index d4dcc35..d6ac2eb 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslator.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslator.java
@@ -304,18 +304,22 @@ public final class DotNetTranslator implements Translator.ScriptTranslator {
@Override
protected Script produceScript(final String traversalSource, final Bytecode o) {
script.append(traversalSource);
+ int instructionPosition = 0;
for (final Bytecode.Instruction instruction : o.getInstructions()) {
final String methodName = instruction.getOperator();
// perhaps too many if/then conditions for specifying generics. doesnt' seem like there is a clear
// way to refactor this more nicely though.
+ //
+ // inject() only has types when called with it when its used as a start step
if (0 == instruction.getArguments().length) {
- if (methodName.equals(GraphTraversal.Symbols.fold) && o.getSourceInstructions().size() + o.getStepInstructions().size() > 1)
+ if (methodName.equals(GraphTraversal.Symbols.fold) && o.getSourceInstructions().size() + o.getStepInstructions().size() > 1 ||
+ (methodName.equals(GraphTraversal.Symbols.inject) && instructionPosition > 0))
script.append(".").append(resolveSymbol(methodName).replace("<object>", "")).append("()");
else
script.append(".").append(resolveSymbol(methodName)).append("()");
} else {
if (methodsWithArgsNotNeedingGeneric.contains(methodName) ||
- (methodName.equals(GraphTraversal.Symbols.inject) && Arrays.stream(instruction.getArguments()).noneMatch(Objects::isNull)))
+ (methodName.equals(GraphTraversal.Symbols.inject) && (Arrays.stream(instruction.getArguments()).noneMatch(Objects::isNull) || instructionPosition > 0)))
script.append(".").append(resolveSymbol(methodName).replace("<object>", "").replace("<object,object>", "")).append("(");
else
script.append(".").append(resolveSymbol(methodName)).append("(");
@@ -359,6 +363,7 @@ public final class DotNetTranslator implements Translator.ScriptTranslator {
}
script.setCharAtEnd(')');
}
+ instructionPosition++;
}
return script;
}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/GroovyTranslator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/GroovyTranslator.java
index f11378b..1cf44a8 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/GroovyTranslator.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/GroovyTranslator.java
@@ -28,6 +28,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
import org.apache.tinkerpop.gremlin.process.traversal.Script;
import org.apache.tinkerpop.gremlin.process.traversal.TextP;
import org.apache.tinkerpop.gremlin.process.traversal.Translator;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalOptionParent;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.TraversalStrategyProxy;
import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP;
@@ -311,21 +312,31 @@ public final class GroovyTranslator implements Translator.ScriptTranslator {
}
@Override
- protected Script produceScript(final String traversalSource, final Bytecode o) {
+ protected Script produceScript(final String traversalSource, final Bytecode bytecode) {
script.append(traversalSource);
- for (final Bytecode.Instruction instruction : o.getInstructions()) {
+ for (final Bytecode.Instruction instruction : bytecode.getInstructions()) {
final String methodName = instruction.getOperator();
if (0 == instruction.getArguments().length) {
script.append(".").append(methodName).append("()");
} else {
script.append(".").append(methodName).append("(");
- final Iterator<Object> itty = Arrays.stream(instruction.getArguments()).iterator();
- while(itty.hasNext()) {
- convertToScript(itty.next());
- if (itty.hasNext()) script.append(",");
+ // special case inject(null, null) or else groovy might guess the JDK collection extension form
+ if (methodName.equals(TraversalSource.Symbols.withSack)) {
+ final Iterator<Object> itty = Arrays.stream(instruction.getArguments()).iterator();
+ while (itty.hasNext()) {
+ final Object o = itty.next();
+ if (null == o) script.append("(Object)");
+ convertToScript(o);
+ if (itty.hasNext()) script.append(",");
+ }
+ } else {
+ final Iterator<Object> itty = Arrays.stream(instruction.getArguments()).iterator();
+ while (itty.hasNext()) {
+ convertToScript(itty.next());
+ if (itty.hasNext()) script.append(",");
+ }
}
-
script.append(")");
}
}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/StringFactory.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/StringFactory.java
index dfab163..49206cf 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/StringFactory.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/StringFactory.java
@@ -218,7 +218,6 @@ public final class StringFactory {
public static String stepString(final Step<?, ?> step, final Object... arguments) {
final StringBuilder builder = new StringBuilder(step.getClass().getSimpleName());
final List<String> strings = Stream.of(arguments)
- .filter(o -> null != o)
.filter(o -> {
if (o instanceof TraversalRing)
return !((TraversalRing) o).isEmpty();
@@ -227,10 +226,10 @@ public final class StringFactory {
else if (o instanceof Map)
return !((Map) o).isEmpty();
else
- return !o.toString().isEmpty();
+ return !Objects.toString(o).isEmpty();
})
.map(o -> {
- final String string = o.toString();
+ final String string = Objects.toString(o);
return hasLambda(string) ? "lambda" : string;
}).collect(Collectors.toList());
if (!strings.isEmpty()) {
@@ -239,7 +238,6 @@ public final class StringFactory {
builder.append(')');
}
if (!step.getLabels().isEmpty()) builder.append('@').append(step.getLabels());
- //builder.append("^").append(step.getId());
return builder.toString();
}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/ArrayIterator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/ArrayIterator.java
index 7d5f959..3d87f34 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/ArrayIterator.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/ArrayIterator.java
@@ -23,6 +23,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementExce
import java.io.Serializable;
import java.util.Arrays;
import java.util.Iterator;
+import java.util.Objects;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -33,7 +34,7 @@ public final class ArrayIterator<T> implements Iterator<T>, Serializable {
private int current = 0;
public ArrayIterator(final T[] array) {
- this.array = array;
+ this.array = Objects.requireNonNull(array);
}
@Override
@@ -53,6 +54,6 @@ public final class ArrayIterator<T> implements Iterator<T>, Serializable {
@Override
public String toString() {
- return Arrays.asList(array).toString();
+ return array.length == 1 && null == array[0] ? "[null]" : Arrays.asList(array).toString();
}
}
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslatorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslatorTest.java
index 3e5654c..1b0fd71 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslatorTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslatorTest.java
@@ -88,8 +88,20 @@ public class DotNetTranslatorTest {
@Test
public void shouldTranslateInject() {
- final String script = translator.translate(g.inject(10,20,null,20,10,10).asAdmin().getBytecode()).getScript();
+ String script = translator.translate(g.inject(10,20,null,20,10,10).asAdmin().getBytecode()).getScript();
assertEquals("g.Inject<object>(10,20,null,20,10,10)", script);
+ script = translator.translate(g.inject().asAdmin().getBytecode()).getScript();
+ assertEquals("g.Inject<object>()", script);
+ script = translator.translate(g.inject((Object) null).asAdmin().getBytecode()).getScript();
+ assertEquals("g.Inject<object>(null)", script);
+ script = translator.translate(g.inject(null, null).asAdmin().getBytecode()).getScript();
+ assertEquals("g.Inject<object>(null,null)", script);
+ script = translator.translate(g.V().values("age").inject().asAdmin().getBytecode()).getScript();
+ assertEquals("g.V().Values<object>(\"age\").Inject()", script);
+ script = translator.translate(g.V().values("age").inject(null).asAdmin().getBytecode()).getScript();
+ assertEquals("g.V().Values<object>(\"age\").Inject(null)", script);
+ script = translator.translate(g.V().values("age").inject(null, null).asAdmin().getBytecode()).getScript();
+ assertEquals("g.V().Values<object>(\"age\").Inject(null,null)", script);
}
@Test
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/JavascriptTranslatorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/JavascriptTranslatorTest.java
index 5990418..8ae9f4c 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/JavascriptTranslatorTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/JavascriptTranslatorTest.java
@@ -115,6 +115,11 @@ public class JavascriptTranslatorTest {
}
@Test
+ public void shouldHaveNull() {
+ translator.translate(g.inject(null, null).asAdmin().getBytecode()).getScript();
+ }
+
+ @Test
public void shouldEscapeStrings() {
final String script = translator.translate(g.addV("customer")
.property("customer_id", 501L)
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/ArrayIteratorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/ArrayIteratorTest.java
index 2293277..d2027e3 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/ArrayIteratorTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/ArrayIteratorTest.java
@@ -78,4 +78,36 @@ public class ArrayIteratorTest {
final Iterator<String> itty = new ArrayIterator<>(arr);
assertEquals("[test1, test2, test3]", itty.toString());
}
+
+ @Test(expected = NullPointerException.class)
+ public void shouldNotAllowNullConstruction() {
+ new ArrayIterator<>(null);
+ }
+
+ @Test
+ public void shouldAllowNullInArray() {
+ final String[] arr = new String[3];
+ arr[0] = "test1";
+ arr[1] = null;
+ arr[2] = "test3";
+
+ final Iterator<String> itty = new ArrayIterator<>(arr);
+ assertEquals("[test1, null, test3]", itty.toString());
+ }
+
+ @Test
+ public void shouldAllowSingleNullInArray() {
+ final String[] arr = new String[1];
+
+ final Iterator<String> itty = new ArrayIterator<>(arr);
+ assertEquals("[null]", itty.toString());
+ }
+
+ @Test
+ public void shouldAllowZeroNullInArray() {
+ final String[] arr = new String[0];
+
+ final Iterator<String> itty = new ArrayIterator<>(arr);
+ assertEquals("[]", itty.toString());
+ }
}
diff --git a/gremlin-dotnet/build/generate.groovy b/gremlin-dotnet/build/generate.groovy
index ad7a160..5fa64fa 100644
--- a/gremlin-dotnet/build/generate.groovy
+++ b/gremlin-dotnet/build/generate.groovy
@@ -104,52 +104,64 @@ radishGremlinFile.withWriter('UTF-8') { Writer writer ->
' new Dictionary<string, List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>>>\n' +
' {')
+ // Groovy can't process certain null oriented calls because it gets confused with the right overload to call
+ // at runtime. using this approach for now as these are the only such situations encountered so far. a better
+ // solution may become necessary as testing of nulls expands.
+ def staticTranslate = [
+ g_injectXnull_nullX: " {\"g_injectXnull_nullX\", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject<object>(null,null)}}, ",
+ g_VX1X_valuesXageX_injectXnull_nullX: " {\"g_VX1X_valuesXageX_injectXnull_nullX\", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p[\"xx1\"]).Values<object>(\"age\").Inject(null,null)}}, "
+ ]
+
gremlins.each { k,v ->
- writer.write(" {\"")
- writer.write(k)
- writer.write("\", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {")
- def collected = v.collect{
- def t = gremlinGroovyScriptEngine.eval(it, bindings)
- [t, t.bytecode.bindings.keySet()]
- }
+ if (staticTranslate.containsKey(k)) {
+ writer.writeLine(staticTranslate[k])
+ } else {
+ writer.write(" {\"")
+ writer.write(k)
+ writer.write("\", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {")
+ def collected = v.collect {
+ def t = gremlinGroovyScriptEngine.eval(it, bindings)
+ [t, t.bytecode.bindings.keySet()]
+ }
- def gremlinItty = collected.iterator()
- while (gremlinItty.hasNext()) {
- def t = gremlinItty.next()[0]
- writer.write("(g,p) =>")
- writer.write(translator.translate(t.bytecode).script.
- replace("xx1", "p[\"xx1\"]").
- replace("xx2", "p[\"xx2\"]").
- replace("xx3", "p[\"xx3\"]").
- replace("v1", "(Vertex) p[\"v1\"]").
- replace("v2", "(Vertex) p[\"v2\"]").
- replace("v3", "(Vertex) p[\"v3\"]").
- replace("v4", "(Vertex) p[\"v4\"]").
- replace("v5", "(Vertex) p[\"v5\"]").
- replace("v6", "(Vertex) p[\"v6\"]").
- replace("vid1", "p[\"vid1\"]").
- replace("vid2", "p[\"vid2\"]").
- replace("vid3", "p[\"vid3\"]").
- replace("vid4", "p[\"vid4\"]").
- replace("vid5", "p[\"vid5\"]").
- replace("vid6", "p[\"vid6\"]").
- replace("e7", "p[\"e7\"]").
- replace("e10", "p[\"e10\"]").
- replace("e11", "p[\"e11\"]").
- replace("eid7", "p[\"eid7\"]").
- replace("eid10", "p[\"eid10\"]").
- replace("eid11", "p[\"eid11\"]").
- replace("l1", "(IFunction) p[\"l1\"]").
- replace("l2", "(IFunction) p[\"l2\"]").
- replace("pred1", "(IPredicate) p[\"pred1\"]").
- replace("c1", "(IComparator) p[\"c1\"]").
- replace("c2", "(IComparator) p[\"c2\"]"))
- if (gremlinItty.hasNext())
- writer.write(', ')
- else
- writer.write("}")
+ def gremlinItty = collected.iterator()
+ while (gremlinItty.hasNext()) {
+ def t = gremlinItty.next()[0]
+ writer.write("(g,p) =>")
+ writer.write(translator.translate(t.bytecode).script.
+ replace("xx1", "p[\"xx1\"]").
+ replace("xx2", "p[\"xx2\"]").
+ replace("xx3", "p[\"xx3\"]").
+ replace("v1", "(Vertex) p[\"v1\"]").
+ replace("v2", "(Vertex) p[\"v2\"]").
+ replace("v3", "(Vertex) p[\"v3\"]").
+ replace("v4", "(Vertex) p[\"v4\"]").
+ replace("v5", "(Vertex) p[\"v5\"]").
+ replace("v6", "(Vertex) p[\"v6\"]").
+ replace("vid1", "p[\"vid1\"]").
+ replace("vid2", "p[\"vid2\"]").
+ replace("vid3", "p[\"vid3\"]").
+ replace("vid4", "p[\"vid4\"]").
+ replace("vid5", "p[\"vid5\"]").
+ replace("vid6", "p[\"vid6\"]").
+ replace("e7", "p[\"e7\"]").
+ replace("e10", "p[\"e10\"]").
+ replace("e11", "p[\"e11\"]").
+ replace("eid7", "p[\"eid7\"]").
+ replace("eid10", "p[\"eid10\"]").
+ replace("eid11", "p[\"eid11\"]").
+ replace("l1", "(IFunction) p[\"l1\"]").
+ replace("l2", "(IFunction) p[\"l2\"]").
+ replace("pred1", "(IPredicate) p[\"pred1\"]").
+ replace("c1", "(IComparator) p[\"c1\"]").
+ replace("c2", "(IComparator) p[\"c2\"]"))
+ if (gremlinItty.hasNext())
+ writer.write(', ')
+ else
+ writer.write("}")
+ }
+ writer.writeLine('}, ')
}
- writer.writeLine('}, ')
}
writer.writeLine(' };\n')
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
index 8f6df56..2bc4de8 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
@@ -885,9 +885,18 @@ namespace Gremlin.Net.Process.Traversal
/// </summary>
public GraphTraversal<S, E> Inject (params E[] injections)
{
- var args = new List<object>(0 + injections.Length) {};
- args.AddRange(injections.Cast<object>());
- Bytecode.AddStep("inject", args.ToArray());
+ // null injections is treated as g.inject(null) meaning inject a single null traverser
+ if (injections == null)
+ {
+ Bytecode.AddStep("inject", new object[1] { null });
+ }
+ else
+ {
+ var args = new List<object>(0 + injections.Length) {};
+ args.AddRange(injections.Cast<object>());
+ Bytecode.AddStep("inject", args.ToArray());
+ }
+
return Wrap<S, E>(this);
}
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs
index db4c521..c74e826 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs
@@ -351,9 +351,19 @@ namespace Gremlin.Net.Process.Traversal
public GraphTraversal<S, S> Inject<S>(params S[] starts)
{
var traversal = new GraphTraversal<S, S>(TraversalStrategies, new Bytecode(Bytecode));
- var args = new List<object>(0 + starts.Length) {};
- args.AddRange(starts.Cast<object>());
- traversal.Bytecode.AddStep("inject", args.ToArray());
+
+ // null starts is treated as g.inject(null) meaning inject a single null traverser
+ if (starts == null)
+ {
+ traversal.Bytecode.AddStep("inject", new object[1] { null });
+ }
+ else
+ {
+ var args = new List<object>(0 + starts.Length) {};
+ args.AddRange(starts.Cast<object>());
+ traversal.Bytecode.AddStep("inject", args.ToArray());
+ }
+
return traversal;
}
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
index cc043f2..dac2353 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
@@ -711,6 +711,12 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
{"g_injectXnull_1_3_nullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject<object>(null,1,3,null)}},
{"g_injectX10_20_null_20_10_10X_groupCountXxX_dedup_asXyX_projectXa_bX_by_byXselectXxX_selectXselectXyXXX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject<object>(10,20,null,20,10,10).GroupCount("x").Dedup().As("y").Project<object>("a","b").By().By(__.Select<object>("x").Select<object>(__.Select<object>("y")))}},
{"g_injectXname_marko_age_nullX_selectXname_ageX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject(p["xx1"]).Select<object>("name","age")}},
+ {"g_injectXnull_nullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject<object>(null,null)}},
+ {"g_injectXnullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject<object>(null)}},
+ {"g_inject", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject<object>()}},
+ {"g_VX1X_valuesXageX_injectXnull_nullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p["xx1"]).Values<object>("age").Inject(null,null)}},
+ {"g_VX1X_valuesXageX_injectXnullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p["xx1"]).Values<object>("age").Inject(null)}},
+ {"g_VX1X_valuesXageX_inject", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p["xx1"]).Values<object>("age").Inject()}},
{"g_io_readXkryoX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Io<object>("data/tinkerpop-modern.kryo").Read(), (g,p) =>g.V(), (g,p) =>g.E()}},
{"g_io_read_withXreader_gryoX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Io<object>("data/tinkerpop-modern.kryo").With("~tinkerpop.io.reader","gryo").Read(), (g,p) =>g.V(), (g,p) =>g.E()}},
{"g_io_readXgraphsonX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Io<object>("data/tinkerpop-modern.json").Read(), (g,p) =>g.V(), (g,p) =>g.E()}},
diff --git a/gremlin-javascript/build/generate.groovy b/gremlin-javascript/build/generate.groovy
index 7a374c0..c82b14d 100644
--- a/gremlin-javascript/build/generate.groovy
+++ b/gremlin-javascript/build/generate.groovy
@@ -93,30 +93,42 @@ radishGremlinFile.withWriter('UTF-8') { Writer writer ->
'const TextP = traversalModule.TextP\n' +
'const WithOptions = traversalModule.withOptions\n')
+ // Groovy can't process certain null oriented calls because it gets confused with the right overload to call
+ // at runtime. using this approach for now as these are the only such situations encountered so far. a better
+ // solution may become necessary as testing of nulls expands.
+ def staticTranslate = [
+ g_injectXnull_nullX: " g_injectXnull_nullX: [function({g}) { return g.inject(null,null) }], ",
+ g_VX1X_valuesXageX_injectXnull_nullX: " g_VX1X_valuesXageX_injectXnull_nullX: [function({g, xx1}) { return g.V(xx1).values(\"age\").inject(null,null) }], "
+ ]
+
writer.writeLine('const gremlins = {')
gremlins.each { k,v ->
- writer.write(" ")
- writer.write(k)
- writer.write(": [")
- def collected = v.collect{
- def t = gremlinGroovyScriptEngine.eval(it, bindings)
- [t, t.bytecode.bindings.keySet()]
- }
- def uniqueBindings = collected.collect{it[1]}.flatten().unique()
- def gremlinItty = collected.iterator()
- while (gremlinItty.hasNext()) {
- def t = gremlinItty.next()[0]
- writer.write("function({g")
- if (!uniqueBindings.isEmpty()) {
- writer.write(", ")
- writer.write(uniqueBindings.join(", "))
+ if (staticTranslate.containsKey(k)) {
+ writer.writeLine(staticTranslate[k])
+ } else {
+ writer.write(" ")
+ writer.write(k)
+ writer.write(": [")
+ def collected = v.collect {
+ def t = gremlinGroovyScriptEngine.eval(it, bindings)
+ [t, t.bytecode.bindings.keySet()]
+ }
+ def uniqueBindings = collected.collect { it[1] }.flatten().unique()
+ def gremlinItty = collected.iterator()
+ while (gremlinItty.hasNext()) {
+ def t = gremlinItty.next()[0]
+ writer.write("function({g")
+ if (!uniqueBindings.isEmpty()) {
+ writer.write(", ")
+ writer.write(uniqueBindings.join(", "))
+ }
+ writer.write("}) { return ")
+ writer.write(translator.translate(t.bytecode).script)
+ writer.write(" }")
+ if (gremlinItty.hasNext()) writer.write(', ')
}
- writer.write("}) { return ")
- writer.write(translator.translate(t.bytecode).script)
- writer.write(" }")
- if (gremlinItty.hasNext()) writer.write(', ')
+ writer.writeLine('], ')
}
- writer.writeLine('], ')
}
writer.writeLine('}\n')
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
index 7548afe..feb52ff 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
@@ -700,6 +700,12 @@ const gremlins = {
g_injectXnull_1_3_nullX: [function({g}) { return g.inject(null,1,3,null) }],
g_injectX10_20_null_20_10_10X_groupCountXxX_dedup_asXyX_projectXa_bX_by_byXselectXxX_selectXselectXyXXX: [function({g}) { return g.inject(10,20,null,20,10,10).groupCount("x").dedup().as("y").project("a","b").by().by(__.select("x").select(__.select("y"))) }],
g_injectXname_marko_age_nullX_selectXname_ageX: [function({g, xx1}) { return g.inject(xx1).select("name","age") }],
+ g_injectXnull_nullX: [function({g}) { return g.inject(null,null) }],
+ g_injectXnullX: [function({g}) { return g.inject(null) }],
+ g_inject: [function({g}) { return g.inject() }],
+ g_VX1X_valuesXageX_injectXnull_nullX: [function({g, xx1}) { return g.V(xx1).values("age").inject(null,null) }],
+ g_VX1X_valuesXageX_injectXnullX: [function({g, xx1}) { return g.V(xx1).values("age").inject(null) }],
+ g_VX1X_valuesXageX_inject: [function({g, xx1}) { return g.V(xx1).values("age").inject() }],
g_io_readXkryoX: [function({g}) { return g.io("data/tinkerpop-modern.kryo").read() }, function({g}) { return g.V() }, function({g}) { return g.E() }],
g_io_read_withXreader_gryoX: [function({g}) { return g.io("data/tinkerpop-modern.kryo").with_("~tinkerpop.io.reader","gryo").read() }, function({g}) { return g.V() }, function({g}) { return g.E() }],
g_io_readXgraphsonX: [function({g}) { return g.io("data/tinkerpop-modern.json").read() }, function({g}) { return g.V() }, function({g}) { return g.E() }],
diff --git a/gremlin-python/build/generate.groovy b/gremlin-python/build/generate.groovy
index 05507d5..bac3d1b 100644
--- a/gremlin-python/build/generate.groovy
+++ b/gremlin-python/build/generate.groovy
@@ -77,31 +77,44 @@ radishGremlinFile.withWriter('UTF-8') { Writer writer ->
'from gremlin_python.process.graph_traversal import __\n' +
'from gremlin_python.structure.graph import Graph\n' +
'from gremlin_python.process.traversal import Barrier, Cardinality, P, TextP, Pop, Scope, Column, Order, Direction, T, Pick, Operator, IO, WithOptions\n')
+
+ // Groovy can't process certain null oriented calls because it gets confused with the right overload to call
+ // at runtime. using this approach for now as these are the only such situations encountered so far. a better
+ // solution may become necessary as testing of nulls expands.
+ def staticTranslate = [
+ g_injectXnull_nullX: " 'g_injectXnull_nullX': [(lambda g: g.inject(None,None))], ",
+ g_VX1X_valuesXageX_injectXnull_nullX: " 'g_VX1X_valuesXageX_injectXnull_nullX': [(lambda g, xx1=None: g.V(xx1).values('age').inject(None,None))], "
+ ]
+
writer.writeLine('world.gremlins = {')
gremlins.each { k,v ->
- writer.write(" '")
- writer.write(k)
- writer.write("': [")
- def collected = v.collect{
- def t = gremlinGroovyScriptEngine.eval(it, bindings)
- [t, t.bytecode.bindings.keySet()]
- }
- def uniqueBindings = collected.collect{it[1]}.flatten().unique()
- def gremlinItty = collected.iterator()
- while (gremlinItty.hasNext()) {
- def t = gremlinItty.next()[0]
- writer.write("(lambda g")
- if (!uniqueBindings.isEmpty()) {
- writer.write(", ")
- writer.write(uniqueBindings.join("=None,"))
- writer.write("=None")
+ if (staticTranslate.containsKey(k)) {
+ writer.writeLine(staticTranslate[k])
+ } else {
+ writer.write(" '")
+ writer.write(k)
+ writer.write("': [")
+ def collected = v.collect {
+ def t = gremlinGroovyScriptEngine.eval(it, bindings)
+ [t, t.bytecode.bindings.keySet()]
+ }
+ def uniqueBindings = collected.collect { it[1] }.flatten().unique()
+ def gremlinItty = collected.iterator()
+ while (gremlinItty.hasNext()) {
+ def t = gremlinItty.next()[0]
+ writer.write("(lambda g")
+ if (!uniqueBindings.isEmpty()) {
+ writer.write(", ")
+ writer.write(uniqueBindings.join("=None,"))
+ writer.write("=None")
+ }
+ writer.write(":")
+ writer.write(translator.translate(t.bytecode).script)
+ writer.write(")")
+ if (gremlinItty.hasNext()) writer.write(', ')
}
- writer.write(":")
- writer.write(translator.translate(t.bytecode).script)
- writer.write(")")
- if (gremlinItty.hasNext()) writer.write(', ')
+ writer.writeLine('], ')
}
- writer.writeLine('], ')
}
writer.writeLine('}')
}
diff --git a/gremlin-python/src/main/python/radish/gremlin.py b/gremlin-python/src/main/python/radish/gremlin.py
index b4e6d81..defbf6b 100644
--- a/gremlin-python/src/main/python/radish/gremlin.py
+++ b/gremlin-python/src/main/python/radish/gremlin.py
@@ -685,6 +685,12 @@ world.gremlins = {
'g_injectXnull_1_3_nullX': [(lambda g:g.inject(None,1,3,None))],
'g_injectX10_20_null_20_10_10X_groupCountXxX_dedup_asXyX_projectXa_bX_by_byXselectXxX_selectXselectXyXXX': [(lambda g:g.inject(10,20,None,20,10,10).groupCount('x').dedup().as_('y').project('a','b').by().by(__.select('x').select(__.select('y'))))],
'g_injectXname_marko_age_nullX_selectXname_ageX': [(lambda g, xx1=None:g.inject(xx1).select('name','age'))],
+ 'g_injectXnull_nullX': [(lambda g: g.inject(None,None))],
+ 'g_injectXnullX': [(lambda g:g.inject(None))],
+ 'g_inject': [(lambda g:g.inject())],
+ 'g_VX1X_valuesXageX_injectXnull_nullX': [(lambda g, xx1=None: g.V(xx1).values('age').inject(None,None))],
+ 'g_VX1X_valuesXageX_injectXnullX': [(lambda g, xx1=None:g.V(xx1).age.inject(None))],
+ 'g_VX1X_valuesXageX_inject': [(lambda g, xx1=None:g.V(xx1).age.inject())],
'g_io_readXkryoX': [(lambda g:g.io('data/tinkerpop-modern.kryo').read()), (lambda g:g.V()), (lambda g:g.E())],
'g_io_read_withXreader_gryoX': [(lambda g:g.io('data/tinkerpop-modern.kryo').with_('~tinkerpop.io.reader','gryo').read()), (lambda g:g.V()), (lambda g:g.E())],
'g_io_readXgraphsonX': [(lambda g:g.io('data/tinkerpop-modern.json').read()), (lambda g:g.V()), (lambda g:g.E())],
diff --git a/gremlin-test/features/sideEffect/Inject.feature b/gremlin-test/features/sideEffect/Inject.feature
index dc5e717..49d8569 100644
--- a/gremlin-test/features/sideEffect/Inject.feature
+++ b/gremlin-test/features/sideEffect/Inject.feature
@@ -104,4 +104,77 @@ Feature: Step - inject()
When iterated to list
Then the result should be unordered
| result |
- | m[{"name":"marko", "age":null}] |
\ No newline at end of file
+ | m[{"name":"marko", "age":null}] |
+
+ Scenario: g_injectXnull_nullX
+ Given the empty graph
+ And the traversal of
+ """
+ g.inject(null, null)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | null |
+ | null |
+
+ Scenario: g_injectXnullX
+ Given the empty graph
+ And the traversal of
+ """
+ g.inject(null)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | null |
+
+
+ Scenario: g_inject
+ Given the empty graph
+ And the traversal of
+ """
+ g.inject()
+ """
+ When iterated to list
+ Then the result should be empty
+
+ Scenario: g_VX1X_valuesXageX_injectXnull_nullX
+ Given the modern graph
+ And using the parameter xx1 defined as "v[marko].id"
+ And the traversal of
+ """
+ g.V(xx1).values("age").inject(null, null)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[29].i |
+ | null |
+ | null |
+
+ Scenario: g_VX1X_valuesXageX_injectXnullX
+ Given the modern graph
+ And using the parameter xx1 defined as "v[marko].id"
+ And the traversal of
+ """
+ g.V(xx1).values("age").inject(null)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[29].i |
+ | null |
+
+
+ Scenario: g_VX1X_valuesXageX_inject
+ Given the modern graph
+ And using the parameter xx1 defined as "v[marko].id"
+ And the traversal of
+ """
+ g.V(xx1).values("age").inject()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[29].i |
\ No newline at end of file
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/InjectTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/InjectTest.java
index fd752d2..8fb3eb4 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/InjectTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/InjectTest.java
@@ -30,6 +30,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -51,6 +52,18 @@ public abstract class InjectTest extends AbstractGremlinProcessTest {
public abstract Traversal<Integer, Integer> get_g_injectXnull_1_3_nullX();
+ public abstract Traversal<Integer, Integer> get_g_injectXnull_nullX();
+
+ public abstract Traversal<Integer, Integer> get_g_injectXnullX();
+
+ public abstract Traversal<Integer, Integer> get_g_inject();
+
+ public abstract Traversal<Vertex, Object> get_g_VX1X_valuesXageX_injectXnull_nullX(final Object vid1);
+
+ public abstract Traversal<Vertex, Object> get_g_VX1X_valuesXageX_injectXnullX(final Object vid1);
+
+ public abstract Traversal<Vertex, Object> get_g_VX1X_valuesXageX_inject(final Object vid1);
+
public abstract Traversal<Integer, Map<String, Object>> get_g_injectX10_20_null_20_10_10X_groupCountXxX_dedup_asXyX_projectXa_bX_by_byXselectXxX_selectXselectXyXXX();
public abstract Traversal<Map<String,Object>, Map<String, Object>> get_g_injectXname_marko_age_nullX_selectXname_ageX();
@@ -99,6 +112,51 @@ public abstract class InjectTest extends AbstractGremlinProcessTest {
}
@Test
+ public void g_injectXnull_nullX() {
+ final Traversal<Integer, Integer> traversal = get_g_injectXnull_nullX();
+ printTraversalForm(traversal);
+ checkResults(Arrays.asList(null, null), traversal);
+ }
+
+ @Test
+ public void g_injectXnullX() {
+ final Traversal<Integer, Integer> traversal = get_g_injectXnullX();
+ printTraversalForm(traversal);
+ checkResults(Collections.singletonList(null), traversal);
+ }
+
+ @Test
+ public void g_inject() {
+ final Traversal<Integer, Integer> traversal = get_g_inject();
+ printTraversalForm(traversal);
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_VX1X_valuesXageX_injectXnull_nullX() {
+ final Traversal<Vertex, Object> traversal = get_g_VX1X_valuesXageX_injectXnull_nullX(convertToVertexId("marko"));
+ printTraversalForm(traversal);
+ checkResults(Arrays.asList(29, null, null), traversal);
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_VX1X_valuesXageX_injectXnullX() {
+ final Traversal<Vertex, Object> traversal = get_g_VX1X_valuesXageX_injectXnullX(convertToVertexId("marko"));
+ printTraversalForm(traversal);
+ checkResults(Arrays.asList(29, null), traversal);
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_VX1X_valuesXageX_inject() {
+ final Traversal<Vertex, Object> traversal = get_g_VX1X_valuesXageX_inject(convertToVertexId("marko"));
+ printTraversalForm(traversal);
+ checkResults(Arrays.asList(29), traversal);
+ }
+
+ @Test
public void g_injectX10_20_null_20_10_10X_groupCountXxX_dedup_asXyX_projectXa_bX_by_byXselectXxX_selectXselectXyXXX() {
final Traversal<Integer, Map<String, Object>> traversal = get_g_injectX10_20_null_20_10_10X_groupCountXxX_dedup_asXyX_projectXa_bX_by_byXselectXxX_selectXselectXyXXX();
printTraversalForm(traversal);
@@ -146,6 +204,36 @@ public abstract class InjectTest extends AbstractGremlinProcessTest {
}
@Override
+ public Traversal<Integer, Integer> get_g_injectXnull_nullX() {
+ return g.inject(null, null);
+ }
+
+ @Override
+ public Traversal<Integer, Integer> get_g_injectXnullX() {
+ return g.inject(null);
+ }
+
+ @Override
+ public Traversal<Integer, Integer> get_g_inject() {
+ return g.inject();
+ }
+
+ @Override
+ public Traversal<Vertex, Object> get_g_VX1X_valuesXageX_injectXnull_nullX(final Object vid1) {
+ return g.V(vid1).values("age").inject(null, null);
+ }
+
+ @Override
+ public Traversal<Vertex, Object> get_g_VX1X_valuesXageX_injectXnullX(final Object vid1) {
+ return g.V(vid1).values("age").inject(null);
+ }
+
+ @Override
+ public Traversal<Vertex, Object> get_g_VX1X_valuesXageX_inject(final Object vid1) {
+ return g.V(vid1).values("age").inject();
+ }
+
+ @Override
public Traversal<Integer, Map<String, Object>> get_g_injectX10_20_null_20_10_10X_groupCountXxX_dedup_asXyX_projectXa_bX_by_byXselectXxX_selectXselectXyXXX() {
return g.inject(10,20,null,20,10,10).groupCount("x").
dedup().as("y").
[tinkerpop] 02/10: TINKERPOP-2605 Added test/docs for order() when
the by() produces null
Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2605
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 2838d790974f1dec953c04107a48d81ef905309d
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Tue Aug 24 09:54:09 2021 -0400
TINKERPOP-2605 Added test/docs for order() when the by() produces null
---
docs/src/reference/the-traversal.asciidoc | 11 +++++++++--
gremlin-test/features/map/Order.feature | 16 ++++++++++++++++
.../gremlin/process/traversal/step/map/OrderTest.java | 17 +++++++++++++++++
3 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/docs/src/reference/the-traversal.asciidoc b/docs/src/reference/the-traversal.asciidoc
index 817c95d..92f182c 100644
--- a/docs/src/reference/the-traversal.asciidoc
+++ b/docs/src/reference/the-traversal.asciidoc
@@ -2402,9 +2402,16 @@ g.V().groupCount().by(inE().count()).order(local).by(keys, asc) <4>
NOTE: The `values` and `keys` enums are from `Column` which is used to select "columns" from a `Map`, `Map.Entry`, or `Path`.
+If a property key does not exist, then it will be treated as `null` which will sort it first for `Order.asc` and last
+for `Order.desc`.
+
+[gremlin-groovy,modern]
+----
+g.V().order().by("age").elementMap()
+----
+
NOTE: Prior to version 3.3.4, ordering was defined by `Order.incr` for ascending order and `Order.decr` for descending
-order. That approach is now deprecated with the preferred method shown in the examples which uses the more common
-forms for query languages in `Order.asc` and Order.desc.
+order. Those tokens were deprecated and eventually removed in 3.5.0.
*Additional References*
diff --git a/gremlin-test/features/map/Order.feature b/gremlin-test/features/map/Order.feature
index e208e85..ddb0c52 100644
--- a/gremlin-test/features/map/Order.feature
+++ b/gremlin-test/features/map/Order.feature
@@ -309,6 +309,22 @@ Feature: Step - order()
| v[josh] |
| v[peter] |
+ # tests order().by() where a property isn't present to ensure null comes first
+ Scenario: g_V_orXhasLabelXpersonX_hasXsoftware_name_lopXX_order_byXageX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().or(hasLabel("person"),has("software","name","lop")).order().by("age")
+ """
+ When iterated to list
+ Then the result should be ordered
+ | result |
+ | v[lop] |
+ | v[vadas] |
+ | v[marko] |
+ | v[josh] |
+ | v[peter] |
+
Scenario: g_VX1X_hasXlabel_personX_mapXmapXint_ageXX_orderXlocalX_byXvalues_descX_byXkeys_ascX
Given the modern graph
And using the parameter v1 defined as "v[marko]"
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java
index efcbea9..b41fe70 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java
@@ -44,6 +44,8 @@ import java.util.Map;
import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.GRATEFUL;
import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
import static org.apache.tinkerpop.gremlin.process.traversal.Order.desc;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.hasLabel;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.outE;
import static org.apache.tinkerpop.gremlin.structure.Column.keys;
import static org.hamcrest.core.Is.is;
@@ -87,6 +89,8 @@ public abstract class OrderTest extends AbstractGremlinProcessTest {
public abstract Traversal<Vertex, Vertex> get_g_V_hasLabelXpersonX_order_byXageX();
+ public abstract Traversal<Vertex, Vertex> get_g_V_orXhasLabelXpersonX_hasXsoftware_name_lopXX_order_byXageX();
+
public abstract Traversal<Vertex, List<Vertex>> get_g_V_hasLabelXpersonX_fold_orderXlocalX_byXageX();
public abstract Traversal<Vertex, String> get_g_V_hasLabelXpersonX_order_byXvalueXageX_descX_name();
@@ -304,6 +308,14 @@ public abstract class OrderTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
+ public void g_V_orXhasLabelXpersonX_hasXsoftware_name_lopXX_order_byXageX() {
+ final Traversal<Vertex, Vertex> traversal = get_g_V_orXhasLabelXpersonX_hasXsoftware_name_lopXX_order_byXageX();
+ printTraversalForm(traversal);
+ checkResults(Arrays.asList(convertToVertex(graph, "lop"), convertToVertex(graph, "vadas"), convertToVertex(graph, "marko"), convertToVertex(graph, "josh"), convertToVertex(graph, "peter")), traversal);
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
public void g_V_hasLabelXpersonX_fold_orderXlocalX_byXageX() {
final Traversal<Vertex, List<Vertex>> traversal = get_g_V_hasLabelXpersonX_fold_orderXlocalX_byXageX();
printTraversalForm(traversal);
@@ -570,6 +582,11 @@ public abstract class OrderTest extends AbstractGremlinProcessTest {
}
@Override
+ public Traversal<Vertex, Vertex> get_g_V_orXhasLabelXpersonX_hasXsoftware_name_lopXX_order_byXageX() {
+ return g.V().or(hasLabel("person"), has("software","name","lop")).order().by("age");
+ }
+
+ @Override
public Traversal<Vertex, List<Vertex>> get_g_V_hasLabelXpersonX_fold_orderXlocalX_byXageX() {
return g.V().hasLabel("person").fold().order(Scope.local).by("age");
}
[tinkerpop] 09/10: TINKERPOP-2605 Improved null handling in
reducing math steps.
Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2605
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 89119c39a0e9a4d996559f2a3986bdfca41f29de
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Sun Aug 29 12:15:40 2021 -0400
TINKERPOP-2605 Improved null handling in reducing math steps.
---
CHANGELOG.asciidoc | 2 +
docs/src/dev/developer/for-committers.asciidoc | 3 +-
docs/src/reference/the-traversal.asciidoc | 78 ++++++++++--
docs/src/upgrade/release-3.5.x.asciidoc | 5 +-
.../process/traversal/step/map/MaxGlobalStep.java | 1 -
.../process/traversal/step/map/MeanGlobalStep.java | 22 +++-
.../process/traversal/step/map/MeanLocalStep.java | 18 ++-
.../process/traversal/step/map/MinGlobalStep.java | 1 -
.../process/traversal/step/map/SumGlobalStep.java | 16 ++-
.../process/traversal/step/map/SumLocalStep.java | 11 +-
.../traversal/step/util/ReducingBarrierStep.java | 59 ++++++---
.../gremlin/structure/io/gryo/GryoVersion.java | 10 +-
.../tinkerpop/gremlin/util/NumberHelper.java | 136 +++++++++++++++++++++
.../tinkerpop/gremlin/util/NumberHelperTest.java | 112 +++++++++++------
.../Gherkin/GherkinTestRunner.cs | 9 +-
.../Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs | 20 +++
.../gremlin-javascript/test/cucumber/gremlin.js | 20 +++
gremlin-python/src/main/python/radish/gremlin.py | 20 +++
.../GraphBinaryRemoteGraphComputerProvider.java | 18 ++-
.../GraphSONRemoteGraphComputerProvider.java | 18 ++-
.../remote/GryoRemoteGraphComputerProvider.java | 18 ++-
...emoteGraphGroovyTranslatorComputerProvider.java | 18 ++-
gremlin-test/features/map/Max.feature | 44 +++++++
gremlin-test/features/map/Mean.feature | 73 +++++++++++
gremlin-test/features/map/Min.feature | 44 +++++++
gremlin-test/features/map/Sum.feature | 73 +++++++++++
.../gremlin/process/GremlinProcessRunner.java | 4 +-
.../process/traversal/step/map/MaxTest.java | 63 ++++++++++
.../process/traversal/step/map/MeanTest.java | 93 ++++++++++++++
.../process/traversal/step/map/MinTest.java | 63 ++++++++++
.../process/traversal/step/map/SumTest.java | 100 +++++++++++++++
.../spark/process/computer/SparkMemory.java | 1 -
.../tinkergraph/process/computer/TinkerMemory.java | 21 ++--
.../process/TinkerGraphComputerProvider.java | 3 +-
34 files changed, 1102 insertions(+), 95 deletions(-)
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 9762fca..6557c8b 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -31,6 +31,8 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
* Allowed `null` string values in the Gremlin grammar.
* Prevented exception with `hasLabel(null)` and instead filter away traversers as labels can't ever be null.
* Improved handling of `null` when passed to `P` predicates.
+* Handled `null` for mathematical reducing operations of `sum()`, `mean()`, `max()` and `min()`.
+* Allowed `null` values in `Memory` for `GraphComputer`.
* Refined `DotNetTranslator` to be more explicit with `null` arguments to ensure that the right overloads are called.
* Created `GremlinParser` to construct `Traversal` objects from `gremlin-language`.
diff --git a/docs/src/dev/developer/for-committers.asciidoc b/docs/src/dev/developer/for-committers.asciidoc
index 6abcd0f..e020b71 100644
--- a/docs/src/dev/developer/for-committers.asciidoc
+++ b/docs/src/dev/developer/for-committers.asciidoc
@@ -342,7 +342,8 @@ edge identifier or the `.sid` suffix which gets a string representation of the e
* Lambda - *c[_xxx_]* - The "xxx" should contain a lambda written in Groovy.
* List - *l[_xxx_,_yyy_,_zzz_,...]* - A comma separated collection of values that make up the list should be added to
between the square brackets. These values respect the type system thus allowing for creation of lists of vertices,
-edges, maps, and any other available type.
+edges, maps, and any other available type. Spaces are taken literally, therefore it is important to avoid spaces unless
+they are required for the test.
* Map - *m[_xxx_]* - The "xxx" should be replaced with a JSON string. Note that keys and values will be parsed using
the type notation system so that it is possible to have maps containing arbitrary keys and values.
* Numeric - *d[_xxx_]._y_* - The "xxx" should be replaced with a number. The suffix denoted by "y" should always be
diff --git a/docs/src/reference/the-traversal.asciidoc b/docs/src/reference/the-traversal.asciidoc
index 92f182c..1b662eb 100644
--- a/docs/src/reference/the-traversal.asciidoc
+++ b/docs/src/reference/the-traversal.asciidoc
@@ -2162,7 +2162,8 @@ link:++https://tinkerpop.apache.org/javadocs/x.y.z/core/org/apache/tinkerpop/gre
[[max-step]]
=== Max Step
-The `max()`-step (*map*) operates on a stream of comparable objects and determines which is the last object according to its natural order in the stream.
+The `max()`-step (*map*) operates on a stream of comparable objects and determines which is the last object according
+to its natural order in the stream.
[gremlin-groovy,modern]
----
@@ -2171,8 +2172,22 @@ g.V().repeat(both()).times(3).values('age').max()
g.V().values('name').max()
----
-IMPORTANT: `max(local)` determines the max of the current, local object (not the objects in the traversal stream).
-This works for `Collection` and `Comparable`-type objects.
+When called as `max(local)` it determines the maximum value of the current, local object (not the objects in the
+traversal stream). This works for `Collection` and `Comparable`-type objects.
+
+[gremlin-groovy,modern]
+----
+g.V().values('age').fold().max(local)
+----
+
+When there are `null` values being evaluated the `null` objects are ignored, but if all values are recognized as `null`
+the return value is `null`.
+
+[gremlin-groovy,modern]
+----
+g.inject(null,10, 9, null).max()
+g.inject([null,null,null]).max(local)
+----
*Additional References*
@@ -2195,8 +2210,22 @@ g.V().repeat(both()).times(3).values('age').dedup().mean()
<1> Realize that traversers are being bulked by `repeat()`. There may be more of a particular number than another,
thus altering the average.
-IMPORTANT: `mean(local)` determines the mean of the current, local object (not the objects in the traversal stream).
-This works for `Collection` and `Number`-type objects.
+When called as `mean(local)` it determines the mean of the current, local object (not the objects in the traversal
+stream). This works for `Collection` and `Number`-type objects.
+
+[gremlin-groovy,modern]
+----
+g.V().values('age').fold().mean()
+----
+
+If `mean()` encounters `null` values, they will be ignored (i.e. their traversers not counted toward toward the
+divisor). If all traversers are `null` then the stream will return `null`.
+
+[gremlin-groovy,modern]
+----
+g.inject(null,10, 9, null).mean()
+g.inject([null,null,null]).mean(local)
+----
*Additional References*
@@ -2207,7 +2236,8 @@ link:++https://tinkerpop.apache.org/javadocs/x.y.z/core/org/apache/tinkerpop/gre
[[min-step]]
=== Min Step
-The `min()`-step (*map*) operates on a stream of comparable objects and determines which is the first object according to its natural order in the stream.
+The `min()`-step (*map*) operates on a stream of comparable objects and determines which is the first object according
+to its natural order in the stream.
[gremlin-groovy,modern]
----
@@ -2216,8 +2246,22 @@ g.V().repeat(both()).times(3).values('age').min()
g.V().values('name').min()
----
-IMPORTANT: `min(local)` determines the min of the current, local object (not the objects in the traversal stream).
-This works for `Collection` and `Comparable`-type objects.
+When called as `min(local)` it determines the minimum value of the current, local object (not the objects in the
+traversal stream). This works for `Collection` and `Comparable`-type objects.
+
+[gremlin-groovy,modern]
+----
+g.V().values('age').fold().min(local)
+----
+
+When there are `null` values being evaluated the `null` objects are ignored, but if all values are recognized as `null`
+the return value is `null`.
+
+[gremlin-groovy,modern]
+----
+g.inject(null,10, 9, null).min()
+g.inject([null,null,null]).min(local)
+----
*Additional References*
@@ -3457,8 +3501,22 @@ g.V().values('age').sum()
g.V().repeat(both()).times(3).values('age').sum()
----
-IMPORTANT: `sum(local)` determines the sum of the current, local object (not the objects in the traversal stream).
-This works for `Collection`-type objects.
+When called as `sum(local)` it determines the sum of the current, local object (not the objects in the traversal
+stream). This works for `Collection`-type objects.
+
+[gremlin-groovy,modern]
+----
+g.V().values('age').fold().sum(local)
+----
+
+When there are `null` values being evaluated the `null` objects are ignored, but if all values are recognized as `null`
+the return value is `null`.
+
+[gremlin-groovy,modern]
+----
+g.inject(null,10, 9, null).sum()
+g.inject([null,null,null]).sum(local)
+----
*Additional References*
diff --git a/docs/src/upgrade/release-3.5.x.asciidoc b/docs/src/upgrade/release-3.5.x.asciidoc
index 5a0d66b..b22965b 100644
--- a/docs/src/upgrade/release-3.5.x.asciidoc
+++ b/docs/src/upgrade/release-3.5.x.asciidoc
@@ -37,8 +37,11 @@ been noted that supplying a `null` value as an argument to certain Gremlin steps
were either not clear or perhaps even unexpected. The following changes were made to help make these behaviors more
consistent and to further solidify the semantics of `null` usage in the Gremlin language:
-* `hasLabel(null)` and `has(T.label,null)` - Formerly, these methods threw general `NullPointerException` failures,
+* `hasLabel(null)` and `has(T.label,null)` - These methods used to throw general `NullPointerException` failures,
but now filter results. As a `T.label` can't be `null`, it will effectively filter all elements.
+* `sum()`, `mean()`, `max()` and `min()` - These methods used to throw general `NullPointerException` failures, but
+now ignore `null` values when other numbers are present. If all of the values in the stream are `null` then `hasNext()`
+return `false`.
See: link:https://issues.apache.org/jira/browse/TINKERPOP-2605[TINKERPOP-2605]
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxGlobalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxGlobalStep.java
index 2873f55..1535a11 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxGlobalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxGlobalStep.java
@@ -36,7 +36,6 @@ public final class MaxGlobalStep<S extends Comparable> extends ReducingBarrierSt
public MaxGlobalStep(final Traversal.Admin traversal) {
super(traversal);
- this.setSeedSupplier(new ConstantSupplier<>((S) Double.valueOf(Double.NaN)));
this.setReducingBiOperator((BinaryOperator) Operator.max);
}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanGlobalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanGlobalStep.java
index 5e90336..8f03ef5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanGlobalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanGlobalStep.java
@@ -44,10 +44,23 @@ public final class MeanGlobalStep<S extends Number, E extends Number> extends Re
public MeanGlobalStep(final Traversal.Admin traversal) {
super(traversal);
- this.setSeedSupplier((Supplier) MeanNumberSupplier.instance());
this.setReducingBiOperator(MeanGlobalBiOperator.INSTANCE);
}
+ /**
+ * Advances the starts until a non-null value is found or simply returns {@code null}. In this way, an all
+ * {@code null} stream will result in {@code null}.
+ */
+ @Override
+ protected E generateSeedFromStarts() {
+ E e = null;
+ while (starts.hasNext() && null == e) {
+ e = projectTraverser(this.starts.next());
+ }
+
+ return e;
+ }
+
@Override
public void processAllStarts() {
if (this.starts.hasNext())
@@ -56,7 +69,7 @@ public final class MeanGlobalStep<S extends Number, E extends Number> extends Re
@Override
public E projectTraverser(final Traverser.Admin<S> traverser) {
- return (E) new MeanNumber(traverser.get(), traverser.bulk());
+ return null == traverser.get() ? null : (E) new MeanNumber(traverser.get(), traverser.bulk());
}
@Override
@@ -66,7 +79,8 @@ public final class MeanGlobalStep<S extends Number, E extends Number> extends Re
@Override
public E generateFinalResult(final E meanNumber) {
- return (E) ((MeanNumber) meanNumber).getFinal();
+ // if the meanNumber is null it means the whole stream was null
+ return null == meanNumber ? (E) null : (E) ((MeanNumber) meanNumber).getFinal();
}
/////
@@ -77,6 +91,8 @@ public final class MeanGlobalStep<S extends Number, E extends Number> extends Re
@Override
public S apply(final S mutatingSeed, final S number) {
+ if (null == mutatingSeed || null == number) return mutatingSeed;
+
if (mutatingSeed instanceof MeanNumber) {
return (number instanceof MeanNumber) ?
(S) ((MeanNumber) mutatingSeed).add((MeanNumber) number) :
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanLocalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanLocalStep.java
index 5ffb1a6..2ed1440 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanLocalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanLocalStep.java
@@ -42,17 +42,29 @@ public final class MeanLocalStep<E extends Number, S extends Iterable<E>> extend
protected Number map(final Traverser.Admin<S> traverser) {
final Iterator<E> iterator = traverser.get().iterator();
if (iterator.hasNext()) {
+ // forward the iterator to the first non-null or return null
+ E result = untilNonNull(iterator);
Long counter = 1L;
- E result = iterator.next();
while (iterator.hasNext()) {
- result = (E) NumberHelper.add(result, iterator.next());
- counter++;
+ final Number n = iterator.next();
+ if (n != null) {
+ result = (E) NumberHelper.add(result, n);
+ counter++;
+ }
}
return NumberHelper.div(result, counter, true);
}
throw FastNoSuchElementException.instance();
}
+ private E untilNonNull(final Iterator<E> itty) {
+ E result = null;
+ while (itty.hasNext() && null == result) {
+ result = itty.next();
+ }
+ return result;
+ }
+
@Override
public Set<TraverserRequirement> getRequirements() {
return Collections.singleton(TraverserRequirement.OBJECT);
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinGlobalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinGlobalStep.java
index 781e93d..db6d192 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinGlobalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinGlobalStep.java
@@ -36,7 +36,6 @@ public final class MinGlobalStep<S extends Comparable> extends ReducingBarrierSt
public MinGlobalStep(final Traversal.Admin traversal) {
super(traversal);
- this.setSeedSupplier(new ConstantSupplier<>((S) Double.valueOf(Double.NaN)));
this.setReducingBiOperator((BinaryOperator) Operator.min);
}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumGlobalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumGlobalStep.java
index 3711cfe..21a6187 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumGlobalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumGlobalStep.java
@@ -43,10 +43,23 @@ public final class SumGlobalStep<S extends Number> extends ReducingBarrierStep<S
public SumGlobalStep(final Traversal.Admin traversal) {
super(traversal);
- this.setSeedSupplier(new ConstantSupplier<>((S) Integer.valueOf(0)));
this.setReducingBiOperator((BinaryOperator) Operator.sum);
}
+ /**
+ * Advances the starts until a non-null value is found or simply returns {@code null}. In this way, an all
+ * {@code null} stream will result in {@code null}.
+ */
+ @Override
+ protected S generateSeedFromStarts() {
+ S s = null;
+ while (starts.hasNext() && null == s) {
+ s = projectTraverser(this.starts.next());
+ }
+
+ return s;
+ }
+
@Override
public void processAllStarts() {
if (this.starts.hasNext())
@@ -58,7 +71,6 @@ public final class SumGlobalStep<S extends Number> extends ReducingBarrierStep<S
return (S) mul(traverser.get(), traverser.bulk());
}
-
@Override
public Set<TraverserRequirement> getRequirements() {
return REQUIREMENTS;
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumLocalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumLocalStep.java
index 3249e31..e3284e1 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumLocalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumLocalStep.java
@@ -42,7 +42,8 @@ public final class SumLocalStep<E extends Number, S extends Iterable<E>> extends
protected E map(final Traverser.Admin<S> traverser) {
final Iterator<E> iterator = traverser.get().iterator();
if (iterator.hasNext()) {
- Number result = iterator.next();
+ // forward the iterator to the first non-null or return null
+ Number result = untilNonNull(iterator);
while (iterator.hasNext()) {
result = NumberHelper.add(result, iterator.next());
}
@@ -51,6 +52,14 @@ public final class SumLocalStep<E extends Number, S extends Iterable<E>> extends
throw FastNoSuchElementException.instance();
}
+ private E untilNonNull(final Iterator<E> itty) {
+ E result = null;
+ while (itty.hasNext() && null == result) {
+ result = itty.next();
+ }
+ return result;
+ }
+
@Override
public Set<TraverserRequirement> getRequirements() {
return Collections.singleton(TraverserRequirement.OBJECT);
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ReducingBarrierStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ReducingBarrierStep.java
index 62e12f8..b39576f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ReducingBarrierStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ReducingBarrierStep.java
@@ -24,8 +24,11 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
import org.apache.tinkerpop.gremlin.process.traversal.step.Barrier;
import org.apache.tinkerpop.gremlin.process.traversal.step.Generating;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.SumGlobalStep;
import org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException;
+import java.io.Serializable;
+import java.util.Optional;
import java.util.function.BinaryOperator;
import java.util.function.Supplier;
@@ -34,10 +37,21 @@ import java.util.function.Supplier;
*/
public abstract class ReducingBarrierStep<S, E> extends AbstractStep<S, E> implements Barrier<E>, Generating<E, E> {
- protected Supplier<E> seedSupplier;
+ /**
+ * A seed value not to be emitted from the {@code ReducingBarrierStep} helping with flow control within this step.
+ */
+ public static final Object NON_EMITTING_SEED = NonEmittingSeed.INSTANCE;
+
+ /**
+ * If the {@code seedSupplier} is {@code null} then the default behavior is to generate the seed from the starts.
+ * This supplier must be callable as a constant and not rely on state from the class. Prefer overriding
+ * {@link #generateSeedFromStarts()} otherwise.
+ */
+ protected Supplier<E> seedSupplier = null;
protected BinaryOperator<E> reducingBiOperator;
- private boolean hasProcessedOnce = false;
- private E seed = null;
+ protected boolean hasProcessedOnce = false;
+
+ private E seed = (E) NON_EMITTING_SEED;
public ReducingBarrierStep(final Traversal.Admin traversal) {
super(traversal);
@@ -47,8 +61,18 @@ public abstract class ReducingBarrierStep<S, E> extends AbstractStep<S, E> imple
this.seedSupplier = seedSupplier;
}
+ /**
+ * Gets the provided seed supplier or provides {@link #generateSeedFromStarts()}.
+ */
public Supplier<E> getSeedSupplier() {
- return this.seedSupplier;
+ return Optional.ofNullable(this.seedSupplier).orElse(this::generateSeedFromStarts);
+ }
+
+ /**
+ * If the {@code seedSupplier} is {@code null} then this method is called.
+ */
+ protected E generateSeedFromStarts() {
+ return starts.hasNext() ? projectTraverser(this.starts.next()) : null;
}
public abstract E projectTraverser(final Traverser.Admin<S> traverser);
@@ -64,13 +88,13 @@ public abstract class ReducingBarrierStep<S, E> extends AbstractStep<S, E> imple
public void reset() {
super.reset();
this.hasProcessedOnce = false;
- this.seed = null;
+ this.seed = (E) NON_EMITTING_SEED;
}
@Override
public void done() {
this.hasProcessedOnce = true;
- this.seed = null;
+ this.seed = (E) NON_EMITTING_SEED;
}
@Override
@@ -78,7 +102,11 @@ public abstract class ReducingBarrierStep<S, E> extends AbstractStep<S, E> imple
if (this.hasProcessedOnce && !this.starts.hasNext())
return;
this.hasProcessedOnce = true;
- if (this.seed == null) this.seed = this.seedSupplier.get();
+
+ if (this.seed == NON_EMITTING_SEED) {
+ this.seed = getSeedSupplier().get();
+ }
+
while (this.starts.hasNext())
this.seed = this.reducingBiOperator.apply(this.seed, this.projectTraverser(this.starts.next()));
}
@@ -86,7 +114,7 @@ public abstract class ReducingBarrierStep<S, E> extends AbstractStep<S, E> imple
@Override
public boolean hasNextBarrier() {
this.processAllStarts();
- return null != this.seed;
+ return NON_EMITTING_SEED != this.seed;
}
@Override
@@ -95,14 +123,14 @@ public abstract class ReducingBarrierStep<S, E> extends AbstractStep<S, E> imple
throw FastNoSuchElementException.instance();
else {
final E temp = this.seed;
- this.seed = null;
+ this.seed = (E) NON_EMITTING_SEED;
return temp;
}
}
@Override
public void addBarrier(final E barrier) {
- this.seed = null == this.seed ?
+ this.seed = NON_EMITTING_SEED == this.seed ?
barrier :
this.reducingBiOperator.apply(this.seed, barrier);
}
@@ -110,10 +138,9 @@ public abstract class ReducingBarrierStep<S, E> extends AbstractStep<S, E> imple
@Override
public Traverser.Admin<E> processNextStart() {
this.processAllStarts();
- if (this.seed == null)
- throw FastNoSuchElementException.instance();
+ if (this.seed == NON_EMITTING_SEED) throw FastNoSuchElementException.instance();
final Traverser.Admin<E> traverser = this.getTraversal().getTraverserGenerator().generate(this.generateFinalResult(this.seed), (Step<E, E>) this, 1l);
- this.seed = null;
+ this.seed = (E) NON_EMITTING_SEED;
return traverser;
}
@@ -121,7 +148,7 @@ public abstract class ReducingBarrierStep<S, E> extends AbstractStep<S, E> imple
public ReducingBarrierStep<S, E> clone() {
final ReducingBarrierStep<S, E> clone = (ReducingBarrierStep<S, E>) super.clone();
clone.hasProcessedOnce = false;
- clone.seed = null;
+ clone.seed = (E) NON_EMITTING_SEED;
return clone;
}
@@ -130,4 +157,8 @@ public abstract class ReducingBarrierStep<S, E> extends AbstractStep<S, E> imple
return MemoryComputeKey.of(this.getId(), this.getBiOperator(), false, true);
}
+ public static final class NonEmittingSeed implements Serializable {
+ public static final NonEmittingSeed INSTANCE = new NonEmittingSeed();
+ private NonEmittingSeed() {}
+ }
}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
index eb9566e..f6d06fe 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoVersion.java
@@ -45,6 +45,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.TreeStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ConnectiveStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy;
@@ -335,7 +336,7 @@ public enum GryoVersion {
add(GryoTypeReg.of(HaltedTraverserStrategy.class, 139));
add(GryoTypeReg.of(PartitionStrategy.class, 140, new JavaSerializer()));
add(GryoTypeReg.of(SubgraphStrategy.class, 141, new JavaSerializer()));
- add(GryoTypeReg.of(SeedStrategy.class, 192, new JavaSerializer())); // ***LAST ID***
+ add(GryoTypeReg.of(SeedStrategy.class, 192, new JavaSerializer()));
add(GryoTypeReg.of(VertexProgramStrategy.class, 142, new JavaSerializer()));
add(GryoTypeReg.of(MatchAlgorithmStrategy.class, 143));
add(GryoTypeReg.of(MatchStep.GreedyMatchAlgorithm.class, 144));
@@ -401,6 +402,7 @@ public enum GryoVersion {
add(GryoTypeReg.of(OrderGlobalStep.OrderBiOperator.class, 118));
add(GryoTypeReg.of(ProfileStep.ProfileBiOperator.class, 119));
add(GryoTypeReg.of(IndexedTraverserSet.VertexIndexedTraverserSet.class, 173));
+ add(GryoTypeReg.of(ReducingBarrierStep.NonEmittingSeed.class, 194)); // ***LAST ID***
add(GryoTypeReg.of(B_LP_NL_O_P_S_SE_SL_Traverser.class, 174));
add(GryoTypeReg.of(B_NL_O_S_SE_SL_Traverser.class, 175));
@@ -516,7 +518,7 @@ public enum GryoVersion {
add(GryoTypeReg.of(Bytecode.class, 122, new GryoSerializersV1d0.BytecodeSerializer()));
add(GryoTypeReg.of(P.class, 124, new GryoSerializersV1d0.PSerializer()));
- add(GryoTypeReg.of(TextP.class, 186, new GryoSerializersV1d0.TextPSerializer())); // ***LAST ID***
+ add(GryoTypeReg.of(TextP.class, 186, new GryoSerializersV1d0.TextPSerializer()));
add(GryoTypeReg.of(Lambda.class, 125, new GryoSerializersV1d0.LambdaSerializer()));
add(GryoTypeReg.of(Bytecode.Binding.class, 126, new GryoSerializersV1d0.BindingSerializer()));
add(GryoTypeReg.of(Order.class, 127));
@@ -565,6 +567,8 @@ public enum GryoVersion {
add(GryoTypeReg.of(MeanGlobalStep.MeanGlobalBiOperator.class, 110));
add(GryoTypeReg.of(MeanGlobalStep.MeanNumber.class, 111));
add(GryoTypeReg.of(TreeStep.TreeBiOperator.class, 112));
+ add(GryoTypeReg.of(ReducingBarrierStep.NonEmittingSeed.class, 194)); // ***LAST ID***
+
// skip 113
add(GryoTypeReg.of(RangeGlobalStep.RangeBiOperator.class, 114));
add(GryoTypeReg.of(OrderGlobalStep.OrderBiOperator.class, 118, new JavaSerializer()));
@@ -574,7 +578,7 @@ public enum GryoVersion {
add(GryoTypeReg.of(HaltedTraverserStrategy.class, 139));
add(GryoTypeReg.of(PartitionStrategy.class, 140, new JavaSerializer()));
add(GryoTypeReg.of(SubgraphStrategy.class, 141, new JavaSerializer()));
- add(GryoTypeReg.of(SeedStrategy.class, 192, new JavaSerializer())); // ***LAST ID***
+ add(GryoTypeReg.of(SeedStrategy.class, 192, new JavaSerializer()));
add(GryoTypeReg.of(VertexProgramStrategy.class, 142, new JavaSerializer()));
add(GryoTypeReg.of(MatchAlgorithmStrategy.class, 143));
add(GryoTypeReg.of(MatchStep.GreedyMatchAlgorithm.class, 144));
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/NumberHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/NumberHelper.java
index c457c58..8293195 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/NumberHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/NumberHelper.java
@@ -316,36 +316,127 @@ public final class NumberHelper {
return determineNumberClass(bits, fp);
}
+ /**
+ * Adds two numbers returning the highest common number class between them.
+ *
+ * <pre>
+ * a = 1, b = 1 -> 2
+ * a = null, b = 1 -> null
+ * a = 1, b = null -> 1
+ * a = null, b = null -> null
+ * </pre>
+ *
+ * @param a should be thought of as the seed to be modified by {@code b}
+ * @param b the modifier to {code a}
+ */
public static Number add(final Number a, final Number b) {
+ if (null == a || null == b) return a;
final Class<? extends Number> clazz = getHighestCommonNumberClass(a, b);
return getHelper(clazz).add.apply(a, b);
}
+
+ /**
+ * Subtracts two numbers returning the highest common number class between them.
+ *
+ * <pre>
+ * a = 1, b = 1 -> 0
+ * a = null, b = 1 -> null
+ * a = 1, b = null -> 1
+ * a = null, b = null -> null
+ * </pre>
+ *
+ * @param a should be thought of as the seed to be modified by {@code b}
+ * @param b the modifier to {code a}
+ */
public static Number sub(final Number a, final Number b) {
+ if (null == a || null == b) return a;
final Class<? extends Number> clazz = getHighestCommonNumberClass(a, b);
return getHelper(clazz).sub.apply(a, b);
}
+ /**
+ * Multiplies two numbers returning the highest common number class between them.
+ *
+ * <pre>
+ * a = 1, b = 2 -> 2
+ * a = null, b = 1 -> null
+ * a = 1, b = null -> 1
+ * a = null, b = null -> null
+ * </pre>
+ *
+ * @param a should be thought of as the seed to be modified by {@code b}
+ * @param b the modifier to {code a}
+ */
public static Number mul(final Number a, final Number b) {
+ if (null == a || null == b) return a;
final Class<? extends Number> clazz = getHighestCommonNumberClass(a, b);
return getHelper(clazz).mul.apply(a, b);
}
+ /**
+ * Divides two numbers returning the highest common number class between them calling
+ * {@link #div(Number, Number, boolean)} with a {@code false}.
+ */
public static Number div(final Number a, final Number b) {
+ if (null == a || null == b) return a;
return div(a, b, false);
}
+ /**
+ * Divides two numbers returning the highest common number class between them.
+ *
+ * <pre>
+ * a = 4, b = 2 -> 2
+ * a = null, b = 1 -> null
+ * a = 1, b = null -> 1
+ * a = null, b = null -> null
+ * </pre>
+ *
+ * @param a should be thought of as the seed to be modified by {@code b}
+ * @param b the modifier to {code a}
+ * @param forceFloatingPoint when set to {@code true} ensures that the return value is the highest common floating number class
+ */
public static Number div(final Number a, final Number b, final boolean forceFloatingPoint) {
+ if (null == a || null == b) return null;
final Class<? extends Number> clazz = getHighestCommonNumberClass(forceFloatingPoint, a, b);
return getHelper(clazz).div.apply(a, b);
}
+ /**
+ * Gets the smaller number of the two provided returning the highest common number class between them.
+ *
+ * <pre>
+ * a = 4, b = 2 -> 2
+ * a = null, b = 1 -> 1
+ * a = 1, b = null -> 1
+ * a = null, b = null -> null
+ * </pre>
+ */
public static Number min(final Number a, final Number b) {
+ if (null == a && null == b) return null;
final Class<? extends Number> clazz = getHighestCommonNumberClass(a, b);
return getHelper(clazz).min.apply(a, b);
}
+ /**
+ * Gets the smaller number of the two provided returning the highest common number class between them.
+ *
+ * <pre>
+ * a = 4, b = 2 -> 2
+ * a = null, b = 1 -> 1
+ * a = 1, b = null -> 1
+ * a = null, b = null -> null
+ * </pre>
+ */
public static Comparable min(final Comparable a, final Comparable b) {
+ if (null == a || null == b) {
+ if (null == a && null == b)
+ return null;
+ else
+ return null == a ? b : a;
+ }
+
if (a instanceof Number && b instanceof Number && !a.equals(Double.NaN) && !b.equals(Double.NaN)) {
final Number an = (Number) a, bn = (Number) b;
final Class<? extends Number> clazz = getHighestCommonNumberClass(an, bn);
@@ -356,12 +447,40 @@ public final class NumberHelper {
a.compareTo(b) < 0 ? a : b;
}
+ /**
+ * Gets the larger number of the two provided returning the highest common number class between them.
+ *
+ * <pre>
+ * a = 4, b = 2 -> 4
+ * a = null, b = 1 -> 1
+ * a = 1, b = null -> 1
+ * a = null, b = null -> null
+ * </pre>
+ */
public static Number max(final Number a, final Number b) {
+ if (null == a && null == b) return null;
final Class<? extends Number> clazz = getHighestCommonNumberClass(a, b);
return getHelper(clazz).max.apply(a, b);
}
+ /**
+ * Gets the larger number of the two provided returning the highest common number class between them.
+ *
+ * <pre>
+ * a = 4, b = 2 -> 4
+ * a = null, b = 1 -> 1
+ * a = 1, b = null -> 1
+ * a = null, b = null -> null
+ * </pre>
+ */
public static Comparable max(final Comparable a, final Comparable b) {
+ if (null == a || null == b) {
+ if (null == a && null == b)
+ return null;
+ else
+ return null == a ? b : a;
+ }
+
if (a instanceof Number && b instanceof Number && !a.equals(Double.NaN) && !b.equals(Double.NaN)) {
final Number an = (Number) a, bn = (Number) b;
final Class<? extends Number> clazz = getHighestCommonNumberClass(an, bn);
@@ -372,7 +491,24 @@ public final class NumberHelper {
a.compareTo(b) > 0 ? a : b;
}
+ /**
+ * Compares two numbers.
+ *
+ * <pre>
+ * a = 4, b = 2 -> 1
+ * a = 2, b = 4 -> -1
+ * a = null, b = 1 -> -1
+ * a = 1, b = null -> 1
+ * a = null, b = null -> 0
+ * </pre>
+ */
public static Integer compare(final Number a, final Number b) {
+ if (null == a || null == b) {
+ if (a == b)
+ return 0;
+ else
+ return null == a ? -1 : 1;
+ }
final Class<? extends Number> clazz = getHighestCommonNumberClass(a, b);
return getHelper(clazz).cmp.apply(a, b);
}
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/NumberHelperTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/NumberHelperTest.java
index 8f919d8..01ad1ca 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/NumberHelperTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/NumberHelperTest.java
@@ -36,6 +36,7 @@ import static org.apache.tinkerpop.gremlin.util.NumberHelper.min;
import static org.apache.tinkerpop.gremlin.util.NumberHelper.mul;
import static org.apache.tinkerpop.gremlin.util.NumberHelper.sub;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
@@ -50,49 +51,49 @@ public class NumberHelperTest {
private final static List<Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>> COMMON_NUMBER_CLASSES =
Arrays.asList(
// BYTE
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((byte) 1, (byte) 1, Byte.class, Float.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((byte) 1, (short) 1, Short.class, Float.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((byte) 1, 1, Integer.class, Float.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((byte) 1, 1L, Long.class, Double.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((byte) 1, 1F, Float.class, Float.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((byte) 1, 1D, Double.class, Double.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((byte) 1, BigInteger.ONE, BigInteger.class, BigDecimal.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((byte) 1, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
+ new Quartet<>((byte) 1, (byte) 1, Byte.class, Float.class),
+ new Quartet<>((byte) 1, (short) 1, Short.class, Float.class),
+ new Quartet<>((byte) 1, 1, Integer.class, Float.class),
+ new Quartet<>((byte) 1, 1L, Long.class, Double.class),
+ new Quartet<>((byte) 1, 1F, Float.class, Float.class),
+ new Quartet<>((byte) 1, 1D, Double.class, Double.class),
+ new Quartet<>((byte) 1, BigInteger.ONE, BigInteger.class, BigDecimal.class),
+ new Quartet<>((byte) 1, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
// SHORT
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((short) 1, (short) 1, Short.class, Float.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((short) 1, 1, Integer.class, Float.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((short) 1, 1L, Long.class, Double.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((short) 1, 1F, Float.class, Float.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((short) 1, 1D, Double.class, Double.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((short) 1, BigInteger.ONE, BigInteger.class, BigDecimal.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>((short) 1, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
+ new Quartet<>((short) 1, (short) 1, Short.class, Float.class),
+ new Quartet<>((short) 1, 1, Integer.class, Float.class),
+ new Quartet<>((short) 1, 1L, Long.class, Double.class),
+ new Quartet<>((short) 1, 1F, Float.class, Float.class),
+ new Quartet<>((short) 1, 1D, Double.class, Double.class),
+ new Quartet<>((short) 1, BigInteger.ONE, BigInteger.class, BigDecimal.class),
+ new Quartet<>((short) 1, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
// INTEGER
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1, 1, Integer.class, Float.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1, 1L, Long.class, Double.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1, 1F, Float.class, Float.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1, 1D, Double.class, Double.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1, BigInteger.ONE, BigInteger.class, BigDecimal.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
+ new Quartet<>(1, 1, Integer.class, Float.class),
+ new Quartet<>(1, 1L, Long.class, Double.class),
+ new Quartet<>(1, 1F, Float.class, Float.class),
+ new Quartet<>(1, 1D, Double.class, Double.class),
+ new Quartet<>(1, BigInteger.ONE, BigInteger.class, BigDecimal.class),
+ new Quartet<>(1, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
// LONG
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1L, 1L, Long.class, Double.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1L, 1F, Double.class, Double.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1L, 1D, Double.class, Double.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1L, BigInteger.ONE, BigInteger.class, BigDecimal.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1L, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
+ new Quartet<>(1L, 1L, Long.class, Double.class),
+ new Quartet<>(1L, 1F, Double.class, Double.class),
+ new Quartet<>(1L, 1D, Double.class, Double.class),
+ new Quartet<>(1L, BigInteger.ONE, BigInteger.class, BigDecimal.class),
+ new Quartet<>(1L, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
// FLOAT
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1F, 1F, Float.class, Float.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1F, 1D, Double.class, Double.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1F, BigInteger.ONE, BigDecimal.class, BigDecimal.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1F, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
+ new Quartet<>(1F, 1F, Float.class, Float.class),
+ new Quartet<>(1F, 1D, Double.class, Double.class),
+ new Quartet<>(1F, BigInteger.ONE, BigDecimal.class, BigDecimal.class),
+ new Quartet<>(1F, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
// DOUBLE
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1D, 1D, Double.class, Double.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1D, BigInteger.ONE, BigDecimal.class, BigDecimal.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(1D, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
+ new Quartet<>(1D, 1D, Double.class, Double.class),
+ new Quartet<>(1D, BigInteger.ONE, BigDecimal.class, BigDecimal.class),
+ new Quartet<>(1D, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
// BIG INTEGER
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(BigInteger.ONE, BigInteger.ONE, BigInteger.class, BigDecimal.class),
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(BigInteger.ONE, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
+ new Quartet<>(BigInteger.ONE, BigInteger.ONE, BigInteger.class, BigDecimal.class),
+ new Quartet<>(BigInteger.ONE, BigDecimal.ONE, BigDecimal.class, BigDecimal.class),
// BIG DECIMAL
- new Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>>(BigDecimal.ONE, BigDecimal.ONE, BigDecimal.class, BigDecimal.class)
+ new Quartet<>(BigDecimal.ONE, BigDecimal.ONE, BigDecimal.class, BigDecimal.class)
);
@Test
@@ -113,11 +114,28 @@ public class NumberHelperTest {
}
@Test
+ public void shouldHandleAllNullInput() {
+ assertNull(add(null, null));
+ assertNull(sub(null, null));
+ assertNull(mul(null, null));
+ assertNull(div(null, null));
+ assertNull(max((Number) null, null));
+ assertNull(max((Comparable) null, null));
+ assertNull(min((Number) null, null));
+ assertNull(min((Comparable) null, null));
+ assertEquals(0, compare(null, null).intValue());
+ }
+
+ @Test
public void shouldAddAndReturnCorrectType() {
// NOTE: The smallest possible number type for return values is Integer; this seems to be a JVM thing and has
// nothing to do with the actual NumberHelper implementation
+ // the above NOTE isn't quite true - TINKERPOP-2610
+ assertEquals((byte) 1, add((byte) 1, (Byte) null));
+ assertNull(add((Byte) null, (byte) 1));
+
// BYTE
assertEquals(2, add((byte) 1, (byte) 1));
assertEquals(2, add((byte) 1, (short) 1));
@@ -177,6 +195,10 @@ public class NumberHelperTest {
// NOTE: The smallest possible number type for return values is Integer; this seems to be a JVM thing and has
// nothing to do with the actual NumberHelper implementation
+ // the above NOTE isn't quite true - TINKERPOP-2610
+ assertEquals((byte) 1, sub((byte) 1, (Byte) null));
+ assertNull(sub((Byte) null, (byte) 1));
+
// BYTE
assertEquals(0, sub((byte) 1, (byte) 1));
assertEquals(0, sub((byte) 1, (short) 1));
@@ -236,6 +258,10 @@ public class NumberHelperTest {
// NOTE: The smallest possible number type for return values is Integer; this seems to be a JVM thing and has
// nothing to do with the actual NumberHelper implementation
+ // the above NOTE isn't quite true - TINKERPOP-2610
+ assertEquals((byte) 1, mul((byte) 1, (Byte) null));
+ assertNull(mul((Byte) null, (byte) 1));
+
// BYTE
assertEquals(1, mul((byte) 1, (byte) 1));
assertEquals(1, mul((byte) 1, (short) 1));
@@ -295,6 +321,10 @@ public class NumberHelperTest {
// NOTE: The smallest possible number type for return values is Integer; this seems to be a JVM thing and has
// nothing to do with the actual NumberHelper implementation
+ // the above NOTE isn't quite true - TINKERPOP-2610
+ assertEquals((byte) 1, div((byte) 1, (Byte) null));
+ assertNull(div((Byte) null, (byte) 1));
+
// BYTE
assertEquals(1, div((byte) 1, (byte) 1));
assertEquals(1, div((byte) 1, (short) 1));
@@ -425,5 +455,15 @@ public class NumberHelperTest {
assertTrue(compare(one, one) == 0);
}
}
+
+ for (Number one : ones) {
+ assertEquals(1, min(null, one).intValue());
+ assertEquals(1, min(one, null).intValue());
+ assertEquals(1, max(null, one).intValue());
+ assertEquals(1, max(one, null).intValue());
+
+ assertEquals(-1, compare(null, one).intValue());
+ assertEquals(1, compare(one, null).intValue());
+ }
}
}
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
index c3a67b0..ce33709 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
@@ -46,11 +46,16 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
// Add here the name of scenarios to ignore and the reason, e.g.:
{"g_V_group_byXageX", IgnoreReason.NullKeysInMapNotSupported},
- // expect to fix the following before 3.5.0 release. they are not failing as a result of the Gremlin
- // itself - they are failing because of shortcomings in the test suite.
+ // they are not failing as a result of the Gremlin itself - they are failing because of shortcomings in
+ // the test suite.
// https://issues.apache.org/jira/browse/TINKERPOP-2518
{"g_withSackX0X_V_outE_sackXsumX_byXweightX_inV_sack_sum", IgnoreReason.NoReason},
+ {"g_V_aggregateXaX_byXageX_capXaX_unfold_sum", IgnoreReason.NoReason},
{"g_withSackX0X_V_repeatXoutE_sackXsumX_byXweightX_inVX_timesX2X_sack", IgnoreReason.NoReason},
+ {"g_injectXlistXnull_10_20_nullXX_meanXlocalX", IgnoreReason.NoReason},
+ {"g_injectXnull_10_20_nullX_mean", IgnoreReason.NoReason},
+ {"g_injectXnull_10_5_nullX_sum", IgnoreReason.NoReason},
+ {"g_injectXlistXnull_10_5_nullXX_sumXlocalX", IgnoreReason.NoReason},
{
"g_withBulkXfalseX_withSackX1_sumX_VX1X_localXoutEXknowsX_barrierXnormSackX_inVX_inXknowsX_barrier_sack",
IgnoreReason.NoReason
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
index a3966da..cc043f2 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
@@ -432,6 +432,10 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
{"g_V_foo_max", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("foo").Max<object>()}},
{"g_V_name_max", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("name").Max<object>()}},
{"g_V_age_fold_maxXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("age").Fold().Max<object>(Scope.Local)}},
+ {"g_V_aggregateXaX_byXageX_capXaX_maxXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("age").Cap<object>("a").Max<object>(Scope.Local)}},
+ {"g_V_aggregateXaX_byXageX_capXaX_unfold_max", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("age").Cap<object>("a").Unfold<object>().Max<object>()}},
+ {"g_V_aggregateXaX_byXfooX_capXaX_maxXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("foo").Cap<object>("a").Max<object>(Scope.Local)}},
+ {"g_V_aggregateXaX_byXfooX_capXaX_unfold_max", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("foo").Cap<object>("a").Unfold<object>().Max<object>()}},
{"g_V_foo_fold_maxXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("foo").Fold().Max<object>(Scope.Local)}},
{"g_V_name_fold_maxXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("name").Fold().Max<object>(Scope.Local)}},
{"g_V_repeatXbothX_timesX5X_age_max", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Repeat(__.Both()).Times(5).Values<object>("age").Max<object>()}},
@@ -441,10 +445,20 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
{"g_V_age_fold_meanXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("age").Fold().Mean<object>(Scope.Local)}},
{"g_V_foo_fold_meanXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("foo").Fold().Mean<object>(Scope.Local)}},
{"g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_meanX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().HasLabel("software").Group<object,object>().By("name").By(__.BothE().Values<object>("weight").Mean<object>())}},
+ {"g_V_aggregateXaX_byXageX_meanXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("age").Cap<object>("a").Mean<object>(Scope.Local)}},
+ {"g_V_aggregateXaX_byXageX_capXaX_unfold_mean", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("age").Cap<object>("a").Unfold<object>().Mean<object>()}},
+ {"g_V_aggregateXaX_byXfooX_meanXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("foo").Cap<object>("a").Mean<object>(Scope.Local)}},
+ {"g_V_aggregateXaX_byXfooX_capXaX_unfold_mean", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("foo").Cap<object>("a").Unfold<object>().Mean<object>()}},
+ {"g_injectXnull_10_20_nullX_mean", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject<object>(null,p["xx1"],p["xx2"],null).Mean<object>()}},
+ {"g_injectXlistXnull_10_20_nullXX_meanXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject(p["xx1"]).Mean<object>(Scope.Local)}},
{"g_V_age_min", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("age").Min<object>()}},
{"g_V_foo_min", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("foo").Min<object>()}},
{"g_V_name_min", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("name").Min<object>()}},
{"g_V_age_fold_minXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("age").Fold().Min<object>(Scope.Local)}},
+ {"g_V_aggregateXaX_byXageX_capXaX_minXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("age").Cap<object>("a").Min<object>(Scope.Local)}},
+ {"g_V_aggregateXaX_byXageX_capXaX_unfold_min", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("age").Cap<object>("a").Unfold<object>().Min<object>()}},
+ {"g_V_aggregateXaX_byXfooX_capXaX_minXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("foo").Cap<object>("a").Min<object>(Scope.Local)}},
+ {"g_V_aggregateXaX_byXfooX_capXaX_unfold_min", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("foo").Cap<object>("a").Unfold<object>().Min<object>()}},
{"g_V_foo_fold_minXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("foo").Fold().Min<object>(Scope.Local)}},
{"g_V_name_fold_minXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("name").Fold().Min<object>(Scope.Local)}},
{"g_V_repeatXbothX_timesX5X_age_min", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Repeat(__.Both()).Times(5).Values<object>("age").Min<object>()}},
@@ -583,6 +597,12 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
{"g_V_age_fold_sumXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("age").Fold().Sum<object>(Scope.Local)}},
{"g_V_foo_fold_sumXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("foo").Fold().Sum<object>(Scope.Local)}},
{"g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_sumX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().HasLabel("software").Group<object,object>().By("name").By(__.BothE().Values<object>("weight").Sum<object>())}},
+ {"g_V_aggregateXaX_byXageX_sumXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("age").Cap<object>("a").Sum<object>(Scope.Local)}},
+ {"g_V_aggregateXaX_byXageX_capXaX_unfold_sum", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("age").Cap<object>("a").Unfold<object>().Sum<object>()}},
+ {"g_V_aggregateXaX_byXfooX_sumXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("foo").Cap<object>("a").Sum<object>(Scope.Local)}},
+ {"g_V_aggregateXaX_byXfooX_capXaX_unfold_sum", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Aggregate("a").By("foo").Cap<object>("a").Unfold<object>().Sum<object>()}},
+ {"g_injectXnull_10_5_nullX_sum", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject<object>(null,p["xx1"],p["xx2"],null).Sum<object>()}},
+ {"g_injectXlistXnull_10_5_nullXX_sumXlocalX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject(p["xx1"]).Sum<object>(Scope.Local)}},
{"g_V_localXoutE_foldX_unfold", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Local<object>(__.OutE().Fold()).Unfold<object>()}},
{"g_V_valueMap_unfold_mapXkeyX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().ValueMap<object,object>().Unfold<object>().Map<object>((IFunction) p["l1"])}},
{"g_VX1X_repeatXboth_simplePathX_untilXhasIdX6XX_path_byXnameX_unfold", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p["vid1"]).Repeat(__.Both().SimplePath()).Until(__.HasId(p["vid6"])).Path().By("name").Unfold<object>()}},
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
index d0aa270..7548afe 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
@@ -421,6 +421,10 @@ const gremlins = {
g_V_foo_max: [function({g}) { return g.V().values("foo").max() }],
g_V_name_max: [function({g}) { return g.V().values("name").max() }],
g_V_age_fold_maxXlocalX: [function({g}) { return g.V().values("age").fold().max(Scope.local) }],
+ g_V_aggregateXaX_byXageX_capXaX_maxXlocalX: [function({g}) { return g.V().aggregate("a").by("age").cap("a").max(Scope.local) }],
+ g_V_aggregateXaX_byXageX_capXaX_unfold_max: [function({g}) { return g.V().aggregate("a").by("age").cap("a").unfold().max() }],
+ g_V_aggregateXaX_byXfooX_capXaX_maxXlocalX: [function({g}) { return g.V().aggregate("a").by("foo").cap("a").max(Scope.local) }],
+ g_V_aggregateXaX_byXfooX_capXaX_unfold_max: [function({g}) { return g.V().aggregate("a").by("foo").cap("a").unfold().max() }],
g_V_foo_fold_maxXlocalX: [function({g}) { return g.V().values("foo").fold().max(Scope.local) }],
g_V_name_fold_maxXlocalX: [function({g}) { return g.V().values("name").fold().max(Scope.local) }],
g_V_repeatXbothX_timesX5X_age_max: [function({g}) { return g.V().repeat(__.both()).times(5).values("age").max() }],
@@ -430,10 +434,20 @@ const gremlins = {
g_V_age_fold_meanXlocalX: [function({g}) { return g.V().values("age").fold().mean(Scope.local) }],
g_V_foo_fold_meanXlocalX: [function({g}) { return g.V().values("foo").fold().mean(Scope.local) }],
g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_meanX: [function({g}) { return g.V().hasLabel("software").group().by("name").by(__.bothE().values("weight").mean()) }],
+ g_V_aggregateXaX_byXageX_meanXlocalX: [function({g}) { return g.V().aggregate("a").by("age").cap("a").mean(Scope.local) }],
+ g_V_aggregateXaX_byXageX_capXaX_unfold_mean: [function({g}) { return g.V().aggregate("a").by("age").cap("a").unfold().mean() }],
+ g_V_aggregateXaX_byXfooX_meanXlocalX: [function({g}) { return g.V().aggregate("a").by("foo").cap("a").mean(Scope.local) }],
+ g_V_aggregateXaX_byXfooX_capXaX_unfold_mean: [function({g}) { return g.V().aggregate("a").by("foo").cap("a").unfold().mean() }],
+ g_injectXnull_10_20_nullX_mean: [function({g, xx1, xx2}) { return g.inject(null,xx1,xx2,null).mean() }],
+ g_injectXlistXnull_10_20_nullXX_meanXlocalX: [function({g, xx1}) { return g.inject(xx1).mean(Scope.local) }],
g_V_age_min: [function({g}) { return g.V().values("age").min() }],
g_V_foo_min: [function({g}) { return g.V().values("foo").min() }],
g_V_name_min: [function({g}) { return g.V().values("name").min() }],
g_V_age_fold_minXlocalX: [function({g}) { return g.V().values("age").fold().min(Scope.local) }],
+ g_V_aggregateXaX_byXageX_capXaX_minXlocalX: [function({g}) { return g.V().aggregate("a").by("age").cap("a").min(Scope.local) }],
+ g_V_aggregateXaX_byXageX_capXaX_unfold_min: [function({g}) { return g.V().aggregate("a").by("age").cap("a").unfold().min() }],
+ g_V_aggregateXaX_byXfooX_capXaX_minXlocalX: [function({g}) { return g.V().aggregate("a").by("foo").cap("a").min(Scope.local) }],
+ g_V_aggregateXaX_byXfooX_capXaX_unfold_min: [function({g}) { return g.V().aggregate("a").by("foo").cap("a").unfold().min() }],
g_V_foo_fold_minXlocalX: [function({g}) { return g.V().values("foo").fold().min(Scope.local) }],
g_V_name_fold_minXlocalX: [function({g}) { return g.V().values("name").fold().min(Scope.local) }],
g_V_repeatXbothX_timesX5X_age_min: [function({g}) { return g.V().repeat(__.both()).times(5).values("age").min() }],
@@ -572,6 +586,12 @@ const gremlins = {
g_V_age_fold_sumXlocalX: [function({g}) { return g.V().values("age").fold().sum(Scope.local) }],
g_V_foo_fold_sumXlocalX: [function({g}) { return g.V().values("foo").fold().sum(Scope.local) }],
g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_sumX: [function({g}) { return g.V().hasLabel("software").group().by("name").by(__.bothE().values("weight").sum()) }],
+ g_V_aggregateXaX_byXageX_sumXlocalX: [function({g}) { return g.V().aggregate("a").by("age").cap("a").sum(Scope.local) }],
+ g_V_aggregateXaX_byXageX_capXaX_unfold_sum: [function({g}) { return g.V().aggregate("a").by("age").cap("a").unfold().sum() }],
+ g_V_aggregateXaX_byXfooX_sumXlocalX: [function({g}) { return g.V().aggregate("a").by("foo").cap("a").sum(Scope.local) }],
+ g_V_aggregateXaX_byXfooX_capXaX_unfold_sum: [function({g}) { return g.V().aggregate("a").by("foo").cap("a").unfold().sum() }],
+ g_injectXnull_10_5_nullX_sum: [function({g, xx1, xx2}) { return g.inject(null,xx1,xx2,null).sum() }],
+ g_injectXlistXnull_10_5_nullXX_sumXlocalX: [function({g, xx1}) { return g.inject(xx1).sum(Scope.local) }],
g_V_localXoutE_foldX_unfold: [function({g}) { return g.V().local(__.outE().fold()).unfold() }],
g_V_valueMap_unfold_mapXkeyX: [function({g, l1}) { return g.V().valueMap().unfold().map(l1) }],
g_VX1X_repeatXboth_simplePathX_untilXhasIdX6XX_path_byXnameX_unfold: [function({g, vid6, vid1}) { return g.V(vid1).repeat(__.both().simplePath()).until(__.hasId(vid6)).path().by("name").unfold() }],
diff --git a/gremlin-python/src/main/python/radish/gremlin.py b/gremlin-python/src/main/python/radish/gremlin.py
index 317a387..b4e6d81 100644
--- a/gremlin-python/src/main/python/radish/gremlin.py
+++ b/gremlin-python/src/main/python/radish/gremlin.py
@@ -406,6 +406,10 @@ world.gremlins = {
'g_V_foo_max': [(lambda g:g.V().foo.max())],
'g_V_name_max': [(lambda g:g.V().name.max())],
'g_V_age_fold_maxXlocalX': [(lambda g:g.V().age.fold().max(Scope.local))],
+ 'g_V_aggregateXaX_byXageX_capXaX_maxXlocalX': [(lambda g:g.V().aggregate('a').by('age').cap('a').max(Scope.local))],
+ 'g_V_aggregateXaX_byXageX_capXaX_unfold_max': [(lambda g:g.V().aggregate('a').by('age').cap('a').unfold().max())],
+ 'g_V_aggregateXaX_byXfooX_capXaX_maxXlocalX': [(lambda g:g.V().aggregate('a').by('foo').cap('a').max(Scope.local))],
+ 'g_V_aggregateXaX_byXfooX_capXaX_unfold_max': [(lambda g:g.V().aggregate('a').by('foo').cap('a').unfold().max())],
'g_V_foo_fold_maxXlocalX': [(lambda g:g.V().foo.fold().max(Scope.local))],
'g_V_name_fold_maxXlocalX': [(lambda g:g.V().name.fold().max(Scope.local))],
'g_V_repeatXbothX_timesX5X_age_max': [(lambda g:g.V().repeat(__.both()).times(5).age.max())],
@@ -415,10 +419,20 @@ world.gremlins = {
'g_V_age_fold_meanXlocalX': [(lambda g:g.V().age.fold().mean(Scope.local))],
'g_V_foo_fold_meanXlocalX': [(lambda g:g.V().foo.fold().mean(Scope.local))],
'g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_meanX': [(lambda g:g.V().hasLabel('software').group().by('name').by(__.bothE().weight.mean()))],
+ 'g_V_aggregateXaX_byXageX_meanXlocalX': [(lambda g:g.V().aggregate('a').by('age').cap('a').mean(Scope.local))],
+ 'g_V_aggregateXaX_byXageX_capXaX_unfold_mean': [(lambda g:g.V().aggregate('a').by('age').cap('a').unfold().mean())],
+ 'g_V_aggregateXaX_byXfooX_meanXlocalX': [(lambda g:g.V().aggregate('a').by('foo').cap('a').mean(Scope.local))],
+ 'g_V_aggregateXaX_byXfooX_capXaX_unfold_mean': [(lambda g:g.V().aggregate('a').by('foo').cap('a').unfold().mean())],
+ 'g_injectXnull_10_20_nullX_mean': [(lambda g, xx1=None,xx2=None:g.inject(None,xx1,xx2,None).mean())],
+ 'g_injectXlistXnull_10_20_nullXX_meanXlocalX': [(lambda g, xx1=None:g.inject(xx1).mean(Scope.local))],
'g_V_age_min': [(lambda g:g.V().age.min())],
'g_V_foo_min': [(lambda g:g.V().foo.min())],
'g_V_name_min': [(lambda g:g.V().name.min())],
'g_V_age_fold_minXlocalX': [(lambda g:g.V().age.fold().min(Scope.local))],
+ 'g_V_aggregateXaX_byXageX_capXaX_minXlocalX': [(lambda g:g.V().aggregate('a').by('age').cap('a').min(Scope.local))],
+ 'g_V_aggregateXaX_byXageX_capXaX_unfold_min': [(lambda g:g.V().aggregate('a').by('age').cap('a').unfold().min())],
+ 'g_V_aggregateXaX_byXfooX_capXaX_minXlocalX': [(lambda g:g.V().aggregate('a').by('foo').cap('a').min(Scope.local))],
+ 'g_V_aggregateXaX_byXfooX_capXaX_unfold_min': [(lambda g:g.V().aggregate('a').by('foo').cap('a').unfold().min())],
'g_V_foo_fold_minXlocalX': [(lambda g:g.V().foo.fold().min(Scope.local))],
'g_V_name_fold_minXlocalX': [(lambda g:g.V().name.fold().min(Scope.local))],
'g_V_repeatXbothX_timesX5X_age_min': [(lambda g:g.V().repeat(__.both()).times(5).age.min())],
@@ -557,6 +571,12 @@ world.gremlins = {
'g_V_age_fold_sumXlocalX': [(lambda g:g.V().age.fold().sum(Scope.local))],
'g_V_foo_fold_sumXlocalX': [(lambda g:g.V().foo.fold().sum(Scope.local))],
'g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_sumX': [(lambda g:g.V().hasLabel('software').group().by('name').by(__.bothE().weight.sum()))],
+ 'g_V_aggregateXaX_byXageX_sumXlocalX': [(lambda g:g.V().aggregate('a').by('age').cap('a').sum(Scope.local))],
+ 'g_V_aggregateXaX_byXageX_capXaX_unfold_sum': [(lambda g:g.V().aggregate('a').by('age').cap('a').unfold().sum())],
+ 'g_V_aggregateXaX_byXfooX_sumXlocalX': [(lambda g:g.V().aggregate('a').by('foo').cap('a').sum(Scope.local))],
+ 'g_V_aggregateXaX_byXfooX_capXaX_unfold_sum': [(lambda g:g.V().aggregate('a').by('foo').cap('a').unfold().sum())],
+ 'g_injectXnull_10_5_nullX_sum': [(lambda g, xx1=None,xx2=None:g.inject(None,xx1,xx2,None).sum())],
+ 'g_injectXlistXnull_10_5_nullXX_sumXlocalX': [(lambda g, xx1=None:g.inject(xx1).sum(Scope.local))],
'g_V_localXoutE_foldX_unfold': [(lambda g:g.V().local(__.outE().fold()).unfold())],
'g_V_valueMap_unfold_mapXkeyX': [(lambda g, l1=None:g.V().valueMap().unfold().map(l1))],
'g_VX1X_repeatXboth_simplePathX_untilXhasIdX6XX_path_byXnameX_unfold': [(lambda g, vid6=None,vid1=None:g.V(vid1).repeat(__.both().simplePath()).until(__.hasId(vid6)).path().by('name').unfold())],
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/GraphBinaryRemoteGraphComputerProvider.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/GraphBinaryRemoteGraphComputerProvider.java
index e938ce1..54ab3df 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/GraphBinaryRemoteGraphComputerProvider.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/GraphBinaryRemoteGraphComputerProvider.java
@@ -90,7 +90,23 @@ import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComp
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesTest",
method = "g_injectXg_VX1X_propertiesXnameX_nextX_value",
- reason = "Needs investigation")
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.SumTest",
+ method = "g_injectXnull_10_5_nullX_sum",
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.SumTest",
+ method = "g_injectXlistXnull_10_5_nullXX_sumXlocalX",
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.MeanTest",
+ method = "g_injectXlistXnull_10_20_nullXX_meanXlocalX",
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.MeanTest",
+ method = "g_injectXnull_10_20_nullX_mean",
+ reason = "The inject() step is not supported by GraphComputer")
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.ReadTest",
method = "*",
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/GraphSONRemoteGraphComputerProvider.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/GraphSONRemoteGraphComputerProvider.java
index b9b251d..2678738 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/GraphSONRemoteGraphComputerProvider.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/GraphSONRemoteGraphComputerProvider.java
@@ -90,7 +90,23 @@ import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComp
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesTest",
method = "g_injectXg_VX1X_propertiesXnameX_nextX_value",
- reason = "Needs investigation")
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.SumTest",
+ method = "g_injectXnull_10_5_nullX_sum",
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.SumTest",
+ method = "g_injectXlistXnull_10_5_nullXX_sumXlocalX",
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.MeanTest",
+ method = "g_injectXlistXnull_10_20_nullXX_meanXlocalX",
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.MeanTest",
+ method = "g_injectXnull_10_20_nullX_mean",
+ reason = "The inject() step is not supported by GraphComputer")
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.ReadTest",
method = "*",
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/GryoRemoteGraphComputerProvider.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/GryoRemoteGraphComputerProvider.java
index 032e845..3d5c510 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/GryoRemoteGraphComputerProvider.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/driver/remote/GryoRemoteGraphComputerProvider.java
@@ -91,7 +91,23 @@ import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComp
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesTest",
method = "g_injectXg_VX1X_propertiesXnameX_nextX_value",
- reason = "Needs investigation")
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.SumTest",
+ method = "g_injectXnull_10_5_nullX_sum",
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.SumTest",
+ method = "g_injectXlistXnull_10_5_nullXX_sumXlocalX",
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.MeanTest",
+ method = "g_injectXlistXnull_10_20_nullXX_meanXlocalX",
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.MeanTest",
+ method = "g_injectXnull_10_20_nullX_mean",
+ reason = "The inject() step is not supported by GraphComputer")
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.ReadTest",
method = "*",
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GryoRemoteGraphGroovyTranslatorComputerProvider.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GryoRemoteGraphGroovyTranslatorComputerProvider.java
index a049904..01b3a21 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GryoRemoteGraphGroovyTranslatorComputerProvider.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GryoRemoteGraphGroovyTranslatorComputerProvider.java
@@ -93,7 +93,23 @@ import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComp
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesTest",
method = "g_injectXg_VX1X_propertiesXnameX_nextX_value",
- reason = "Needs investigation")
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.SumTest",
+ method = "g_injectXnull_10_5_nullX_sum",
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.SumTest",
+ method = "g_injectXlistXnull_10_5_nullXX_sumXlocalX",
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.MeanTest",
+ method = "g_injectXlistXnull_10_20_nullXX_meanXlocalX",
+ reason = "The inject() step is not supported by GraphComputer")
+@Graph.OptOut(
+ test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.MeanTest",
+ method = "g_injectXnull_10_20_nullX_mean",
+ reason = "The inject() step is not supported by GraphComputer")
@Graph.OptOut(
test = "org.apache.tinkerpop.gremlin.process.traversal.step.map.ReadTest",
method = "*",
diff --git a/gremlin-test/features/map/Max.feature b/gremlin-test/features/map/Max.feature
index 44d9640..4288563 100644
--- a/gremlin-test/features/map/Max.feature
+++ b/gremlin-test/features/map/Max.feature
@@ -59,6 +59,50 @@ Feature: Step - max()
| result |
| d[35].i |
+ Scenario: g_V_aggregateXaX_byXageX_capXaX_maxXlocalX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("age").cap("a").max(Scope.local)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[35].i |
+
+ Scenario: g_V_aggregateXaX_byXageX_capXaX_unfold_max
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("age").cap("a").unfold().max()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[35].i |
+
+ Scenario: g_V_aggregateXaX_byXfooX_capXaX_maxXlocalX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("foo").cap("a").max(Scope.local)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | null |
+
+ Scenario: g_V_aggregateXaX_byXfooX_capXaX_unfold_max
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("foo").cap("a").unfold().max()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | null |
+
Scenario: g_V_foo_fold_maxXlocalX
Given the modern graph
And the traversal of
diff --git a/gremlin-test/features/map/Mean.feature b/gremlin-test/features/map/Mean.feature
index dc28ecb..5e01db1 100644
--- a/gremlin-test/features/map/Mean.feature
+++ b/gremlin-test/features/map/Mean.feature
@@ -67,3 +67,76 @@ Feature: Step - mean()
Then the result should be unordered
| result |
| m[{"ripple":"d[1.0].d","lop":"d[0.3333333333333333].d"}] |
+
+ # null values are ignored in mean() which is similar to sum aggregation works in SQL
+ Scenario: g_V_aggregateXaX_byXageX_meanXlocalX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("age").cap("a").mean(Scope.local)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[30.75].d |
+
+ # null values are ignored in mean() which is similar to sum aggregation works in SQL
+ Scenario: g_V_aggregateXaX_byXageX_capXaX_unfold_mean
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("age").cap("a").unfold().mean()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[30.75].d |
+
+ # if all values are null then the result is null
+ Scenario: g_V_aggregateXaX_byXfooX_meanXlocalX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("foo").cap("a").mean(Scope.local)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | null |
+
+ # if all values are null then the result is null
+ Scenario: g_V_aggregateXaX_byXfooX_capXaX_unfold_mean
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("foo").cap("a").unfold().mean()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | null |
+
+ Scenario: g_injectXnull_10_20_nullX_mean
+ Given the modern graph
+ And using the parameter xx1 defined as "d[10].i"
+ And using the parameter xx2 defined as "d[20].i"
+ And the traversal of
+ """
+ g.inject(null, xx1, xx2, null).mean()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[15].i |
+
+ Scenario: g_injectXlistXnull_10_20_nullXX_meanXlocalX
+ Given the modern graph
+ And using the parameter xx1 defined as "l[null,d[10].i,d[20].i,null]"
+ And the traversal of
+ """
+ g.inject(xx1).mean(local)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[15].i |
\ No newline at end of file
diff --git a/gremlin-test/features/map/Min.feature b/gremlin-test/features/map/Min.feature
index ad866ec..8d90a64 100644
--- a/gremlin-test/features/map/Min.feature
+++ b/gremlin-test/features/map/Min.feature
@@ -59,6 +59,50 @@ Feature: Step - min()
| result |
| d[27].i |
+ Scenario: g_V_aggregateXaX_byXageX_capXaX_minXlocalX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("age").cap("a").min(Scope.local)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[27].i |
+
+ Scenario: g_V_aggregateXaX_byXageX_capXaX_unfold_min
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("age").cap("a").unfold().min()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[27].i |
+
+ Scenario: g_V_aggregateXaX_byXfooX_capXaX_minXlocalX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("foo").cap("a").min(Scope.local)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | null |
+
+ Scenario: g_V_aggregateXaX_byXfooX_capXaX_unfold_min
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("foo").cap("a").unfold().min()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | null |
+
Scenario: g_V_foo_fold_minXlocalX
Given the modern graph
And the traversal of
diff --git a/gremlin-test/features/map/Sum.feature b/gremlin-test/features/map/Sum.feature
index 0e20368..50c5c16 100644
--- a/gremlin-test/features/map/Sum.feature
+++ b/gremlin-test/features/map/Sum.feature
@@ -67,3 +67,76 @@ Feature: Step - sum()
Then the result should be unordered
| result |
| m[{"ripple":"d[1.0].d","lop":"d[1.0].d"}] |
+
+ # null values are ignored in sum() which is similar to sum aggregation works in SQL
+ Scenario: g_V_aggregateXaX_byXageX_sumXlocalX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("age").cap("a").sum(Scope.local)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[123].i |
+
+ # null values are ignored in sum() which is similar to sum aggregation works in SQL
+ Scenario: g_V_aggregateXaX_byXageX_capXaX_unfold_sum
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("age").cap("a").unfold().sum()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[123].i |
+
+ # if all values are null then the result is null
+ Scenario: g_V_aggregateXaX_byXfooX_sumXlocalX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("foo").cap("a").sum(Scope.local)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | null |
+
+ # if all values are null then the result is null
+ Scenario: g_V_aggregateXaX_byXfooX_capXaX_unfold_sum
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().aggregate("a").by("foo").cap("a").unfold().sum()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | null |
+
+ Scenario: g_injectXnull_10_5_nullX_sum
+ Given the modern graph
+ And using the parameter xx1 defined as "d[10].i"
+ And using the parameter xx2 defined as "d[5].i"
+ And the traversal of
+ """
+ g.inject(null, xx1, xx2, null).sum()
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[15].i |
+
+ Scenario: g_injectXlistXnull_10_5_nullXX_sumXlocalX
+ Given the modern graph
+ And using the parameter xx1 defined as "l[null,d[10].i,d[5].i,null]"
+ And the traversal of
+ """
+ g.inject(xx1).sum(local)
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[15].i |
\ No newline at end of file
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/GremlinProcessRunner.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/GremlinProcessRunner.java
index b70f303..0cda9fa 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/GremlinProcessRunner.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/GremlinProcessRunner.java
@@ -73,8 +73,8 @@ public class GremlinProcessRunner extends BlockJUnit4ClassRunner {
// for remote tests ex will be a IllegalStateException holding a VerificationException or only have a
// string message to compare on
if (ex instanceof VerificationException || ex.getCause() instanceof VerificationException ||
- ex.getMessage().contains("It is not possible to access more than a path element's id on GraphComputer") ||
- ex.getMessage().contains("Local traversals may not traverse past the local star-graph on GraphComputer"))
+ (ex.getMessage() != null && (ex.getMessage().contains("It is not possible to access more than a path element's id on GraphComputer") ||
+ ex.getMessage().contains("Local traversals may not traverse past the local star-graph on GraphComputer"))))
return true;
else if (ex instanceof NotSerializableException)
return true;
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxTest.java
index 1ddd859..bb85fa2 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MaxTest.java
@@ -35,6 +35,7 @@ import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.both;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.bothE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
@@ -47,6 +48,14 @@ public abstract class MaxTest extends AbstractGremlinProcessTest {
public abstract Traversal<Vertex, Integer> get_g_V_age_fold_maxXlocalX();
+ public abstract Traversal<Vertex, Integer> get_g_V_aggregateXaX_byXageX_capXaX_maxXlocalX();
+
+ public abstract Traversal<Vertex, Integer> get_g_V_aggregateXaX_byXageX_capXaX_unfold_max();
+
+ public abstract Traversal<Vertex, Comparable> get_g_V_aggregateXaX_byXfooX_capXaX_maxXlocalX();
+
+ public abstract Traversal<Vertex, Comparable> get_g_V_aggregateXaX_byXfooX_capXaX_unfold_max();
+
public abstract Traversal<Vertex, Comparable> get_g_V_foo_max();
public abstract Traversal<Vertex, Comparable> get_g_V_foo_fold_maxXlocalX();
@@ -77,6 +86,40 @@ public abstract class MaxTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXageX_capXaX_maxXlocalX() {
+ final Traversal<Vertex, Integer> traversal = get_g_V_aggregateXaX_byXageX_capXaX_maxXlocalX();
+ printTraversalForm(traversal);
+ checkResults(Arrays.asList(35), traversal);
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXageX_capXaX_unfold_max() {
+ final Traversal<Vertex, Integer> traversal = get_g_V_aggregateXaX_byXageX_capXaX_unfold_max();
+ printTraversalForm(traversal);
+ checkResults(Arrays.asList(35), traversal);
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXfooX_capXaX_maxXlocalX() {
+ final Traversal<Vertex, Comparable> traversal = get_g_V_aggregateXaX_byXfooX_capXaX_maxXlocalX();
+ printTraversalForm(traversal);
+ assertNull(traversal.next());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXfooX_capXaX_unfold_max() {
+ final Traversal<Vertex, Comparable> traversal = get_g_V_aggregateXaX_byXfooX_capXaX_unfold_max();
+ printTraversalForm(traversal);
+ assertNull(traversal.next());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
public void g_V_foo_max() {
final Traversal<Vertex, Comparable> traversal = get_g_V_foo_max();
printTraversalForm(traversal);
@@ -136,11 +179,31 @@ public abstract class MaxTest extends AbstractGremlinProcessTest {
}
@Override
+ public Traversal<Vertex, Comparable> get_g_V_aggregateXaX_byXfooX_capXaX_maxXlocalX() {
+ return g.V().aggregate("a").by("foo").cap("a").max(Scope.local);
+ }
+
+ @Override
+ public Traversal<Vertex, Comparable> get_g_V_aggregateXaX_byXfooX_capXaX_unfold_max() {
+ return g.V().aggregate("a").by("foo").cap("a").unfold().max();
+ }
+
+ @Override
public Traversal<Vertex, Integer> get_g_V_age_fold_maxXlocalX() {
return g.V().values("age").fold().max(Scope.local);
}
@Override
+ public Traversal<Vertex, Integer> get_g_V_aggregateXaX_byXageX_capXaX_maxXlocalX() {
+ return g.V().aggregate("a").by("age").cap("a").max(Scope.local);
+ }
+
+ @Override
+ public Traversal<Vertex, Integer> get_g_V_aggregateXaX_byXageX_capXaX_unfold_max() {
+ return g.V().aggregate("aaazzz").by("age").cap("aaazzz").unfold().max();
+ }
+
+ @Override
public Traversal<Vertex, Comparable> get_g_V_foo_max() {
return g.V().values("foo").max();
}
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanTest.java
index cb2aac4..0908646 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MeanTest.java
@@ -28,12 +28,14 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Arrays;
+import java.util.List;
import java.util.Map;
import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.bothE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
@@ -52,6 +54,18 @@ public abstract class MeanTest extends AbstractGremlinProcessTest {
public abstract Traversal<Vertex, Map<String, Number>> get_g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_meanX();
+ public abstract Traversal<Vertex, Double> get_g_V_aggregateXaX_byXageX_meanXlocalX();
+
+ public abstract Traversal<Vertex, Double> get_g_V_aggregateXaX_byXageX_capXaX_unfold_mean();
+
+ public abstract Traversal<Vertex, Double> get_g_V_aggregateXaX_byXfooX_meanXlocalX();
+
+ public abstract Traversal<Vertex, Double> get_g_V_aggregateXaX_byXfooX_capXaX_unfold_mean();
+
+ public abstract Traversal<Integer, Double> get_g_injectXnull_10_20_nullX_mean();
+
+ public abstract Traversal<List<Integer>, Double> get_g_injectXlistXnull_10_20_nullXX_meanXlocalX();
+
@Test
@LoadGraphWith(MODERN)
public void g_V_age_mean() {
@@ -74,6 +88,24 @@ public abstract class MeanTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXfooX_meanXlocalX() {
+ final Traversal<Vertex, Double> traversal = get_g_V_aggregateXaX_byXfooX_meanXlocalX();
+ printTraversalForm(traversal);
+ assertNull(traversal.next());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXfooX_capXaX_unfold_mean() {
+ final Traversal<Vertex, Double> traversal = get_g_V_aggregateXaX_byXfooX_capXaX_unfold_mean();
+ printTraversalForm(traversal);
+ assertNull(traversal.next());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
public void g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_meanX() {
final Traversal<Vertex, Map<String, Number>> traversal = get_g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_meanX();
printTraversalForm(traversal);
@@ -85,6 +117,37 @@ public abstract class MeanTest extends AbstractGremlinProcessTest {
assertEquals(1.0 / 3, map.get("lop"));
}
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXageX_meanXlocalX() {
+ for (final Traversal<Vertex, Double> traversal : Arrays.asList(get_g_V_aggregateXaX_byXageX_capXaX_unfold_mean(), get_g_V_aggregateXaX_byXageX_meanXlocalX())) {
+ printTraversalForm(traversal);
+ final Double mean = traversal.next();
+ assertEquals(30.75, mean, 0.05);
+ assertFalse(traversal.hasNext());
+ }
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_injectXnull_10_20_nullX_mean() {
+ final Traversal<Integer, Double> traversal = get_g_injectXnull_10_20_nullX_mean();
+ printTraversalForm(traversal);
+ final Double mean = traversal.next();
+ assertEquals(15.00, mean, 0.05);
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_injectXlistXnull_10_20_nullXX_meanXlocalX() {
+ final Traversal<List<Integer>, Double> traversal = get_g_injectXlistXnull_10_20_nullXX_meanXlocalX();
+ printTraversalForm(traversal);
+ final Double mean = traversal.next();
+ assertEquals(15.00, mean, 0.05);
+ assertFalse(traversal.hasNext());
+ }
+
public static class Traversals extends MeanTest {
@Override
@@ -93,6 +156,16 @@ public abstract class MeanTest extends AbstractGremlinProcessTest {
}
@Override
+ public Traversal<Vertex, Double> get_g_V_aggregateXaX_byXfooX_meanXlocalX() {
+ return g.V().aggregate("a").by("foo").cap("a").mean(Scope.local);
+ }
+
+ @Override
+ public Traversal<Vertex, Double> get_g_V_aggregateXaX_byXfooX_capXaX_unfold_mean() {
+ return g.V().aggregate("a").by("foo").cap("a").unfold().mean();
+ }
+
+ @Override
public Traversal<Vertex, Double> get_g_V_age_fold_meanXlocalX() {
return g.V().values("age").fold().mean(Scope.local);
}
@@ -111,5 +184,25 @@ public abstract class MeanTest extends AbstractGremlinProcessTest {
public Traversal<Vertex, Map<String, Number>> get_g_V_hasLabelXsoftwareX_group_byXnameX_byXbothE_weight_meanX() {
return g.V().hasLabel("software").<String, Number>group().by("name").by(bothE().values("weight").mean());
}
+
+ @Override
+ public Traversal<Vertex, Double> get_g_V_aggregateXaX_byXageX_meanXlocalX() {
+ return g.V().aggregate("a").by("age").cap("a").mean(Scope.local);
+ }
+
+ @Override
+ public Traversal<Vertex, Double> get_g_V_aggregateXaX_byXageX_capXaX_unfold_mean() {
+ return g.V().aggregate("a").by("age").cap("a").unfold().mean();
+ }
+
+ @Override
+ public Traversal<Integer, Double> get_g_injectXnull_10_20_nullX_mean() {
+ return g.inject(null, 10, 20, null).mean();
+ }
+
+ @Override
+ public Traversal<List<Integer>, Double> get_g_injectXlistXnull_10_20_nullXX_meanXlocalX() {
+ return g.inject(Arrays.asList(null, 10, 20, null)).mean(Scope.local);
+ }
}
}
\ No newline at end of file
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinTest.java
index d4a13b8..51c2e2a 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MinTest.java
@@ -35,6 +35,7 @@ import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.both;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.bothE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
@@ -47,6 +48,14 @@ public abstract class MinTest extends AbstractGremlinProcessTest {
public abstract Traversal<Vertex, Integer> get_g_V_age_fold_minXlocalX();
+ public abstract Traversal<Vertex, Integer> get_g_V_aggregateXaX_byXageX_capXaX_minXlocalX();
+
+ public abstract Traversal<Vertex, Integer> get_g_V_aggregateXaX_byXageX_capXaX_unfold_min();
+
+ public abstract Traversal<Vertex, Comparable> get_g_V_aggregateXaX_byXfooX_capXaX_minXlocalX();
+
+ public abstract Traversal<Vertex, Comparable> get_g_V_aggregateXaX_byXfooX_capXaX_unfold_min();
+
public abstract Traversal<Vertex, Comparable> get_g_V_foo_min();
public abstract Traversal<Vertex, Comparable> get_g_V_foo_fold_minXlocalX();
@@ -79,6 +88,22 @@ public abstract class MinTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXageX_capXaX_minXlocalX() {
+ final Traversal<Vertex, Integer> traversal = get_g_V_aggregateXaX_byXageX_capXaX_minXlocalX();
+ printTraversalForm(traversal);
+ checkResults(Arrays.asList(27), traversal);
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXageX_capXaX_unfold_min() {
+ final Traversal<Vertex, Integer> traversal = get_g_V_aggregateXaX_byXageX_capXaX_unfold_min();
+ printTraversalForm(traversal);
+ checkResults(Arrays.asList(27), traversal);
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
public void g_V_foo_min() {
final Traversal<Vertex, Comparable> traversal = get_g_V_foo_min();
printTraversalForm(traversal);
@@ -103,6 +128,24 @@ public abstract class MinTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXfooX_capXaX_minXlocalX() {
+ final Traversal<Vertex, Comparable> traversal = get_g_V_aggregateXaX_byXfooX_capXaX_minXlocalX();
+ printTraversalForm(traversal);
+ assertNull(traversal.next());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXfooX_capXaX_unfold_min() {
+ final Traversal<Vertex, Comparable> traversal = get_g_V_aggregateXaX_byXfooX_capXaX_unfold_min();
+ printTraversalForm(traversal);
+ assertNull(traversal.next());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
public void g_V_name_fold_minXlocalX() {
final Traversal<Vertex, String> traversal = get_g_V_name_fold_minXlocalX();
printTraversalForm(traversal);
@@ -148,6 +191,16 @@ public abstract class MinTest extends AbstractGremlinProcessTest {
}
@Override
+ public Traversal<Vertex, Comparable> get_g_V_aggregateXaX_byXfooX_capXaX_minXlocalX() {
+ return g.V().aggregate("a").by("foo").cap("a").min(Scope.local);
+ }
+
+ @Override
+ public Traversal<Vertex, Comparable> get_g_V_aggregateXaX_byXfooX_capXaX_unfold_min() {
+ return g.V().aggregate("a").by("foo").cap("a").unfold().min();
+ }
+
+ @Override
public Traversal<Vertex, Integer> get_g_V_age_fold_minXlocalX() {
return g.V().values("age").fold().min(Scope.local);
}
@@ -173,6 +226,16 @@ public abstract class MinTest extends AbstractGremlinProcessTest {
}
@Override
+ public Traversal<Vertex, Integer> get_g_V_aggregateXaX_byXageX_capXaX_minXlocalX() {
+ return g.V().aggregate("a").by("age").cap("a").min(Scope.local);
+ }
+
+ @Override
+ public Traversal<Vertex, Integer> get_g_V_aggregateXaX_byXageX_capXaX_unfold_min() {
+ return g.V().aggregate("a").by("age").cap("a").unfold().min();
+ }
+
+ @Override
public Traversal<Vertex, Integer> get_g_V_repeatXbothX_timesX5X_age_min() {
return g.V().repeat(both()).times(5).values("age").min();
}
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumTest.java
index bd981c1..6d45fed 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SumTest.java
@@ -27,12 +27,15 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Test;
import org.junit.runner.RunWith;
+import java.util.Arrays;
+import java.util.List;
import java.util.Map;
import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.bothE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
@@ -43,6 +46,18 @@ public abstract class SumTest extends AbstractGremlinProcessTest {
public abstract Traversal<Vertex, Number> get_g_V_age_sum();
+ public abstract Traversal<Vertex, Number> get_g_V_aggregateXaX_byXageX_sumXlocalX();
+
+ public abstract Traversal<Vertex, Number> get_g_V_aggregateXaX_byXfooX_sumXlocalX();
+
+ public abstract Traversal<Vertex, Number> get_g_V_aggregateXaX_byXageX_capXaX_unfold_sum();
+
+ public abstract Traversal<Integer, Number> get_g_injectXnull_10_5_nullX_sum();
+
+ public abstract Traversal<List<Integer>, Number> get_g_injectXlistXnull_10_5_nullXX_sumXlocalX();
+
+ public abstract Traversal<Vertex, Number> get_g_V_aggregateXaX_byXfooX_capXaX_unfold_sum();
+
public abstract Traversal<Vertex, Number> get_g_V_age_fold_sumXlocalX();
public abstract Traversal<Vertex, Number> get_g_V_foo_sum();
@@ -62,6 +77,62 @@ public abstract class SumTest extends AbstractGremlinProcessTest {
}
@Test
+ public void g_injectXnull_10_5_nullX_sum() {
+ final Traversal<Integer, Number> traversal = get_g_injectXnull_10_5_nullX_sum();
+ printTraversalForm(traversal);
+ final Number sum = traversal.next();
+ assertEquals(15, sum.intValue());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ public void g_injectXlistXnull_10_5_nullXX_sumXlocalX() {
+ final Traversal<List<Integer>, Number> traversal = get_g_injectXlistXnull_10_5_nullXX_sumXlocalX();
+ printTraversalForm(traversal);
+ final Number sum = traversal.next();
+ assertEquals(15, sum.intValue());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXageX_sumXlocalX() {
+ final Traversal<Vertex, Number> traversal = get_g_V_aggregateXaX_byXageX_sumXlocalX();
+ printTraversalForm(traversal);
+ final Number sum = traversal.next();
+ assertEquals(123, sum.intValue());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXageX_capXaX_unfold_sum() {
+ final Traversal<Vertex, Number> traversal = get_g_V_aggregateXaX_byXageX_capXaX_unfold_sum();
+ printTraversalForm(traversal);
+ final Number sum = traversal.next();
+ assertEquals(123, sum.intValue());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXfooX_sumXlocalX() {
+ final Traversal<Vertex, Number> traversal = get_g_V_aggregateXaX_byXfooX_sumXlocalX();
+ printTraversalForm(traversal);
+ assertNull(traversal.next());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_aggregateXaX_byXfooX_capXaX_unfold_sum() {
+ final Traversal<Vertex, Number> traversal = get_g_V_aggregateXaX_byXfooX_capXaX_unfold_sum();
+ printTraversalForm(traversal);
+ assertNull(traversal.next());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
@LoadGraphWith(MODERN)
public void g_V_age_fold_sumXlocalX() {
final Traversal<Vertex, Number> traversal = get_g_V_age_fold_sumXlocalX();
@@ -108,6 +179,35 @@ public abstract class SumTest extends AbstractGremlinProcessTest {
}
@Override
+ public Traversal<Integer, Number> get_g_injectXnull_10_5_nullX_sum() {
+ return g.inject(null, 10, 5, null).sum();
+ }
+ @Override
+ public Traversal<List<Integer>, Number> get_g_injectXlistXnull_10_5_nullXX_sumXlocalX() {
+ return g.inject(Arrays.asList(null, 10, 5, null)).sum(Scope.local);
+ }
+
+ @Override
+ public Traversal<Vertex, Number> get_g_V_aggregateXaX_byXageX_sumXlocalX() {
+ return g.V().aggregate("a").by("age").cap("a").sum(Scope.local);
+ }
+
+ @Override
+ public Traversal<Vertex, Number> get_g_V_aggregateXaX_byXageX_capXaX_unfold_sum() {
+ return g.V().aggregate("a").by("age").cap("a").unfold().sum();
+ }
+
+ @Override
+ public Traversal<Vertex, Number> get_g_V_aggregateXaX_byXfooX_sumXlocalX() {
+ return g.V().aggregate("a").by("foo").cap("a").sum(Scope.local);
+ }
+
+ @Override
+ public Traversal<Vertex, Number> get_g_V_aggregateXaX_byXfooX_capXaX_unfold_sum() {
+ return g.V().aggregate("a").by("foo").cap("a").unfold().sum();
+ }
+
+ @Override
public Traversal<Vertex, Number> get_g_V_age_fold_sumXlocalX() {
return g.V().values("age").fold().sum(Scope.local);
}
diff --git a/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkMemory.java b/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkMemory.java
index 5a04162..9f9a4a9 100644
--- a/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkMemory.java
+++ b/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkMemory.java
@@ -167,6 +167,5 @@ public final class SparkMemory implements Memory.Admin, Serializable {
private void checkKeyValue(final String key, final Object value) {
if (!this.memoryComputeKeys.containsKey(key))
throw GraphComputer.Exceptions.providedKeyIsNotAMemoryComputeKey(key);
- MemoryHelper.validateValue(value);
}
}
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMemory.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMemory.java
index 1502d84..f577c26 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMemory.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMemory.java
@@ -29,6 +29,7 @@ import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
@@ -41,13 +42,14 @@ import java.util.stream.Collectors;
public final class TinkerMemory implements Memory.Admin {
public final Map<String, MemoryComputeKey> memoryKeys = new HashMap<>();
- public Map<String, Object> previousMap;
- public Map<String, Object> currentMap;
+ public Map<String, Optional<Object>> previousMap;
+ public Map<String, Optional<Object>> currentMap;
private final AtomicInteger iteration = new AtomicInteger(0);
private final AtomicLong runtime = new AtomicLong(0l);
private boolean inExecute = false;
public TinkerMemory(final VertexProgram<?> vertexProgram, final Set<MapReduce> mapReducers) {
+ // ConcurrentHashMap makes us use Optional since you cant store null in them as values (or keys)
this.currentMap = new ConcurrentHashMap<>();
this.previousMap = new ConcurrentHashMap<>();
if (null != vertexProgram) {
@@ -108,10 +110,11 @@ public final class TinkerMemory implements Memory.Admin {
@Override
public <R> R get(final String key) throws IllegalArgumentException {
- final R r = (R) this.previousMap.get(key);
- if (null == r)
- throw Memory.Exceptions.memoryDoesNotExist(key);
- else if (this.inExecute && !this.memoryKeys.get(key).isBroadcast())
+ if (!this.previousMap.containsKey(key)) throw Memory.Exceptions.memoryDoesNotExist(key);
+
+ final Optional<Object> o = this.previousMap.get(key);
+ final R r = (R) o.orElse(null);
+ if (this.inExecute && !this.memoryKeys.get(key).isBroadcast())
throw Memory.Exceptions.memoryDoesNotExist(key);
else
return r;
@@ -122,7 +125,7 @@ public final class TinkerMemory implements Memory.Admin {
checkKeyValue(key, value);
if (this.inExecute)
throw Memory.Exceptions.memorySetOnlyDuringVertexProgramSetUpAndTerminate(key);
- this.currentMap.put(key, value);
+ this.currentMap.put(key, Optional.ofNullable(value));
}
@Override
@@ -130,7 +133,7 @@ public final class TinkerMemory implements Memory.Admin {
checkKeyValue(key, value);
if (!this.inExecute)
throw Memory.Exceptions.memoryAddOnlyDuringVertexProgramExecute(key);
- this.currentMap.compute(key, (k, v) -> null == v ? value : this.memoryKeys.get(key).getReducer().apply(v, value));
+ this.currentMap.compute(key, (k, v) -> Optional.ofNullable(null == v || !v.isPresent() ? value : this.memoryKeys.get(key).getReducer().apply(v.get(), value)));
}
@Override
@@ -141,6 +144,6 @@ public final class TinkerMemory implements Memory.Admin {
protected void checkKeyValue(final String key, final Object value) {
if (!this.memoryKeys.containsKey(key))
throw GraphComputer.Exceptions.providedKeyIsNotAMemoryComputeKey(key);
- MemoryHelper.validateValue(value);
+ //MemoryHelper.validateValue(value);
}
}
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java
index 6121ef7..e7a6c16 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java
@@ -42,7 +42,8 @@ public class TinkerGraphComputerProvider extends TinkerGraphProvider {
@Override
public GraphTraversalSource traversal(final Graph graph) {
return graph.traversal().withStrategies(VertexProgramStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
- put(VertexProgramStrategy.WORKERS, RANDOM.nextInt(Runtime.getRuntime().availableProcessors()) + 1);
+ put(VertexProgramStrategy.WORKERS, 1);
+ //put(VertexProgramStrategy.WORKERS, RANDOM.nextInt(Runtime.getRuntime().availableProcessors()) + 1);
put(VertexProgramStrategy.GRAPH_COMPUTER, RANDOM.nextBoolean() ?
GraphComputer.class.getCanonicalName() :
TinkerGraphComputer.class.getCanonicalName());
[tinkerpop] 03/10: TINKERPOP-2605 Added test to validate dedup()
grabbing the first item it encounters
Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2605
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit e9329ebfd2b033e29bed9470ca25db649dbe8ad2
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Tue Aug 24 10:29:50 2021 -0400
TINKERPOP-2605 Added test to validate dedup() grabbing the first item it encounters
Also better validates null returned from dedup().by()
---
gremlin-test/features/filter/Dedup.feature | 21 +++++++++++++++++++-
.../process/traversal/step/filter/DedupTest.java | 23 ++++++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/gremlin-test/features/filter/Dedup.feature b/gremlin-test/features/filter/Dedup.feature
index c157ac7..a85dcfc 100644
--- a/gremlin-test/features/filter/Dedup.feature
+++ b/gremlin-test/features/filter/Dedup.feature
@@ -283,4 +283,23 @@ Feature: Step - dedup()
When iterated to list
Then the result should be unordered
| result |
- | d[21].l |
\ No newline at end of file
+ | d[21].l |
+
+ # ensures that dedup() returns the first item encountered. the ordering supplied will put "ripple" in front of
+ # "lop" and make it the first to hit dedup() and as "age" is not a property of either of those only "ripple" will
+ # win. the barrier() is required to trick out FilterRankingStrategy which will optimize the traversal placing the
+ # dedup() prior to the order() and sorta ruin the test semantics
+ Scenario: g_V_order_byXname_descX_barrier_dedup_age_name
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().order().by("name",desc).barrier().dedup().by("age").values("name")
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | vadas |
+ | ripple |
+ | peter |
+ | marko |
+ | josh |
\ No newline at end of file
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/DedupTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/DedupTest.java
index c36d10d..35bb75e 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/DedupTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/DedupTest.java
@@ -64,6 +64,8 @@ import static org.junit.Assert.fail;
public abstract class DedupTest extends AbstractGremlinProcessTest {
public abstract Traversal<Vertex, String> get_g_V_both_dedup_name();
+
+ public abstract Traversal<Vertex, String> get_g_V_order_byXname_descX_barrier_dedup_age_name();
public abstract Traversal<Vertex, String> get_g_V_both_hasXlabel_softwareX_dedup_byXlangX_name();
@@ -143,6 +145,22 @@ public abstract class DedupTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
+ @IgnoreEngine(TraversalEngine.Type.COMPUTER)
+ public void g_V_order_byXname_descX_barrier_dedup_age_name() {
+ final Traversal<Vertex, String> traversal = get_g_V_order_byXname_descX_barrier_dedup_age_name();
+ printTraversalForm(traversal);
+ final List<String> names = traversal.toList();
+ assertEquals(5, names.size());
+ assertTrue(names.contains("marko"));
+ assertTrue(names.contains("vadas"));
+ assertTrue(names.contains("josh"));
+ assertTrue(names.contains("ripple"));
+ assertTrue(names.contains("peter"));
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
public void g_V_both_hasXlabel_softwareX_dedup_byXlangX_name() {
final Traversal<Vertex, String> traversal = get_g_V_both_hasXlabel_softwareX_dedup_byXlangX_name();
printTraversalForm(traversal);
@@ -384,6 +402,11 @@ public abstract class DedupTest extends AbstractGremlinProcessTest {
}
@Override
+ public Traversal<Vertex, String> get_g_V_order_byXname_descX_barrier_dedup_age_name() {
+ return g.V().order().by("name", Order.desc).barrier().dedup().by("age").values("name");
+ }
+
+ @Override
public Traversal<Vertex, String> get_g_V_both_hasXlabel_softwareX_dedup_byXlangX_name() {
return g.V().both().has(T.label, "software").dedup().by("lang").values("name");
}
[tinkerpop] 06/10: TINKERPOP-2605 Added test for select() where
by() produces null
Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2605
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 24c70cf03e8a000cffc408cbafbcdd37bbfa57df
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Tue Aug 24 13:12:11 2021 -0400
TINKERPOP-2605 Added test for select() where by() produces null
---
.../Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs | 1 +
.../gremlin-javascript/test/cucumber/gremlin.js | 1 +
gremlin-python/src/main/python/radish/gremlin.py | 1 +
gremlin-test/features/map/Select.feature | 18 +++++++++++++++++-
.../gremlin/process/traversal/step/map/SelectTest.java | 15 +++++++++++++++
5 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
index fe23a6f..f9567a0 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
@@ -560,6 +560,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
{"g_V_hasXperson_name_markoX_path_asXaX_unionXidentity_identityX_selectXaX_unfold", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has("person","name","marko").Path().As("a").Union<object>(__.Identity(),__.Identity()).Select<object>("a").Unfold<object>()}},
{"g_EX11X_propertiesXweightX_asXaX_selectXaX_byXkeyX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.E(p["eid11"]).Properties<object>("weight").As("a").Select<object>("a").By(T.Key)}},
{"g_EX11X_propertiesXweightX_asXaX_selectXaX_byXvalueX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.E(p["eid11"]).Properties<object>("weight").As("a").Select<object>("a").By(T.Value)}},
+ {"g_V_asXaX_selectXaX_byXageX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().As("a").Select<object>("a").By("age")}},
{"g_V_shortestPath", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.WithStrategies(new VertexProgramStrategy(graphComputer: "org.apache.tinkerpop.gremlin.process.computer.GraphComputer")).V().Identity().ShortestPath()}},
{"g_V_both_dedup_shortestPath", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.WithStrategies(new VertexProgramStrategy(graphComputer: "org.apache.tinkerpop.gremlin.process.computer.GraphComputer")).V().Both().Dedup().ShortestPath()}},
{"g_V_shortestPath_edgesIncluded", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.WithStrategies(new VertexProgramStrategy(graphComputer: "org.apache.tinkerpop.gremlin.process.computer.GraphComputer")).V().Identity().ShortestPath().With("~tinkerpop.shortestPath.includeEdges")}},
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
index 5bda6d9..13a5a24 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
@@ -549,6 +549,7 @@ const gremlins = {
g_V_hasXperson_name_markoX_path_asXaX_unionXidentity_identityX_selectXaX_unfold: [function({g}) { return g.V().has("person","name","marko").path().as("a").union(__.identity(),__.identity()).select("a").unfold() }],
g_EX11X_propertiesXweightX_asXaX_selectXaX_byXkeyX: [function({g, eid11}) { return g.E(eid11).properties("weight").as("a").select("a").by(T.key) }],
g_EX11X_propertiesXweightX_asXaX_selectXaX_byXvalueX: [function({g, eid11}) { return g.E(eid11).properties("weight").as("a").select("a").by(T.value) }],
+ g_V_asXaX_selectXaX_byXageX: [function({g}) { return g.V().as("a").select("a").by("age") }],
g_V_shortestPath: [function({g}) { return g.withStrategies(new VertexProgramStrategy(new Map([["graphComputer","org.apache.tinkerpop.gremlin.process.computer.GraphComputer"]]))).V().identity().shortestPath() }],
g_V_both_dedup_shortestPath: [function({g}) { return g.withStrategies(new VertexProgramStrategy(new Map([["graphComputer","org.apache.tinkerpop.gremlin.process.computer.GraphComputer"]]))).V().both().dedup().shortestPath() }],
g_V_shortestPath_edgesIncluded: [function({g}) { return g.withStrategies(new VertexProgramStrategy(new Map([["graphComputer","org.apache.tinkerpop.gremlin.process.computer.GraphComputer"]]))).V().identity().shortestPath().with_("~tinkerpop.shortestPath.includeEdges") }],
diff --git a/gremlin-python/src/main/python/radish/gremlin.py b/gremlin-python/src/main/python/radish/gremlin.py
index 69379ec..3974ce9 100644
--- a/gremlin-python/src/main/python/radish/gremlin.py
+++ b/gremlin-python/src/main/python/radish/gremlin.py
@@ -534,6 +534,7 @@ world.gremlins = {
'g_V_hasXperson_name_markoX_path_asXaX_unionXidentity_identityX_selectXaX_unfold': [(lambda g:g.V().has('person','name','marko').path().as_('a').union(__.identity(),__.identity()).select('a').unfold())],
'g_EX11X_propertiesXweightX_asXaX_selectXaX_byXkeyX': [(lambda g, eid11=None:g.E(eid11).properties('weight').as_('a').select('a').by(T.key))],
'g_EX11X_propertiesXweightX_asXaX_selectXaX_byXvalueX': [(lambda g, eid11=None:g.E(eid11).properties('weight').as_('a').select('a').by(T.value))],
+ 'g_V_asXaX_selectXaX_byXageX': [(lambda g:g.V().as_('a').select('a').by('age'))],
'g_V_shortestPath': [(lambda g:g.withStrategies(*[TraversalStrategy('VertexProgramStrategy',{'graphComputer':'org.apache.tinkerpop.gremlin.process.computer.GraphComputer'}, 'org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy')]).V().identity().shortestPath())],
'g_V_both_dedup_shortestPath': [(lambda g:g.withStrategies(*[TraversalStrategy('VertexProgramStrategy',{'graphComputer':'org.apache.tinkerpop.gremlin.process.computer.GraphComputer'}, 'org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy')]).V().both().dedup().shortestPath())],
'g_V_shortestPath_edgesIncluded': [(lambda g:g.withStrategies(*[TraversalStrategy('VertexProgramStrategy',{'graphComputer':'org.apache.tinkerpop.gremlin.process.computer.GraphComputer'}, 'org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy')]).V().identity().shortestPath().with_('~tinkerpop.shortestPath.includeEdges'))],
diff --git a/gremlin-test/features/map/Select.feature b/gremlin-test/features/map/Select.feature
index c0002f2..3169e0e 100644
--- a/gremlin-test/features/map/Select.feature
+++ b/gremlin-test/features/map/Select.feature
@@ -814,4 +814,20 @@ Feature: Step - select()
When iterated to list
Then the result should be unordered
| result |
- | d[0.4].d |
\ No newline at end of file
+ | d[0.4].d |
+
+ Scenario: g_V_asXaX_selectXaX_byXageX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().as("a").select("a").by("age")
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | d[29].i |
+ | d[27].i |
+ | null |
+ | d[32].i |
+ | null |
+ | d[35].i |
\ No newline at end of file
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java
index cd274d0..f6c8d12 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java
@@ -94,6 +94,8 @@ public abstract class SelectTest extends AbstractGremlinProcessTest {
public abstract Traversal<Vertex, Long> get_g_V_selectXaX_count();
+ public abstract Traversal<Vertex, Object> get_g_V_asXaX_selectXaX_byXageX();
+
// below are original back()-tests
public abstract Traversal<Vertex, Vertex> get_g_VX1X_asXhereX_out_selectXhereX(final Object v1Id);
@@ -886,6 +888,14 @@ public abstract class SelectTest extends AbstractGremlinProcessTest {
checkResults(Arrays.asList(convertToVertex(graph, "marko"), convertToVertex(graph, "marko")), traversal);
}
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_asXaX_selectXaX_byXageX() {
+ final Traversal<Vertex, Object> traversal = get_g_V_asXaX_selectXaX_byXageX();
+ printTraversalForm(traversal);
+ checkResults(Arrays.asList(29, 27, null, 32, null, 35), traversal);
+ }
+
public static class Traversals extends SelectTest {
@Override
public Traversal<Vertex, Map<String, Vertex>> get_g_VX1X_asXaX_outXknowsX_asXbX_selectXa_bX(final Object v1Id) {
@@ -1209,5 +1219,10 @@ public abstract class SelectTest extends AbstractGremlinProcessTest {
public Traversal<Vertex, Vertex> get_g_V_hasXperson_name_markoX_path_asXaX_unionXidentity_identityX_selectXaX_unfold() {
return g.V().has("person","name","marko").path().as("a").union(identity(),identity()).select("a").unfold();
}
+
+ @Override
+ public Traversal<Vertex, Object> get_g_V_asXaX_selectXaX_byXageX() {
+ return g.V().as("a").select("a").by("age");
+ }
}
}
[tinkerpop] 04/10: TINKERPOP-2605 Added tests for path() where by()
can produce null
Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2605
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit c159c53346116b47c0ceb7f6da6e61fe8f72dfd4
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Tue Aug 24 11:53:55 2021 -0400
TINKERPOP-2605 Added tests for path() where by() can produce null
---
.../Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs | 3 +++
.../gremlin-javascript/test/cucumber/gremlin.js | 3 +++
gremlin-python/src/main/python/radish/gremlin.py | 3 +++
gremlin-test/features/map/Path.feature | 14 ++++++++++
.../process/traversal/step/map/PathTest.java | 31 +++++++++++++++++++---
5 files changed, 51 insertions(+), 3 deletions(-)
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
index 0e1ae90..cdebd15 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
@@ -151,6 +151,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
{"g_V_bothE_properties_dedup_count", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().BothE().Properties<object>().Dedup().Count()}},
{"g_V_both_properties_dedup_count", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Both().Properties<object>().Dedup().Count()}},
{"g_V_both_properties_properties_dedup_count", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Both().Properties<object>().Properties<object>().Dedup().Count()}},
+ {"g_V_order_byXname_descX_barrier_dedup_age_name", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Order().By("name",Order.Desc).Barrier().Dedup().By("age").Values<object>("name")}},
{"g_V_drop", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.AddV().As("a").AddV().As("b").AddE("knows").To("a"), (g,p) =>g.V().Drop(), (g,p) =>g.V(), (g,p) =>g.E()}},
{"g_V_outE_drop", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.AddV().As("a").AddV().As("b").AddE("knows").To("a"), (g,p) =>g.V().OutE().Drop(), (g,p) =>g.V(), (g,p) =>g.E()}},
{"g_V_properties_drop", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.AddV().Property("name","bob").AddV().Property("name","alice"), (g,p) =>g.V().Properties<object>().Drop(), (g,p) =>g.V(), (g,p) =>g.V().Properties<object>()}},
@@ -466,6 +467,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
{"g_V_both_hasLabelXpersonX_order_byXage_descX_name", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Both().HasLabel("person").Order().By("age",Order.Desc).Values<object>("name")}},
{"g_V_order_byXoutE_count_descX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Order().By(__.OutE().Count(),Order.Desc)}},
{"g_V_hasLabelXpersonX_order_byXageX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().HasLabel("person").Order().By("age")}},
+ {"g_V_orXhasLabelXpersonX_hasXsoftware_name_lopXX_order_byXageX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Or(__.HasLabel("person"),__.Has("software","name","lop")).Order().By("age")}},
{"g_VX1X_hasXlabel_personX_mapXmapXint_ageXX_orderXlocalX_byXvalues_descX_byXkeys_ascX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V((Vertex) p["v1"]).HasLabel("person").Map<object>((IFunction) p["l1"]).Order(Scope.Local).By(Column.Values,Order.Desc).By(Column.Keys,Order.Asc)}},
{"g_VX1X_elementMap_orderXlocalX_byXkeys_descXunfold", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p["vid1"]).ElementMap<object>().Order(Scope.Local).By(Column.Keys,Order.Desc).Unfold<object>()}},
{"g_V_pageRank_hasXpageRankX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.WithStrategies(new VertexProgramStrategy(graphComputer: "org.apache.tinkerpop.gremlin.process.computer.GraphComputer")).V().PageRank().Has("gremlin.pageRankVertexProgram.pageRank"), (g,p) =>g.WithStrategies(new VertexProgramStrategy(graphComputer: "org.apache.tinkerpop.gremlin.process.computer.GraphComputer")).V().PageRank().Has("gremlin.pageRankVertexPro [...]
@@ -484,6 +486,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
{"g_V_asXaX_hasXname_markoX_asXbX_hasXage_29X_asXcX_path", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().As("a").Has("name","marko").As("b").Has("age",29).As("c").Path()}},
{"g_VX1X_outEXcreatedX_inV_inE_outV_path", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p["vid1"]).OutE("created").InV().InE().OutV().Path()}},
{"g_V_asXaX_out_asXbX_out_asXcX_path_fromXbX_toXcX_byXnameX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().As("a").Out().As("b").Out().As("c").Path().From("b").To("c").By("name")}},
+ {"g_VX1X_out_path_byXageX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p["vid1"]).Out().Path().By("age")}},
{"g_V_peerPressure_hasXclusterX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.WithStrategies(new VertexProgramStrategy(graphComputer: "org.apache.tinkerpop.gremlin.process.computer.GraphComputer")).V().PeerPressure().Has("gremlin.peerPressureVertexProgram.cluster"), (g,p) =>g.WithStrategies(new VertexProgramStrategy(graphComputer: "org.apache.tinkerpop.gremlin.process.computer.GraphComputer")).V().PeerPressure().Has("gremlin.pee [...]
{"g_V_peerPressure_withXpropertyName_clusterX_withXedges_outEXknowsXX_pageRankX1X_byXrankX_withXedges_outEXknowsX_withXtimes_2X_group_byXclusterX_byXrank_sumX_limitX100X", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.WithStrategies(new VertexProgramStrategy(graphComputer: "org.apache.tinkerpop.gremlin.process.computer.GraphComputer")).V().PeerPressure().With("~tinkerpop.peerPressure.propertyName","cluster").With("~tinkerpop.peerP [...]
{"g_V_hasXname_rippleX_inXcreatedX_peerPressure_withXedges_outEX_withyXpropertyName_clusterX_repeatXunionXidentity__bothX_timesX2X_dedup_valueMapXname_clusterX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.WithStrategies(new VertexProgramStrategy(graphComputer: "org.apache.tinkerpop.gremlin.process.computer.GraphComputer")).V().Has("name","ripple").In("created").PeerPressure().With("~tinkerpop.peerPressure.edges",__.OutE()).With [...]
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
index 8a7e31f..fafe089 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
@@ -140,6 +140,7 @@ const gremlins = {
g_V_bothE_properties_dedup_count: [function({g}) { return g.V().bothE().properties().dedup().count() }],
g_V_both_properties_dedup_count: [function({g}) { return g.V().both().properties().dedup().count() }],
g_V_both_properties_properties_dedup_count: [function({g}) { return g.V().both().properties().properties().dedup().count() }],
+ g_V_order_byXname_descX_barrier_dedup_age_name: [function({g}) { return g.V().order().by("name",Order.desc).barrier().dedup().by("age").values("name") }],
g_V_drop: [function({g}) { return g.addV().as("a").addV().as("b").addE("knows").to("a") }, function({g}) { return g.V().drop() }, function({g}) { return g.V() }, function({g}) { return g.E() }],
g_V_outE_drop: [function({g}) { return g.addV().as("a").addV().as("b").addE("knows").to("a") }, function({g}) { return g.V().outE().drop() }, function({g}) { return g.V() }, function({g}) { return g.E() }],
g_V_properties_drop: [function({g}) { return g.addV().property("name","bob").addV().property("name","alice") }, function({g}) { return g.V().properties().drop() }, function({g}) { return g.V() }, function({g}) { return g.V().properties() }],
@@ -455,6 +456,7 @@ const gremlins = {
g_V_both_hasLabelXpersonX_order_byXage_descX_name: [function({g}) { return g.V().both().hasLabel("person").order().by("age",Order.desc).values("name") }],
g_V_order_byXoutE_count_descX: [function({g}) { return g.V().order().by(__.outE().count(),Order.desc) }],
g_V_hasLabelXpersonX_order_byXageX: [function({g}) { return g.V().hasLabel("person").order().by("age") }],
+ g_V_orXhasLabelXpersonX_hasXsoftware_name_lopXX_order_byXageX: [function({g}) { return g.V().or(__.hasLabel("person"),__.has("software","name","lop")).order().by("age") }],
g_VX1X_hasXlabel_personX_mapXmapXint_ageXX_orderXlocalX_byXvalues_descX_byXkeys_ascX: [function({g, l1, v1}) { return g.V(v1).hasLabel("person").map(l1).order(Scope.local).by(Column.values,Order.desc).by(Column.keys,Order.asc) }],
g_VX1X_elementMap_orderXlocalX_byXkeys_descXunfold: [function({g, vid1}) { return g.V(vid1).elementMap().order(Scope.local).by(Column.keys,Order.desc).unfold() }],
g_V_pageRank_hasXpageRankX: [function({g}) { return g.withStrategies(new VertexProgramStrategy(new Map([["graphComputer","org.apache.tinkerpop.gremlin.process.computer.GraphComputer"]]))).V().pageRank().has("gremlin.pageRankVertexProgram.pageRank") }, function({g}) { return g.withStrategies(new VertexProgramStrategy(new Map([["graphComputer","org.apache.tinkerpop.gremlin.process.computer.GraphComputer"]]))).V().pageRank().has("gremlin.pageRankVertexProgram.pageRank") }],
@@ -473,6 +475,7 @@ const gremlins = {
g_V_asXaX_hasXname_markoX_asXbX_hasXage_29X_asXcX_path: [function({g}) { return g.V().as("a").has("name","marko").as("b").has("age",29).as("c").path() }],
g_VX1X_outEXcreatedX_inV_inE_outV_path: [function({g, vid1}) { return g.V(vid1).outE("created").inV().inE().outV().path() }],
g_V_asXaX_out_asXbX_out_asXcX_path_fromXbX_toXcX_byXnameX: [function({g}) { return g.V().as("a").out().as("b").out().as("c").path().from_("b").to("c").by("name") }],
+ g_VX1X_out_path_byXageX: [function({g, vid1}) { return g.V(vid1).out().path().by("age") }],
g_V_peerPressure_hasXclusterX: [function({g}) { return g.withStrategies(new VertexProgramStrategy(new Map([["graphComputer","org.apache.tinkerpop.gremlin.process.computer.GraphComputer"]]))).V().peerPressure().has("gremlin.peerPressureVertexProgram.cluster") }, function({g}) { return g.withStrategies(new VertexProgramStrategy(new Map([["graphComputer","org.apache.tinkerpop.gremlin.process.computer.GraphComputer"]]))).V().peerPressure().has("gremlin.peerPressureVertexProgram.cluster") }],
g_V_peerPressure_withXpropertyName_clusterX_withXedges_outEXknowsXX_pageRankX1X_byXrankX_withXedges_outEXknowsX_withXtimes_2X_group_byXclusterX_byXrank_sumX_limitX100X: [function({g}) { return g.withStrategies(new VertexProgramStrategy(new Map([["graphComputer","org.apache.tinkerpop.gremlin.process.computer.GraphComputer"]]))).V().peerPressure().with_("~tinkerpop.peerPressure.propertyName","cluster").with_("~tinkerpop.peerPressure.edges",__.outE("knows")).pageRank(1.0).with_("~tinker [...]
g_V_hasXname_rippleX_inXcreatedX_peerPressure_withXedges_outEX_withyXpropertyName_clusterX_repeatXunionXidentity__bothX_timesX2X_dedup_valueMapXname_clusterX: [function({g}) { return g.withStrategies(new VertexProgramStrategy(new Map([["graphComputer","org.apache.tinkerpop.gremlin.process.computer.GraphComputer"]]))).V().has("name","ripple").in_("created").peerPressure().with_("~tinkerpop.peerPressure.edges",__.outE()).with_("~tinkerpop.peerPressure.propertyName","cluster").repeat(__ [...]
diff --git a/gremlin-python/src/main/python/radish/gremlin.py b/gremlin-python/src/main/python/radish/gremlin.py
index 9560589..2599b40 100644
--- a/gremlin-python/src/main/python/radish/gremlin.py
+++ b/gremlin-python/src/main/python/radish/gremlin.py
@@ -125,6 +125,7 @@ world.gremlins = {
'g_V_bothE_properties_dedup_count': [(lambda g:g.V().bothE().properties().dedup().count())],
'g_V_both_properties_dedup_count': [(lambda g:g.V().both().properties().dedup().count())],
'g_V_both_properties_properties_dedup_count': [(lambda g:g.V().both().properties().properties().dedup().count())],
+ 'g_V_order_byXname_descX_barrier_dedup_age_name': [(lambda g:g.V().order().by('name',Order.desc).barrier().dedup().by('age').name)],
'g_V_drop': [(lambda g:g.addV().as_('a').addV().as_('b').addE('knows').to('a')), (lambda g:g.V().drop()), (lambda g:g.V()), (lambda g:g.E())],
'g_V_outE_drop': [(lambda g:g.addV().as_('a').addV().as_('b').addE('knows').to('a')), (lambda g:g.V().outE().drop()), (lambda g:g.V()), (lambda g:g.E())],
'g_V_properties_drop': [(lambda g:g.addV().property('name','bob').addV().property('name','alice')), (lambda g:g.V().properties().drop()), (lambda g:g.V()), (lambda g:g.V().properties())],
@@ -440,6 +441,7 @@ world.gremlins = {
'g_V_both_hasLabelXpersonX_order_byXage_descX_name': [(lambda g:g.V().both().hasLabel('person').order().by('age',Order.desc).name)],
'g_V_order_byXoutE_count_descX': [(lambda g:g.V().order().by(__.outE().count(),Order.desc))],
'g_V_hasLabelXpersonX_order_byXageX': [(lambda g:g.V().hasLabel('person').order().by('age'))],
+ 'g_V_orXhasLabelXpersonX_hasXsoftware_name_lopXX_order_byXageX': [(lambda g:g.V().or_(__.hasLabel('person'),__.has('software','name','lop')).order().by('age'))],
'g_VX1X_hasXlabel_personX_mapXmapXint_ageXX_orderXlocalX_byXvalues_descX_byXkeys_ascX': [(lambda g, l1=None,v1=None:g.V(v1).hasLabel('person').map(l1).order(Scope.local).by(Column.values,Order.desc).by(Column.keys,Order.asc))],
'g_VX1X_elementMap_orderXlocalX_byXkeys_descXunfold': [(lambda g, vid1=None:g.V(vid1).elementMap().order(Scope.local).by(Column.keys,Order.desc).unfold())],
'g_V_pageRank_hasXpageRankX': [(lambda g:g.withStrategies(*[TraversalStrategy('VertexProgramStrategy',{'graphComputer':'org.apache.tinkerpop.gremlin.process.computer.GraphComputer'}, 'org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy')]).V().pageRank().has('gremlin.pageRankVertexProgram.pageRank')), (lambda g:g.withStrategies(*[TraversalStrategy('VertexProgramStrategy',{'graphComputer':'org.apache.tinkerpop.gremlin.process.computer.Grap [...]
@@ -458,6 +460,7 @@ world.gremlins = {
'g_V_asXaX_hasXname_markoX_asXbX_hasXage_29X_asXcX_path': [(lambda g:g.V().as_('a').has('name','marko').as_('b').has('age',29).as_('c').path())],
'g_VX1X_outEXcreatedX_inV_inE_outV_path': [(lambda g, vid1=None:g.V(vid1).outE('created').inV().inE().outV().path())],
'g_V_asXaX_out_asXbX_out_asXcX_path_fromXbX_toXcX_byXnameX': [(lambda g:g.V().as_('a').out().as_('b').out().as_('c').path().from_('b').to('c').by('name'))],
+ 'g_VX1X_out_path_byXageX': [(lambda g, vid1=None:g.V(vid1).out().path().by('age'))],
'g_V_peerPressure_hasXclusterX': [(lambda g:g.withStrategies(*[TraversalStrategy('VertexProgramStrategy',{'graphComputer':'org.apache.tinkerpop.gremlin.process.computer.GraphComputer'}, 'org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy')]).V().peerPressure().has('gremlin.peerPressureVertexProgram.cluster')), (lambda g:g.withStrategies(*[TraversalStrategy('VertexProgramStrategy',{'graphComputer':'org.apache.tinkerpop.gremlin.process.com [...]
'g_V_peerPressure_withXpropertyName_clusterX_withXedges_outEXknowsXX_pageRankX1X_byXrankX_withXedges_outEXknowsX_withXtimes_2X_group_byXclusterX_byXrank_sumX_limitX100X': [(lambda g:g.withStrategies(*[TraversalStrategy('VertexProgramStrategy',{'graphComputer':'org.apache.tinkerpop.gremlin.process.computer.GraphComputer'}, 'org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy')]).V().peerPressure().with_('~tinkerpop.peerPressure.propertyNam [...]
'g_V_hasXname_rippleX_inXcreatedX_peerPressure_withXedges_outEX_withyXpropertyName_clusterX_repeatXunionXidentity__bothX_timesX2X_dedup_valueMapXname_clusterX': [(lambda g:g.withStrategies(*[TraversalStrategy('VertexProgramStrategy',{'graphComputer':'org.apache.tinkerpop.gremlin.process.computer.GraphComputer'}, 'org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy')]).V().has('name','ripple').in_('created').peerPressure().with_('~tinkerpo [...]
diff --git a/gremlin-test/features/map/Path.feature b/gremlin-test/features/map/Path.feature
index 822358e..40dcd88 100644
--- a/gremlin-test/features/map/Path.feature
+++ b/gremlin-test/features/map/Path.feature
@@ -103,3 +103,17 @@ Feature: Step - path()
| result |
| p[josh,ripple] |
| p[josh,lop] |
+
+ Scenario: g_VX1X_out_path_byXageX
+ Given the modern graph
+ And using the parameter vid1 defined as "v[marko].id"
+ And the traversal of
+ """
+ g.V(vid1).out().path().by("age")
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | p[d[29].i,null] |
+ | p[d[29].i,d[27].i] |
+ | p[d[29].i,d[32].i] |
\ No newline at end of file
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PathTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PathTest.java
index 7f2d800..1856677 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PathTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PathTest.java
@@ -50,6 +50,8 @@ public abstract class PathTest extends AbstractGremlinProcessTest {
public abstract Traversal<Vertex, Path> get_g_VX1X_name_path(final Object v1Id);
+ public abstract Traversal<Vertex, Path> get_g_VX1X_out_path_byXageX(final Object v1Id);
+
public abstract Traversal<Vertex, Path> get_g_VX1X_out_path_byXageX_byXnameX(final Object v1Id);
public abstract Traversal<Vertex, Path> get_g_V_repeatXoutX_timesX2X_path_by_byXnameX_byXlangX();
@@ -77,6 +79,24 @@ public abstract class PathTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
+ public void g_VX1X_out_path_byXageX() {
+ final Traversal<Vertex, Path> traversal = get_g_VX1X_out_path_byXageX(convertToVertexId("marko"));
+ printTraversalForm(traversal);
+ int counter = 0;
+ final Set<Object> ages = new HashSet<>();
+ while (traversal.hasNext()) {
+ counter++;
+ final Path path = traversal.next();
+ assertEquals(Integer.valueOf(29), path.<Integer>get(0));
+ assertTrue(path.get(1) == null || path.get(1).equals(27) || path.get(1).equals(32));
+ ages.add(path.get(1));
+ }
+ assertEquals(3, counter);
+ assertEquals(3, ages.size());
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
public void g_VX1X_out_path_byXageX_byXnameX() {
final Traversal<Vertex, Path> traversal = get_g_VX1X_out_path_byXageX_byXnameX(convertToVertexId("marko"));
printTraversalForm(traversal);
@@ -165,11 +185,11 @@ public abstract class PathTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
public void g_V_asXaX_out_asXbX_out_asXcX_path_fromXbX_toXcX_byXnameX() {
- final Traversal<Vertex, Path> traveral = get_g_V_asXaX_out_asXbX_out_asXcX_path_fromXbX_toXcX_byXnameX();
- printTraversalForm(traveral);
+ final Traversal<Vertex, Path> traversal = get_g_V_asXaX_out_asXbX_out_asXcX_path_fromXbX_toXcX_byXnameX();
+ printTraversalForm(traversal);
checkResults(Arrays.asList(
MutablePath.make().extend("josh", Collections.singleton("b")).extend("lop", Collections.singleton("c")),
- MutablePath.make().extend("josh", Collections.singleton("b")).extend("ripple", Collections.singleton("c"))), traveral);
+ MutablePath.make().extend("josh", Collections.singleton("b")).extend("ripple", Collections.singleton("c"))), traversal);
}
public static class Traversals extends PathTest {
@@ -179,6 +199,11 @@ public abstract class PathTest extends AbstractGremlinProcessTest {
}
@Override
+ public Traversal<Vertex, Path> get_g_VX1X_out_path_byXageX(final Object v1Id) {
+ return g.V(v1Id).out().path().by("age");
+ }
+
+ @Override
public Traversal<Vertex, Path> get_g_VX1X_out_path_byXageX_byXnameX(final Object v1Id) {
return g.V(v1Id).out().path().by("age").by("name");
}
[tinkerpop] 07/10: TINKERPOP-2598 Addressed NullPointerException
with P.within/out
Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2605
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit a0d4b30197404561f72311aa65e8bb6373897b08
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Wed Aug 25 10:38:39 2021 -0400
TINKERPOP-2598 Addressed NullPointerException with P.within/out
---
CHANGELOG.asciidoc | 1 +
.../tinkerpop/gremlin/process/traversal/P.java | 20 ++++++++++++-----
.../structure/io/binary/types/PSerializer.java | 2 +-
.../structure/io/gryo/GryoSerializersV1d0.java | 2 +-
.../structure/io/gryo/GryoSerializersV3d0.java | 2 +-
.../tinkerpop/gremlin/process/traversal/PTest.java | 26 ++++++++++++++++++++++
.../graphson/GraphSONMapperEmbeddedTypeTest.java | 4 ++--
.../Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs | 1 +
.../GraphBinaryReaderWriterRoundTripTest.java | 2 +-
.../gremlin-javascript/test/cucumber/gremlin.js | 1 +
gremlin-python/src/main/python/radish/gremlin.py | 1 +
gremlin-test/features/filter/Has.feature | 11 +++++++++
12 files changed, 61 insertions(+), 12 deletions(-)
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 825b951..9762fca 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -30,6 +30,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
* Deprecated `JsonBuilder` serialization for GraphSON and Gryo.
* Allowed `null` string values in the Gremlin grammar.
* Prevented exception with `hasLabel(null)` and instead filter away traversers as labels can't ever be null.
+* Improved handling of `null` when passed to `P` predicates.
* Refined `DotNetTranslator` to be more explicit with `null` arguments to ensure that the right overloads are called.
* Created `GremlinParser` to construct `Traversal` objects from `gremlin-language`.
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/P.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/P.java
index 8454f33..a79231a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/P.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/P.java
@@ -204,38 +204,46 @@ public class P<V> implements Predicate<V>, Serializable, Cloneable {
}
/**
- * Determines if a value is within the specified list of values.
+ * Determines if a value is within the specified list of values. If the array of arguments itself is {@code null}
+ * then the argument is treated as {@code Object[1]} where that single value is {@code null}.
*
* @since 3.0.0-incubating
*/
public static <V> P<V> within(final V... values) {
- return P.within(Arrays.asList(values));
+ final V[] v = null == values ? (V[]) new Object[] { null } : values;
+ return P.within(Arrays.asList(v));
}
/**
- * Determines if a value is within the specified list of values.
+ * Determines if a value is within the specified list of values. Calling this with {@code null} is the same as
+ * calling {@link #within(Object[])} using {@code null}.
*
* @since 3.0.0-incubating
*/
public static <V> P<V> within(final Collection<V> value) {
+ if (null == value) return P.within((V) null);
return new P(Contains.within, value);
}
/**
- * Determines if a value is not within the specified list of values.
+ * Determines if a value is not within the specified list of values. If the array of arguments itself is {@code null}
+ * then the argument is treated as {@code Object[1]} where that single value is {@code null}.
*
* @since 3.0.0-incubating
*/
public static <V> P<V> without(final V... values) {
- return P.without(Arrays.asList(values));
+ final V[] v = null == values ? (V[]) new Object[] { null } : values;
+ return P.without(Arrays.asList(v));
}
/**
- * Deermines if a value is not within the specified list of values.
+ * Determines if a value is not within the specified list of values. Calling this with {@code null} is the same as
+ * calling {@link #within(Object[])} using {@code null}.
*
* @since 3.0.0-incubating
*/
public static <V> P<V> without(final Collection<V> value) {
+ if (null == value) return P.without((V) null);
return new P(Contains.without, value);
}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/binary/types/PSerializer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/binary/types/PSerializer.java
index e5ea3e3..a44e41d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/binary/types/PSerializer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/binary/types/PSerializer.java
@@ -60,7 +60,7 @@ public class PSerializer<T extends P> extends SimpleTypeSerializer<T> {
final Class<?>[] argumentClasses = new Class[length];
for (int i = 0; i < length; i++) {
args[i] = context.read(buffer);
- argumentClasses[i] = args[i].getClass();
+ argumentClasses[i] = null == args[i] ? Object.class : args[i].getClass();
}
if ("and".equals(predicateName))
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializersV1d0.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializersV1d0.java
index 7697462..33e535a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializersV1d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializersV1d0.java
@@ -196,7 +196,7 @@ public final class GryoSerializersV1d0 {
final boolean isCollection = input.readByte() == (byte) 0;
final Object value;
if (isCollection) {
- value = new ArrayList();
+ value = new ArrayList<>();
final int size = input.readInt();
for (int ix = 0; ix < size; ix++) {
((List) value).add(kryo.readClassAndObject(input));
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializersV3d0.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializersV3d0.java
index e35bd33..d45bdd9 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializersV3d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializersV3d0.java
@@ -312,7 +312,7 @@ public final class GryoSerializersV3d0 {
final boolean isCollection = input.readByte() == (byte) 0;
final Object value;
if (isCollection) {
- value = new ArrayList();
+ value = new ArrayList<>();
final int size = input.readInt();
for (int ix = 0; ix < size; ix++) {
((List) value).add(kryo.readClassAndObject(input));
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java
index f2e0868..f6ec0d9 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java
@@ -52,8 +52,14 @@ public class PTest {
return new ArrayList<>(Arrays.asList(new Object[][]{
{P.eq(0), 0, true},
{P.eq(0), 1, false},
+ {P.eq(0), null, false},
+ {P.eq(null), null, true},
+ {P.eq(null), 0, false},
{P.neq(0), 0, false},
{P.neq(0), 1, true},
+ {P.neq(0), null, true},
+ {P.neq(null), null, false},
+ {P.neq(null), 0, true},
{P.gt(0), -1, false},
{P.gt(0), 0, false},
{P.gt(0), 1, true},
@@ -78,15 +84,35 @@ public class PTest {
{P.outside(1, 10), 1, false},
{P.outside(1, 10), 9, false},
{P.outside(1, 10), 10, false},
+ {P.within((Object) null), 0, false},
+ {P.within((Object) null), null, true},
+ {P.within((Collection) null), 0, false},
+ {P.within((Collection) null), null, true},
+ {P.within(null, 2, 3), 0, false},
+ {P.within(null, 2, 3), null, true},
+ {P.within(null, 2, 3), 2, true},
{P.within(1, 2, 3), 0, false},
{P.within(1, 2, 3), 1, true},
{P.within(1, 2, 3), 10, false},
+ {P.within(Arrays.asList(null, 2, 3)), null, true},
+ {P.within(Arrays.asList(null, 2, 3)), 1, false},
+ {P.within(Arrays.asList(null, 2, 3)), 2, true},
{P.within(Arrays.asList(1, 2, 3)), 0, false},
{P.within(Arrays.asList(1, 2, 3)), 1, true},
{P.within(Arrays.asList(1, 2, 3)), 10, false},
+ {P.without((Object) null), 0, true},
+ {P.without((Object) null), null, false},
+ {P.without((Collection) null), 0, true},
+ {P.without((Collection) null), null, false},
+ {P.without(null, 2, 3), 0, true},
+ {P.without(null, 2, 3), null, false},
+ {P.without(null, 2, 3), 2, false},
{P.without(1, 2, 3), 0, true},
{P.without(1, 2, 3), 1, false},
{P.without(1, 2, 3), 10, true},
+ {P.without(Arrays.asList(null, 2, 3)), null, false},
+ {P.without(Arrays.asList(null, 2, 3)), 1, true},
+ {P.without(Arrays.asList(null, 2, 3)), 2, false},
{P.without(Arrays.asList(1, 2, 3)), 0, true},
{P.without(Arrays.asList(1, 2, 3)), 1, false},
{P.without(Arrays.asList(1, 2, 3)), 10, true},
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
index dd25ec9..3238480 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
@@ -373,7 +373,7 @@ public class GraphSONMapperEmbeddedTypeTest extends AbstractGraphSONTest {
public void shouldHandlePMultiValue() throws Exception {
assumeThat(version, either(startsWith("v2")).or(startsWith("v3")));
- final P o = P.within(1,2,3);
+ final P o = P.within(1,2,3,null);
assertEquals(o, serializeDeserialize(mapper, o, P.class));
}
@@ -389,7 +389,7 @@ public class GraphSONMapperEmbeddedTypeTest extends AbstractGraphSONTest {
public void shouldHandlePMultiValueAsList() throws Exception {
assumeThat(version, either(startsWith("v2")).or(startsWith("v3")));
- final P o = P.within(Arrays.asList(1,2,3));
+ final P o = P.within(Arrays.asList(1,2,3,null));
assertEquals(o, serializeDeserialize(mapper, o, P.class));
}
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
index f9567a0..6bc762c 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
@@ -199,6 +199,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
{"g_V_hasLabelXpersonX_hasXage_notXlteX10X_andXnotXbetweenX11_20XXXX_andXltX29X_orXeqX35XXXX_name", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().HasLabel("person").Has("age",P.Gt(10).Or(P.Gte(11).And(P.Lt(20))).And(P.Lt(29).Or(P.Eq(35)))).Values<object>("name")}},
{"g_V_in_hasIdXneqX1XX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().In().HasId(p["xx1"])}},
{"g_V_hasXage_withinX27X_count", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has("age",P.Within(new List<object> {27})).Count()}},
+ {"g_V_hasXage_withinX27_nullX_count", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has("age",P.Within(new List<object> {27, null})).Count()}},
{"g_V_hasXage_withinX27_29X_count", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has("age",P.Within(new List<object> {27, 29})).Count()}},
{"g_V_hasXage_withoutX27X_count", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has("age",P.Without(new List<object> {27})).Count()}},
{"g_V_hasXage_withoutX27_29X_count", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has("age",P.Without(new List<object> {27, 29})).Count()}},
diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryReaderWriterRoundTripTest.java b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryReaderWriterRoundTripTest.java
index 5a351f1..3fd54e2 100644
--- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryReaderWriterRoundTripTest.java
+++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryReaderWriterRoundTripTest.java
@@ -231,7 +231,7 @@ public class GraphBinaryReaderWriterRoundTripTest {
new Object[] {"Pand", P.gt(1).and(P.lt(2)), null},
new Object[] {"Por", P.gt(1).or(P.lt(2)), null},
new Object[] {"Pnot", P.not(P.lte(1)), null},
- new Object[] {"Pwithout", P.without(1,2,3,4), null},
+ new Object[] {"Pwithout", P.without(1,2,3,4,null), null},
new Object[] {"Pinside", P.inside(0.0d, 0.6d), null},
new Object[] {"TextP", TextP.startingWith("mark"), null},
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
index 13a5a24..a82873b 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
@@ -188,6 +188,7 @@ const gremlins = {
g_V_hasLabelXpersonX_hasXage_notXlteX10X_andXnotXbetweenX11_20XXXX_andXltX29X_orXeqX35XXXX_name: [function({g}) { return g.V().hasLabel("person").has("age",P.gt(10).or(P.gte(11).and(P.lt(20))).and(P.lt(29).or(P.eq(35)))).values("name") }],
g_V_in_hasIdXneqX1XX: [function({g, xx1}) { return g.V().in_().hasId(xx1) }],
g_V_hasXage_withinX27X_count: [function({g}) { return g.V().has("age",P.within([27])).count() }],
+ g_V_hasXage_withinX27_nullX_count: [function({g}) { return g.V().has("age",P.within([27, null])).count() }],
g_V_hasXage_withinX27_29X_count: [function({g}) { return g.V().has("age",P.within([27, 29])).count() }],
g_V_hasXage_withoutX27X_count: [function({g}) { return g.V().has("age",P.without([27])).count() }],
g_V_hasXage_withoutX27_29X_count: [function({g}) { return g.V().has("age",P.without([27, 29])).count() }],
diff --git a/gremlin-python/src/main/python/radish/gremlin.py b/gremlin-python/src/main/python/radish/gremlin.py
index 3974ce9..8b4100c 100644
--- a/gremlin-python/src/main/python/radish/gremlin.py
+++ b/gremlin-python/src/main/python/radish/gremlin.py
@@ -173,6 +173,7 @@ world.gremlins = {
'g_V_hasLabelXpersonX_hasXage_notXlteX10X_andXnotXbetweenX11_20XXXX_andXltX29X_orXeqX35XXXX_name': [(lambda g:g.V().hasLabel('person').has('age',P.gt(10).or_(P.gte(11).and_(P.lt(20))).and_(P.lt(29).or_(P.eq(35)))).name)],
'g_V_in_hasIdXneqX1XX': [(lambda g, xx1=None:g.V().in_().hasId(xx1))],
'g_V_hasXage_withinX27X_count': [(lambda g:g.V().has('age',P.within([27])).count())],
+ 'g_V_hasXage_withinX27_nullX_count': [(lambda g:g.V().has('age',P.within([27,None])).count())],
'g_V_hasXage_withinX27_29X_count': [(lambda g:g.V().has('age',P.within([27,29])).count())],
'g_V_hasXage_withoutX27X_count': [(lambda g:g.V().has('age',P.without([27])).count())],
'g_V_hasXage_withoutX27_29X_count': [(lambda g:g.V().has('age',P.without([27,29])).count())],
diff --git a/gremlin-test/features/filter/Has.feature b/gremlin-test/features/filter/Has.feature
index 3be3586..db78114 100644
--- a/gremlin-test/features/filter/Has.feature
+++ b/gremlin-test/features/filter/Has.feature
@@ -419,6 +419,17 @@ Feature: Step - has()
| result |
| d[1].l |
+ Scenario: g_V_hasXage_withinX27_nullX_count
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().has("age", P.within(27,null)).count()
+ """
+ When iterated to list
+ Then the result should be ordered
+ | result |
+ | d[1].l |
+
Scenario: g_V_hasXage_withinX27_29X_count
Given the modern graph
And the traversal of
[tinkerpop] 01/10: TINKERPOP-2605 hasLabel(null) filters results
Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2605
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 086f7faddc485ed2002e51e4f893e79b17f2a8e6
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Tue Aug 24 09:26:59 2021 -0400
TINKERPOP-2605 hasLabel(null) filters results
This change gets rid of the general NullPointerException, fixes .NET translation problems around ambiguous method calls, introduces some additional validations around calling has(T,...) with a null T value and adds null as a valid value for StringLiterals
---
CHANGELOG.asciidoc | 3 +
docs/src/upgrade/release-3.5.x.asciidoc | 14 +++
.../traversal/dsl/graph/GraphTraversal.java | 46 ++++++++--
.../process/traversal/step/map/GraphStep.java | 3 +-
.../process/traversal/step/map/PropertiesStep.java | 3 +-
.../process/traversal/step/util/HasContainer.java | 10 +-
.../traversal/translator/DotNetTranslator.java | 19 +++-
.../traversal/translator/DotNetTranslatorTest.java | 14 +++
.../Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs | 13 ++-
.../gremlin-javascript/test/cucumber/gremlin.js | 13 ++-
gremlin-language/src/main/antlr4/Gremlin.g4 | 1 +
gremlin-python/src/main/python/radish/gremlin.py | 13 ++-
gremlin-test/features/filter/Has.feature | 92 ++++++++++++++++++-
.../process/traversal/step/filter/HasTest.java | 101 ++++++++++++++++++++-
.../traversal/step/sideEffect/Neo4jGraphStep.java | 13 ++-
15 files changed, 319 insertions(+), 39 deletions(-)
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index b157ee7..825b951 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -28,6 +28,9 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
* Fixed bug where `RepeatUnrollStrategy`, `InlineFilterStrategy` and `MessagePassingReductionStrategy` were all being applied more than necessary.
* Ensured `PathRetractionStrategy` is applied after `InlineFilterStrategy` which prevents an error in traverser mapping in certain conditions.
* Deprecated `JsonBuilder` serialization for GraphSON and Gryo.
+* Allowed `null` string values in the Gremlin grammar.
+* Prevented exception with `hasLabel(null)` and instead filter away traversers as labels can't ever be null.
+* Refined `DotNetTranslator` to be more explicit with `null` arguments to ensure that the right overloads are called.
* Created `GremlinParser` to construct `Traversal` objects from `gremlin-language`.
[[release-3-5-1]]
diff --git a/docs/src/upgrade/release-3.5.x.asciidoc b/docs/src/upgrade/release-3.5.x.asciidoc
index c59a972..5a0d66b 100644
--- a/docs/src/upgrade/release-3.5.x.asciidoc
+++ b/docs/src/upgrade/release-3.5.x.asciidoc
@@ -28,6 +28,20 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
Please see the link:https://github.com/apache/tinkerpop/blob/3.5.2/CHANGELOG.asciidoc#release-3-5-2[changelog] for a
complete list of all the modifications that are part of this release.
+=== Upgrading for Users
+
+==== Refinements to null
+
+Release 3.5.0 introduce the ability for there to be traversers that contained a `null` value. Since that time it has
+been noted that supplying a `null` value as an argument to certain Gremlin steps might cause exception behaviors that
+were either not clear or perhaps even unexpected. The following changes were made to help make these behaviors more
+consistent and to further solidify the semantics of `null` usage in the Gremlin language:
+
+* `hasLabel(null)` and `has(T.label,null)` - Formerly, these methods threw general `NullPointerException` failures,
+but now filter results. As a `T.label` can't be `null`, it will effectively filter all elements.
+
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-2605[TINKERPOP-2605]
+
== TinkerPop 3.5.1
*Release Date: July 19, 2021*
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index deb3908..63a394e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -1387,6 +1387,14 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* @since 3.0.0-incubating
*/
public default GraphTraversal<S, E> has(final T accessor, final P<?> predicate) {
+ if (null == accessor)
+ throw new IllegalArgumentException("The T accessor value of has(T,Object) cannot be null");
+
+ // Groovy can get the overload wrong for has(T, null) which should probably go at has(T,Object). users could
+ // explicit cast but a redirect here makes this a bit more seamless
+ if (null == predicate)
+ return has(accessor, (Object) null);
+
this.asAdmin().getBytecode().addStep(Symbols.has, accessor, predicate);
return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(accessor.getAccessor(), predicate));
}
@@ -1421,6 +1429,9 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* @since 3.0.0-incubating
*/
public default GraphTraversal<S, E> has(final T accessor, final Object value) {
+ if (null == accessor)
+ throw new IllegalArgumentException("The T accessor value of has(T,Object) cannot be null");
+
if (value instanceof P)
return this.has(accessor, (P) value);
else if (value instanceof Traversal)
@@ -1474,6 +1485,14 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* @since 3.1.0-incubating
*/
public default GraphTraversal<S, E> has(final T accessor, final Traversal<?, ?> propertyTraversal) {
+ if (null == accessor)
+ throw new IllegalArgumentException("The T accessor value of has(T,Object) cannot be null");
+
+ // Groovy can get the overload wrong for has(T, null) which should probably go at has(T,Object). users could
+ // explicit cast but a redirect here makes this a bit more seamless
+ if (null == propertyTraversal)
+ return has(accessor, (Object) null);
+
this.asAdmin().getBytecode().addStep(Symbols.has, accessor, propertyTraversal);
switch (accessor) {
case id:
@@ -1482,8 +1501,8 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
new IdStep<>(propertyTraversal.asAdmin()))));
case label:
return this.asAdmin().addStep(
- new TraversalFilterStep<>(this.asAdmin(), propertyTraversal.asAdmin().addStep(0,
- new LabelStep<>(propertyTraversal.asAdmin()))));
+ new TraversalFilterStep<>(this.asAdmin(), propertyTraversal.asAdmin().addStep(0,
+ new LabelStep<>(propertyTraversal.asAdmin()))));
default:
throw new IllegalArgumentException("has(T,Traversal) can only take id or label as its argument");
}
@@ -1542,15 +1561,21 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* @since 3.2.2
*/
public default GraphTraversal<S, E> hasLabel(final String label, final String... otherLabels) {
- final String[] labels = new String[otherLabels.length + 1];
+ this.asAdmin().getBytecode().addStep(Symbols.hasLabel, label, otherLabels);
+
+ // groovy evaluation seems to do strange things with varargs given hasLabel(null, null). odd someone would
+ // do this but the failure is ugly if not handled.
+ final int otherLabelsLength = null == otherLabels ? 0 : otherLabels.length;
+ final String[] labels = new String[otherLabelsLength + 1];
labels[0] = label;
- System.arraycopy(otherLabels, 0, labels, 1, otherLabels.length);
- this.asAdmin().getBytecode().addStep(Symbols.hasLabel, labels);
+ if (otherLabelsLength > 0)
+ System.arraycopy(otherLabels, 0, labels, 1, otherLabelsLength);
return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.label.getAccessor(), labels.length == 1 ? P.eq(labels[0]) : P.within(labels)));
}
/**
- * Filters vertices, edges and vertex properties based on their label.
+ * Filters vertices, edges and vertex properties based on their label. Note that calling this step with
+ * {@code null} is the same as calling {@link #hasLabel(String, String...)} with a single {@code null}.
*
* @param predicate the filter to apply to the label of the {@link Element}
* @return the traversal with an appended {@link HasStep}
@@ -1558,8 +1583,13 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
* @since 3.2.4
*/
public default GraphTraversal<S, E> hasLabel(final P<String> predicate) {
- this.asAdmin().getBytecode().addStep(Symbols.hasLabel, predicate);
- return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.label.getAccessor(), predicate));
+ // if calling hasLabel(null), the likely use the caller is going for is not a "no predicate" but a eq(null)
+ if (null == predicate) {
+ return hasLabel((String) null);
+ } else {
+ this.asAdmin().getBytecode().addStep(Symbols.hasLabel, predicate);
+ return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.label.getAccessor(), predicate));
+ }
}
/**
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GraphStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GraphStep.java
index aa3a29f..7982e37 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GraphStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/GraphStep.java
@@ -42,6 +42,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
+import java.util.Objects;
import java.util.function.Supplier;
/**
@@ -177,7 +178,7 @@ public class GraphStep<S, E extends Element> extends AbstractStep<S, E> implemen
int result = super.hashCode() ^ this.returnClass.hashCode();
if (null != this.ids) {
for (final Object id : this.ids) {
- result ^= id.hashCode();
+ result ^= Objects.hashCode(id);
}
}
return result;
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PropertiesStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PropertiesStep.java
index 7cc193a..dce4fed 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PropertiesStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PropertiesStep.java
@@ -30,6 +30,7 @@ import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
+import java.util.Objects;
import java.util.Set;
/**
@@ -81,7 +82,7 @@ public class PropertiesStep<E> extends FlatMapStep<Element, E> implements AutoCl
public int hashCode() {
int result = super.hashCode() ^ this.returnType.hashCode();
for (final String propertyKey : this.propertyKeys) {
- result ^= propertyKey.hashCode();
+ result ^= Objects.hashCode(propertyKey);
}
return result;
}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java
index 111e23c..31cea06 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java
@@ -104,23 +104,23 @@ public class HasContainer implements Serializable, Cloneable, Predicate<Element>
return false;
}
- protected boolean testId(Element element) {
+ protected boolean testId(final Element element) {
return this.predicate.test(element.id());
}
- protected boolean testIdAsString(Element element) {
+ protected boolean testIdAsString(final Element element) {
return this.predicate.test(element.id().toString());
}
- protected boolean testLabel(Element element) {
+ protected boolean testLabel(final Element element) {
return this.predicate.test(element.label());
}
- protected boolean testValue(Property property) {
+ protected boolean testValue(final Property property) {
return this.predicate.test(property.value());
}
- protected boolean testKey(Property property) {
+ protected boolean testKey(final Property property) {
return this.predicate.test(property.key());
}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslator.java
index 181ee1f..d4dcc35 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslator.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslator.java
@@ -340,11 +340,20 @@ public final class DotNetTranslator implements Translator.ScriptTranslator {
convertToScript(instruction.getArguments()[1]);
script.append(",");
} else {
- for (final Object object : instruction.getArguments()) {
- // overloads might have trouble with null. add more as we find them i guess
- if (null == object && methodName.equals(GraphTraversal.Symbols.addV))
- script.append("(string) ");
- convertToScript(object);
+ final Object[] instArgs = instruction.getArguments();
+ for (int idx = 0; idx < instArgs.length; idx++) {
+ final Object instArg = instArgs[idx];
+ // overloads might have trouble with null in calling the right one. add more as we find
+ // them i guess
+ if (null == instArg) {
+ if ((methodName.equals(GraphTraversal.Symbols.addV) && idx % 2 == 0) ||
+ methodName.equals(GraphTraversal.Symbols.hasLabel)) {
+ script.append("(string) ");
+ } else if (methodName.equals(GraphTraversal.Symbols.has)) {
+ if (instArgs[0] instanceof T && idx > 0) script.append("(object) ");
+ }
+ }
+ convertToScript(instArg);
script.append(",");
}
}
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslatorTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslatorTest.java
index a1ec5cb..3e5654c 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslatorTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslatorTest.java
@@ -154,6 +154,20 @@ public class DotNetTranslatorTest {
}
@Test
+ public void shouldTranslateHasLabelNull() {
+ String script = translator.translate(g.V().hasLabel(null).asAdmin().getBytecode()).getScript();
+ assertEquals("g.V().HasLabel((string) null)", script);
+ script = translator.translate(g.V().hasLabel(null, null).asAdmin().getBytecode()).getScript();
+ assertEquals("g.V().HasLabel((string) null,(string) null)", script);
+ script = translator.translate(g.V().hasLabel(null, "person").asAdmin().getBytecode()).getScript();
+ assertEquals("g.V().HasLabel((string) null,\"person\")", script);
+ script = translator.translate(g.V().hasLabel(null, "person", null).asAdmin().getBytecode()).getScript();
+ assertEquals("g.V().HasLabel((string) null,\"person\",(string) null)", script);
+ script = translator.translate(g.V().has(T.label, (Object) null).asAdmin().getBytecode()).getScript();
+ assertEquals("g.V().Has(T.Label,(object) null)", script);
+ }
+
+ @Test
public void shouldEscapeStrings() {
final String script = translator.translate(g.addV("customer")
.property("customer_id", 501L)
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
index 407c9b8..0e1ae90 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
@@ -186,8 +186,8 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
{"g_VX1X_out_hasXid_2_3X", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p["vid1"]).Out().HasId(p["vid2"],p["vid3"])}},
{"g_VX1X_out_hasXid_2AsString_3AsStringX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p["vid1"]).Out().HasId(p["vid2"],p["vid3"])}},
{"g_V_hasXblahX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has("blah")}},
- {"g_EX7X_hasXlabelXknowsX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.E(p["eid7"]).HasLabel("knows")}},
- {"g_E_hasXlabelXknowsX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.E().HasLabel("knows")}},
+ {"g_EX7X_hasLabelXknowsX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.E(p["eid7"]).HasLabel("knows")}},
+ {"g_E_hasLabelXknowsX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.E().HasLabel("knows")}},
{"g_E_hasLabelXuses_traversesX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.E().HasLabel("uses","traverses")}},
{"g_V_hasLabelXperson_software_blahX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().HasLabel("person","software","blah")}},
{"g_V_hasXperson_name_markoX_age", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has("person","name","marko").Values<object>("age")}},
@@ -224,6 +224,15 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
{"g_V_hasXage_gtX18X_andXltX30XXorXgtx35XXX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has("age",P.Gt(18).And(P.Lt(30)).Or(P.Gt(35)))}},
{"g_V_hasXage_gtX18X_andXltX30XXorXltx35XXX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has("age",P.Gt(18).And(P.Lt(30)).And(P.Lt(35)))}},
{"g_V_hasXk_withinXcXX_valuesXkX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.AddV().Property("k","\u8F49\u6CE8").AddV().Property("k","\u2726").AddV().Property("k","\u2660").AddV().Property("k","A"), (g,p) =>g.V().Has("k",P.Within(new List<object> {"\u8F49\u6CE8", "\u2726", "\u2660"})).Values<object>("k")}},
+ {"g_V_hasXnullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has(null)}},
+ {"g_E_hasXnullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.E().Has(null)}},
+ {"g_V_hasLabelXnullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().HasLabel((string) null)}},
+ {"g_V_hasXlabel_nullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Has(T.Label,(object) null)}},
+ {"g_V_hasLabelXnull_nullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().HasLabel((string) null,(string) null)}},
+ {"g_V_hasLabelXnull_personX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().HasLabel((string) null,"person")}},
+ {"g_E_hasLabelXnullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.E().HasLabel((string) null)}},
+ {"g_E_hasXlabel_nullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.E().Has(T.Label,(object) null)}},
+ {"g_V_properties_hasLabelXnullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Properties<object>().HasLabel((string) null)}},
{"g_V_valuesXageX_isX32X", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("age").Is(32)}},
{"g_V_valuesXageX_isXlte_30X", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("age").Is(P.Lte(30))}},
{"g_V_valuesXageX_isXgte_29X_isXlt_34X", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().Values<object>("age").Is(P.Gte(29)).Is(P.Lt(34))}},
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
index be4f51f..8a7e31f 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
@@ -175,8 +175,8 @@ const gremlins = {
g_VX1X_out_hasXid_2_3X: [function({g, vid3, vid2, vid1}) { return g.V(vid1).out().hasId(vid2,vid3) }],
g_VX1X_out_hasXid_2AsString_3AsStringX: [function({g, vid3, vid2, vid1}) { return g.V(vid1).out().hasId(vid2,vid3) }],
g_V_hasXblahX: [function({g}) { return g.V().has("blah") }],
- g_EX7X_hasXlabelXknowsX: [function({g, eid7}) { return g.E(eid7).hasLabel("knows") }],
- g_E_hasXlabelXknowsX: [function({g}) { return g.E().hasLabel("knows") }],
+ g_EX7X_hasLabelXknowsX: [function({g, eid7}) { return g.E(eid7).hasLabel("knows") }],
+ g_E_hasLabelXknowsX: [function({g}) { return g.E().hasLabel("knows") }],
g_E_hasLabelXuses_traversesX: [function({g}) { return g.E().hasLabel("uses","traverses") }],
g_V_hasLabelXperson_software_blahX: [function({g}) { return g.V().hasLabel("person","software","blah") }],
g_V_hasXperson_name_markoX_age: [function({g}) { return g.V().has("person","name","marko").values("age") }],
@@ -213,6 +213,15 @@ const gremlins = {
g_V_hasXage_gtX18X_andXltX30XXorXgtx35XXX: [function({g}) { return g.V().has("age",P.gt(18).and(P.lt(30)).or(P.gt(35))) }],
g_V_hasXage_gtX18X_andXltX30XXorXltx35XXX: [function({g}) { return g.V().has("age",P.gt(18).and(P.lt(30)).and(P.lt(35))) }],
g_V_hasXk_withinXcXX_valuesXkX: [function({g}) { return g.addV().property("k","\u8F49\u6CE8").addV().property("k","\u2726").addV().property("k","\u2660").addV().property("k","A") }, function({g}) { return g.V().has("k",P.within(["\u8F49\u6CE8", "\u2726", "\u2660"])).values("k") }],
+ g_V_hasXnullX: [function({g}) { return g.V().has(null) }],
+ g_E_hasXnullX: [function({g}) { return g.E().has(null) }],
+ g_V_hasLabelXnullX: [function({g}) { return g.V().hasLabel(null) }],
+ g_V_hasXlabel_nullX: [function({g}) { return g.V().has(T.label,null) }],
+ g_V_hasLabelXnull_nullX: [function({g}) { return g.V().hasLabel(null,null) }],
+ g_V_hasLabelXnull_personX: [function({g}) { return g.V().hasLabel(null,"person") }],
+ g_E_hasLabelXnullX: [function({g}) { return g.E().hasLabel(null) }],
+ g_E_hasXlabel_nullX: [function({g}) { return g.E().has(T.label,null) }],
+ g_V_properties_hasLabelXnullX: [function({g}) { return g.V().properties().hasLabel(null) }],
g_V_valuesXageX_isX32X: [function({g}) { return g.V().values("age").is(32) }],
g_V_valuesXageX_isXlte_30X: [function({g}) { return g.V().values("age").is(P.lte(30)) }],
g_V_valuesXageX_isXgte_29X_isXlt_34X: [function({g}) { return g.V().values("age").is(P.gte(29)).is(P.lt(34)) }],
diff --git a/gremlin-language/src/main/antlr4/Gremlin.g4 b/gremlin-language/src/main/antlr4/Gremlin.g4
index 37c8228..2d8d030 100644
--- a/gremlin-language/src/main/antlr4/Gremlin.g4
+++ b/gremlin-language/src/main/antlr4/Gremlin.g4
@@ -1293,6 +1293,7 @@ booleanLiteral
stringLiteral
: NonEmptyStringLiteral
| EmptyStringLiteral
+ | NullLiteral
| gremlinStringConstants
;
diff --git a/gremlin-python/src/main/python/radish/gremlin.py b/gremlin-python/src/main/python/radish/gremlin.py
index 4d58428..9560589 100644
--- a/gremlin-python/src/main/python/radish/gremlin.py
+++ b/gremlin-python/src/main/python/radish/gremlin.py
@@ -160,8 +160,8 @@ world.gremlins = {
'g_VX1X_out_hasXid_2_3X': [(lambda g, vid3=None,vid2=None,vid1=None:g.V(vid1).out().hasId(vid2,vid3))],
'g_VX1X_out_hasXid_2AsString_3AsStringX': [(lambda g, vid3=None,vid2=None,vid1=None:g.V(vid1).out().hasId(vid2,vid3))],
'g_V_hasXblahX': [(lambda g:g.V().has('blah'))],
- 'g_EX7X_hasXlabelXknowsX': [(lambda g, eid7=None:g.E(eid7).hasLabel('knows'))],
- 'g_E_hasXlabelXknowsX': [(lambda g:g.E().hasLabel('knows'))],
+ 'g_EX7X_hasLabelXknowsX': [(lambda g, eid7=None:g.E(eid7).hasLabel('knows'))],
+ 'g_E_hasLabelXknowsX': [(lambda g:g.E().hasLabel('knows'))],
'g_E_hasLabelXuses_traversesX': [(lambda g:g.E().hasLabel('uses','traverses'))],
'g_V_hasLabelXperson_software_blahX': [(lambda g:g.V().hasLabel('person','software','blah'))],
'g_V_hasXperson_name_markoX_age': [(lambda g:g.V().has('person','name','marko').age)],
@@ -198,6 +198,15 @@ world.gremlins = {
'g_V_hasXage_gtX18X_andXltX30XXorXgtx35XXX': [(lambda g:g.V().has('age',P.gt(18).and_(P.lt(30)).or_(P.gt(35))))],
'g_V_hasXage_gtX18X_andXltX30XXorXltx35XXX': [(lambda g:g.V().has('age',P.gt(18).and_(P.lt(30)).and_(P.lt(35))))],
'g_V_hasXk_withinXcXX_valuesXkX': [(lambda g:g.addV().property('k','轉注').addV().property('k','✦').addV().property('k','♠').addV().property('k','A')), (lambda g:g.V().has('k',P.within(['轉注','✦','♠'])).k)],
+ 'g_V_hasXnullX': [(lambda g:g.V().has(None))],
+ 'g_E_hasXnullX': [(lambda g:g.E().has(None))],
+ 'g_V_hasLabelXnullX': [(lambda g:g.V().hasLabel(None))],
+ 'g_V_hasXlabel_nullX': [(lambda g:g.V().has(T.label,None))],
+ 'g_V_hasLabelXnull_nullX': [(lambda g:g.V().hasLabel(None,None))],
+ 'g_V_hasLabelXnull_personX': [(lambda g:g.V().hasLabel(None,'person'))],
+ 'g_E_hasLabelXnullX': [(lambda g:g.E().hasLabel(None))],
+ 'g_E_hasXlabel_nullX': [(lambda g:g.E().has(T.label,None))],
+ 'g_V_properties_hasLabelXnullX': [(lambda g:g.V().properties().hasLabel(None))],
'g_V_valuesXageX_isX32X': [(lambda g:g.V().age.is_(32))],
'g_V_valuesXageX_isXlte_30X': [(lambda g:g.V().age.is_(P.lte(30)))],
'g_V_valuesXageX_isXgte_29X_isXlt_34X': [(lambda g:g.V().age.is_(P.gte(29)).is_(P.lt(34)))],
diff --git a/gremlin-test/features/filter/Has.feature b/gremlin-test/features/filter/Has.feature
index d142c0e..3be3586 100644
--- a/gremlin-test/features/filter/Has.feature
+++ b/gremlin-test/features/filter/Has.feature
@@ -259,7 +259,7 @@ Feature: Step - has()
When iterated to list
Then the result should be empty
- Scenario: g_EX7X_hasXlabelXknowsX
+ Scenario: g_EX7X_hasLabelXknowsX
Given the modern graph
And using the parameter eid7 defined as "e[marko-knows->vadas].id"
And the traversal of
@@ -271,7 +271,7 @@ Feature: Step - has()
| result |
| e[marko-knows->vadas] |
- Scenario: g_E_hasXlabelXknowsX
+ Scenario: g_E_hasLabelXknowsX
Given the modern graph
And the traversal of
"""
@@ -731,4 +731,90 @@ Feature: Step - has()
| result |
| 轉注 |
| ✦ |
- | ♠ |
\ No newline at end of file
+ | ♠ |
+
+ Scenario: g_V_hasXnullX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().has(null)
+ """
+ When iterated to list
+ Then the result should be empty
+
+ Scenario: g_E_hasXnullX
+ Given the modern graph
+ And the traversal of
+ """
+ g.E().has(null)
+ """
+ When iterated to list
+ Then the result should be empty
+
+ Scenario: g_V_hasLabelXnullX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().hasLabel(null)
+ """
+ When iterated to list
+ Then the result should be empty
+
+ Scenario: g_V_hasXlabel_nullX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().has(T.label, null)
+ """
+ When iterated to list
+ Then the result should be empty
+
+ Scenario: g_V_hasLabelXnull_nullX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().hasLabel(null, null)
+ """
+ When iterated to list
+ Then the result should be empty
+
+ Scenario: g_V_hasLabelXnull_personX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().hasLabel(null, "person")
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | v[marko] |
+ | v[vadas] |
+ | v[josh] |
+ | v[peter] |
+
+ Scenario: g_E_hasLabelXnullX
+ Given the modern graph
+ And the traversal of
+ """
+ g.E().hasLabel(null)
+ """
+ When iterated to list
+ Then the result should be empty
+
+ Scenario: g_E_hasXlabel_nullX
+ Given the modern graph
+ And the traversal of
+ """
+ g.E().has(T.label, null)
+ """
+ When iterated to list
+ Then the result should be empty
+
+ Scenario: g_V_properties_hasLabelXnullX
+ Given the modern graph
+ And the traversal of
+ """
+ g.V().properties().hasLabel(null)
+ """
+ When iterated to list
+ Then the result should be empty
\ No newline at end of file
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/HasTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/HasTest.java
index 3e2a006..77d3338 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/HasTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/HasTest.java
@@ -29,6 +29,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.hamcrest.CoreMatchers;
@@ -41,7 +42,6 @@ import java.util.List;
import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.CREW;
import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
-import static org.apache.tinkerpop.gremlin.process.traversal.Contains.within;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -68,6 +68,14 @@ public abstract class HasTest extends AbstractGremlinProcessTest {
public abstract Traversal<Vertex, Vertex> get_g_V_hasXblahX();
+ public abstract Traversal<Vertex, Vertex> get_g_V_hasXnullX();
+
+ public abstract Traversal<Edge, Edge> get_g_E_hasXnullX();
+
+ public abstract Traversal<Vertex, Vertex> get_g_V_hasLabelXnullX();
+
+ public abstract Traversal<Vertex, Vertex> get_g_V_hasLabelXnull_personX();
+
public abstract Traversal<Vertex, Vertex> get_g_VX1X_hasXage_gt_30X(final Object v1Id);
public abstract Traversal<Vertex, Vertex> get_g_VXv1X_hasXage_gt_30X(final Object v1Id);
@@ -88,6 +96,10 @@ public abstract class HasTest extends AbstractGremlinProcessTest {
public abstract Traversal<Edge, Edge> get_g_E_hasLabelXknowsX();
+ public abstract Traversal<Edge, Edge> get_g_E_hasLabelXnullX();
+
+ public abstract Traversal<Vertex, ? extends Property> get_g_V_properties_hasLabelXnullX();
+
public abstract Traversal<Edge, Edge> get_g_EX11X_outV_outE_hasXid_10X(final Object e11Id, final Object e8Id);
public abstract Traversal<Edge, Edge> get_g_E_hasLabelXuses_traversesX();
@@ -339,7 +351,7 @@ public abstract class HasTest extends AbstractGremlinProcessTest {
assertTrue(traversal.hasNext());
assertThat(traversal.next().id(), CoreMatchers.anyOf(is(id2), is(id3)));
assertThat(traversal.next().id(), CoreMatchers.anyOf(is(id2), is(id3)));
- assertFalse(traversal.hasNext());
+ assertThat(traversal.hasNext(), is(false));
}
@Test
@@ -347,13 +359,46 @@ public abstract class HasTest extends AbstractGremlinProcessTest {
public void g_V_hasXblahX() {
final Traversal<Vertex, Vertex> traversal = get_g_V_hasXblahX();
printTraversalForm(traversal);
- assertFalse(traversal.hasNext());
+ assertThat(traversal.hasNext(), is(false));
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_hasXnullX() {
+ final Traversal<Vertex, Vertex> traversal = get_g_V_hasXnullX();
+ printTraversalForm(traversal);
+ assertThat(traversal.hasNext(), is(false));
}
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_E_hasXnullX() {
+ final Traversal<Edge, Edge> traversal = get_g_E_hasXnullX();
+ printTraversalForm(traversal);
+ assertThat(traversal.hasNext(), is(false));
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_hasLabelXnullX() {
+ final Traversal<Vertex, Vertex> traversal = get_g_V_hasLabelXnullX();
+ printTraversalForm(traversal);
+ assertThat(traversal.hasNext(), is(false));
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_hasLabelXnull_personX() {
+ final Traversal<Vertex, Vertex> traversal = get_g_V_hasLabelXnull_personX();
+ printTraversalForm(traversal);
+ final List<Vertex> vertices = traversal.toList();
+ assertEquals(4, vertices.size());
+ assertThat(vertices.stream().allMatch(v -> v.label().equals("person")), is(true));
+ }
@Test
@LoadGraphWith(MODERN)
- public void g_EX7X_hasXlabelXknowsX() {
+ public void g_EX7X_hasLabelXknowsX() {
final Traversal<Edge, Edge> traversal = get_g_EX7X_hasLabelXknowsX(convertToEdgeId("marko", "knows", "vadas"));
printTraversalForm(traversal);
int counter = 0;
@@ -366,7 +411,7 @@ public abstract class HasTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
- public void g_E_hasXlabelXknowsX() {
+ public void g_E_hasLabelXknowsX() {
final Traversal<Edge, Edge> traversal = get_g_E_hasLabelXknowsX();
printTraversalForm(traversal);
int counter = 0;
@@ -378,6 +423,22 @@ public abstract class HasTest extends AbstractGremlinProcessTest {
}
@Test
+ @LoadGraphWith(MODERN)
+ public void g_E_hasLabelXnullX() {
+ final Traversal<Edge, Edge> traversal = get_g_E_hasLabelXnullX();
+ printTraversalForm(traversal);
+ assertThat(traversal.hasNext(), is(false));
+ }
+
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_properties_hasLabelXnullX() {
+ final Traversal<Vertex, ? extends Property> traversal = get_g_V_properties_hasLabelXnullX();
+ printTraversalForm(traversal);
+ assertThat(traversal.hasNext(), is(false));
+ }
+
+ @Test
@LoadGraphWith(CREW)
public void g_E_hasLabelXuses_traversesX() {
final Traversal<Edge, Edge> traversal = get_g_E_hasLabelXuses_traversesX();
@@ -756,6 +817,31 @@ public abstract class HasTest extends AbstractGremlinProcessTest {
}
@Override
+ public Traversal<Vertex, Vertex> get_g_V_hasXnullX() {
+ return g.V().has(null);
+ }
+
+ @Override
+ public Traversal<Edge, Edge> get_g_E_hasXnullX() {
+ return g.E().has(null);
+ }
+
+ @Override
+ public Traversal<Vertex, Vertex> get_g_V_hasLabelXnullX() {
+ return g.V().hasLabel(null);
+ }
+
+ @Override
+ public Traversal<Vertex, Vertex> get_g_V_hasLabelXnull_personX() {
+ return g.V().hasLabel(null, "person");
+ }
+
+ @Override
+ public Traversal<Vertex, ? extends Property> get_g_V_properties_hasLabelXnullX() {
+ return g.V().properties().hasLabel(null);
+ }
+
+ @Override
public Traversal<Vertex, Vertex> get_g_VX1X_hasXage_gt_30X(final Object v1Id) {
return g.V(v1Id).has("age", P.gt(30));
}
@@ -806,6 +892,11 @@ public abstract class HasTest extends AbstractGremlinProcessTest {
}
@Override
+ public Traversal<Edge, Edge> get_g_E_hasLabelXnullX() {
+ return g.E().hasLabel(null);
+ }
+
+ @Override
public Traversal<Edge, Edge> get_g_E_hasLabelXuses_traversesX() {
return g.E().hasLabel("uses", "traverses");
}
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/step/sideEffect/Neo4jGraphStep.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/step/sideEffect/Neo4jGraphStep.java
index 43dcd39..89b17a1 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/step/sideEffect/Neo4jGraphStep.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/step/sideEffect/Neo4jGraphStep.java
@@ -81,24 +81,26 @@ public final class Neo4jGraphStep<S, E extends Element> extends GraphStep<S, E>
Optional<String> label = hasContainers.stream()
.filter(hasContainer -> hasContainer.getKey().equals(T.label.getAccessor()))
.filter(hasContainer -> Compare.eq == hasContainer.getBiPredicate())
+ .filter(hasContainer -> hasContainer.getValue() != null)
.map(hasContainer -> (String) hasContainer.getValue())
.findAny();
if (!label.isPresent())
label = hasContainers.stream()
.filter(hasContainer -> hasContainer.getKey().equals(T.label.getAccessor()))
.filter(hasContainer -> hasContainer.getPredicate() instanceof LabelP)
+ .filter(hasContainer -> hasContainer.getValue() != null)
.map(hasContainer -> (String) hasContainer.getValue())
.findAny();
if (label.isPresent()) {
// find a vertex by label and key/value
- String labelValue = label.get();
- Neo4jGraphAPI baseGraph = graph.getBaseGraph();
+ final String labelValue = label.get();
+ final Neo4jGraphAPI baseGraph = graph.getBaseGraph();
for (final HasContainer hasContainer : hasContainers) {
- String key = hasContainer.getKey();
- Object value = hasContainer.getValue();
+ final String key = hasContainer.getKey();
+ final Object value = hasContainer.getValue();
if (!key.equals(T.label.getAccessor()) && baseGraph.hasSchemaIndex(labelValue, key)) {
- BiPredicate<?, ?> predicate = hasContainer.getBiPredicate();
+ final BiPredicate<?, ?> predicate = hasContainer.getBiPredicate();
Iterable<Neo4jNode> nodes = null;
if (Compare.eq == predicate) {
nodes = baseGraph.findNodes(labelValue, key, value);
@@ -116,6 +118,7 @@ public final class Neo4jGraphStep<S, E extends Element> extends GraphStep<S, E>
}
}
}
+
// find a vertex by label
return IteratorUtils.stream(graph.getBaseGraph().findNodes(label.get()))
.map(node -> (Vertex) new Neo4jVertex(node, graph))
[tinkerpop] 08/10: TINKERPOP-2605 Added test for where() evaluated
null equality
Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2605
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 5f77ae42eea0b27fd5824430ce2575070c1d50e5
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Wed Aug 25 12:10:47 2021 -0400
TINKERPOP-2605 Added test for where() evaluated null equality
---
.../test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs | 1 +
.../gremlin-javascript/test/cucumber/gremlin.js | 1 +
gremlin-python/src/main/python/radish/gremlin.py | 1 +
gremlin-test/features/filter/Where.feature | 15 +++++++++++++++
.../gremlin/process/traversal/step/filter/WhereTest.java | 15 +++++++++++++++
5 files changed, 33 insertions(+)
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
index 6bc762c..a3966da 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
@@ -307,6 +307,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
{"g_V_asXaX_outEXcreatedX_asXbX_inV_asXcX_whereXa_gtXbX_orXeqXbXXX_byXageX_byXweightX_byXweightX_selectXa_cX_byXnameX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().As("a").OutE("created").As("b").InV().As("c").Where("a",P.Gt("b").Or(P.Eq("b"))).By("age").By("weight").By("weight").Select<object>("a","c").By("name")}},
{"g_V_asXaX_outEXcreatedX_asXbX_inV_asXcX_inXcreatedX_asXdX_whereXa_ltXbX_orXgtXcXX_andXneqXdXXX_byXageX_byXweightX_byXinXcreatedX_valuesXageX_minX_selectXa_c_dX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().As("a").OutE("created").As("b").InV().As("c").In("created").As("d").Where("a",P.Lt("b").Or(P.Gt("c")).And(P.Neq("d"))).By("age").By("weight").By(__.In("created").Values<object>("age").Min<object>()).Select<object>("a","c [...]
{"g_VX1X_asXaX_out_hasXageX_whereXgtXaXX_byXageX_name", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p["vid1"]).As("a").Out().Has("age").Where(P.Gt("a")).By("age").Values<object>("name")}},
+ {"g_VX3X_asXaX_in_out_asXbX_whereXa_eqXbXX_byXageX_name", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p["vid3"]).As("a").In().Out().As("b").Where("a",P.Eq("b")).By("age").Values<object>("name")}},
{"g_VX1X_asXaX_outXcreatedX_addEXcreatedByX_toXaX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.AddV("person").Property(T.Id,1).Property("name","marko").Property("age",29).As("marko").AddV("person").Property(T.Id,2).Property("name","vadas").Property("age",27).As("vadas").AddV("software").Property(T.Id,3).Property("name","lop").Property("lang","java").As("lop").AddV("person").Property(T.Id,4).Property("name","josh").Property("age [...]
{"g_VX1X_asXaX_outXcreatedX_addEXcreatedByX_toXaX_propertyXweight_2X", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.AddV("person").Property(T.Id,1).Property("name","marko").Property("age",29).As("marko").AddV("person").Property(T.Id,2).Property("name","vadas").Property("age",27).As("vadas").AddV("software").Property(T.Id,3).Property("name","lop").Property("lang","java").As("lop").AddV("person").Property(T.Id,4).Property("name","j [...]
{"g_V_outE_propertyXweight_nullX", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.AddV("person").Property(T.Id,1).Property("name","marko").Property("age",29).As("marko").AddV("person").Property(T.Id,2).Property("name","vadas").Property("age",27).As("vadas").AddV("software").Property(T.Id,3).Property("name","lop").Property("lang","java").As("lop").AddV("person").Property(T.Id,4).Property("name","josh").Property("age",32).As("josh"). [...]
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
index a82873b..d0aa270 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js
@@ -296,6 +296,7 @@ const gremlins = {
g_V_asXaX_outEXcreatedX_asXbX_inV_asXcX_whereXa_gtXbX_orXeqXbXXX_byXageX_byXweightX_byXweightX_selectXa_cX_byXnameX: [function({g}) { return g.V().as("a").outE("created").as("b").inV().as("c").where("a",P.gt("b").or(P.eq("b"))).by("age").by("weight").by("weight").select("a","c").by("name") }],
g_V_asXaX_outEXcreatedX_asXbX_inV_asXcX_inXcreatedX_asXdX_whereXa_ltXbX_orXgtXcXX_andXneqXdXXX_byXageX_byXweightX_byXinXcreatedX_valuesXageX_minX_selectXa_c_dX: [function({g}) { return g.V().as("a").outE("created").as("b").inV().as("c").in_("created").as("d").where("a",P.lt("b").or(P.gt("c")).and(P.neq("d"))).by("age").by("weight").by(__.in_("created").values("age").min()).select("a","c","d").by("name") }],
g_VX1X_asXaX_out_hasXageX_whereXgtXaXX_byXageX_name: [function({g, vid1}) { return g.V(vid1).as("a").out().has("age").where(P.gt("a")).by("age").values("name") }],
+ g_VX3X_asXaX_in_out_asXbX_whereXa_eqXbXX_byXageX_name: [function({g, vid3}) { return g.V(vid3).as("a").in_().out().as("b").where("a",P.eq("b")).by("age").values("name") }],
g_VX1X_asXaX_outXcreatedX_addEXcreatedByX_toXaX: [function({g, vid1}) { return g.addV("person").property(T.id,1).property("name","marko").property("age",29).as("marko").addV("person").property(T.id,2).property("name","vadas").property("age",27).as("vadas").addV("software").property(T.id,3).property("name","lop").property("lang","java").as("lop").addV("person").property(T.id,4).property("name","josh").property("age",32).as("josh").addV("software").property(T.id,5).property("name","rip [...]
g_VX1X_asXaX_outXcreatedX_addEXcreatedByX_toXaX_propertyXweight_2X: [function({g, vid1}) { return g.addV("person").property(T.id,1).property("name","marko").property("age",29).as("marko").addV("person").property(T.id,2).property("name","vadas").property("age",27).as("vadas").addV("software").property(T.id,3).property("name","lop").property("lang","java").as("lop").addV("person").property(T.id,4).property("name","josh").property("age",32).as("josh").addV("software").property(T.id,5).p [...]
g_V_outE_propertyXweight_nullX: [function({g}) { return g.addV("person").property(T.id,1).property("name","marko").property("age",29).as("marko").addV("person").property(T.id,2).property("name","vadas").property("age",27).as("vadas").addV("software").property(T.id,3).property("name","lop").property("lang","java").as("lop").addV("person").property(T.id,4).property("name","josh").property("age",32).as("josh").addV("software").property(T.id,5).property("name","ripple").property("lang"," [...]
diff --git a/gremlin-python/src/main/python/radish/gremlin.py b/gremlin-python/src/main/python/radish/gremlin.py
index 8b4100c..317a387 100644
--- a/gremlin-python/src/main/python/radish/gremlin.py
+++ b/gremlin-python/src/main/python/radish/gremlin.py
@@ -281,6 +281,7 @@ world.gremlins = {
'g_V_asXaX_outEXcreatedX_asXbX_inV_asXcX_whereXa_gtXbX_orXeqXbXXX_byXageX_byXweightX_byXweightX_selectXa_cX_byXnameX': [(lambda g:g.V().as_('a').outE('created').as_('b').inV().as_('c').where('a',P.gt('b').or_(P.eq('b'))).by('age').by('weight').by('weight').select('a','c').by('name'))],
'g_V_asXaX_outEXcreatedX_asXbX_inV_asXcX_inXcreatedX_asXdX_whereXa_ltXbX_orXgtXcXX_andXneqXdXXX_byXageX_byXweightX_byXinXcreatedX_valuesXageX_minX_selectXa_c_dX': [(lambda g:g.V().as_('a').outE('created').as_('b').inV().as_('c').in_('created').as_('d').where('a',P.lt('b').or_(P.gt('c')).and_(P.neq('d'))).by('age').by('weight').by(__.in_('created').age.min()).select('a','c','d').by('name'))],
'g_VX1X_asXaX_out_hasXageX_whereXgtXaXX_byXageX_name': [(lambda g, vid1=None:g.V(vid1).as_('a').out().has('age').where(P.gt('a')).by('age').name)],
+ 'g_VX3X_asXaX_in_out_asXbX_whereXa_eqXbXX_byXageX_name': [(lambda g, vid3=None:g.V(vid3).as_('a').in_().out().as_('b').where('a',P.eq('b')).by('age').name)],
'g_VX1X_asXaX_outXcreatedX_addEXcreatedByX_toXaX': [(lambda g, vid1=None:g.addV('person').property(T.id,1).property('name','marko').property('age',29).as_('marko').addV('person').property(T.id,2).property('name','vadas').property('age',27).as_('vadas').addV('software').property(T.id,3).property('name','lop').property('lang','java').as_('lop').addV('person').property(T.id,4).property('name','josh').property('age',32).as_('josh').addV('software').property(T.id,5).property('name','rippl [...]
'g_VX1X_asXaX_outXcreatedX_addEXcreatedByX_toXaX_propertyXweight_2X': [(lambda g, vid1=None:g.addV('person').property(T.id,1).property('name','marko').property('age',29).as_('marko').addV('person').property(T.id,2).property('name','vadas').property('age',27).as_('vadas').addV('software').property(T.id,3).property('name','lop').property('lang','java').as_('lop').addV('person').property(T.id,4).property('name','josh').property('age',32).as_('josh').addV('software').property(T.id,5).pro [...]
'g_V_outE_propertyXweight_nullX': [(lambda g:g.addV('person').property(T.id,1).property('name','marko').property('age',29).as_('marko').addV('person').property(T.id,2).property('name','vadas').property('age',27).as_('vadas').addV('software').property(T.id,3).property('name','lop').property('lang','java').as_('lop').addV('person').property(T.id,4).property('name','josh').property('age',32).as_('josh').addV('software').property(T.id,5).property('name','ripple').property('lang','java'). [...]
diff --git a/gremlin-test/features/filter/Where.feature b/gremlin-test/features/filter/Where.feature
index 374c63c..f4e8f9b 100644
--- a/gremlin-test/features/filter/Where.feature
+++ b/gremlin-test/features/filter/Where.feature
@@ -324,3 +324,18 @@ Feature: Step - where()
| result |
| josh |
+ # comparison of null "age" values in where()
+ Scenario: g_VX3X_asXaX_in_out_asXbX_whereXa_eqXbXX_byXageX_name
+ Given the modern graph
+ And using the parameter vid3 defined as "v[lop].id"
+ And the traversal of
+ """
+ g.V(vid3).as("a").in().out().as("b").where("a", P.eq("b")).by("age").values("name")
+ """
+ When iterated to list
+ Then the result should be unordered
+ | result |
+ | lop |
+ | lop |
+ | lop |
+ | ripple |
\ No newline at end of file
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTest.java
index 337d627..dd02b59 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTest.java
@@ -123,6 +123,8 @@ public abstract class WhereTest extends AbstractGremlinProcessTest {
public abstract Traversal<Vertex, String> get_g_VX1X_asXaX_out_hasXageX_whereXgtXaXX_byXageX_name(final Object v1Id);
+ public abstract Traversal<Vertex, String> get_g_VX3X_asXaX_in_out_asXbX_whereXa_eqXbXX_byXageX_name(final Object v3Id);
+
@Test
@LoadGraphWith(MODERN)
public void g_V_hasXageX_asXaX_out_in_hasXageX_asXbX_selectXa_bX_whereXa_eqXbXX() {
@@ -406,6 +408,14 @@ public abstract class WhereTest extends AbstractGremlinProcessTest {
assertFalse(traversal.hasNext());
}
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_VX3X_asXaX_in_out_asXbX_whereXa_eqXbXX_byXageX_name() {
+ final Traversal<Vertex, String> traversal = get_g_VX3X_asXaX_in_out_asXbX_whereXa_eqXbXX_byXageX_name(convertToVertexId(graph, "lop"));
+ printTraversalForm(traversal);
+ checkResults(Arrays.asList("lop", "lop", "lop", "ripple"), traversal);
+ }
+
public static class Traversals extends WhereTest {
@@ -535,5 +545,10 @@ public abstract class WhereTest extends AbstractGremlinProcessTest {
public Traversal<Vertex, String> get_g_VX1X_asXaX_out_hasXageX_whereXgtXaXX_byXageX_name(final Object v1Id) {
return g.V(v1Id).as("a").out().has("age").where(gt("a")).by("age").values("name");
}
+
+ @Override
+ public Traversal<Vertex, String> get_g_VX3X_asXaX_in_out_asXbX_whereXa_eqXbXX_byXageX_name(final Object v3Id) {
+ return g.V(v3Id).as("a").in().out().as("b").where("a", eq("b")).by("age").values("name");
+ }
}
}
\ No newline at end of file