Skip to content

Commit 6aad191

Browse files
authored
Change tail feature test to use valueMap instead of inject as to not be affected by GLV map ordering (#3193)
https://issues.apache.org/jira/browse/TINKERPOP-2491 Change tail feature test to use valueMap() instead of inject(map) as to not be affected by go's lack of ordered map data structure. Added a note to go limitations about the lack of native support for ordered map.
1 parent a1f1680 commit 6aad191

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

docs/src/reference/gremlin-variants.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,9 @@ type implementation. To input a set into Gremlin-Go, a custom struct which imple
517517
will be serialized as a set. `gremlingo.NewSimpleSet` is a basic implementation of a set that is provided by Gremlin-Go
518518
that can be used to fulfill the `gremlingo.Set` interface if desired.
519519
520+
* Go does not support ordered maps natively as the built-in `map` type does not guarantee iteration order. Traversal
521+
results which contain maps may not preserve original ordering when deserialized into Go's native map types.
522+
520523
[[gremlin-go-examples]]
521524
=== Application Examples
522525

gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ private static IDictionary<string, List<Func<GraphTraversalSource, IDictionary<s
448448
{"g_V_asXaX_out_asXaX_out_asXaX_selectXmixed_aX_byXunfold_valuesXnameX_foldX_tailXlocal_2X", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V().As("a").Out().As("a").Out().As("a").Select<object>(Pop.Mixed, "a").By(__.Unfold<object>().Values<object>("name").Fold()).Tail<object>(Scope.Local, 2)}},
449449
{"g_VX1X_valuesXageX_tailXlocal_5X", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p["vid1"]).Values<object>("age").Tail<object>(Scope.Local, 50)}},
450450
{"g_injectXlistX1_2_3XX_tailXlocal_1X", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject<object>(new List<object> { 1, 2, 3 }).Tail<object>(Scope.Local, 1)}},
451-
{"g_injectXa1_b2_c3X_tailXlocal_1X", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject<object>(new Dictionary<object, object> {{ "a", 1 }, { "b", 2 }, { "c", 3 }}).Tail<object>(Scope.Local, 1)}},
451+
{"g_VX1X_valueMapXnameX_tailXlocal_1X", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.V(p["vid1"]).ValueMap<object, object>("name").Tail<object>(Scope.Local, 1)}},
452452
{"g_injectX1_2_3X_tailXlocal_1X_unfold", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject<object>(new List<object> { 1, 2, 3 }).Tail<object>(Scope.Local, 1).Unfold<object>()}},
453453
{"g_injectX1_2_3_4_5_6X_tailXlocal_1X", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject<object>(new List<object> { 1, 2, 3 }, new List<object> { 4, 5, 6 }).Tail<object>(Scope.Local, 1)}},
454454
{"g_injectX1_2_3_4_5X_tailXlocal_2X", new List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject<object>(new List<object> { 1, 2, 3, 4, 5 }).Tail<object>(Scope.Local, 2)}},

gremlin-go/driver/cucumber/gremlin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ var translationMap = map[string][]func(g *gremlingo.GraphTraversalSource, p map[
418418
"g_V_asXaX_out_asXaX_out_asXaX_selectXmixed_aX_byXunfold_valuesXnameX_foldX_tailXlocal_2X": {func(g *gremlingo.GraphTraversalSource, p map[string]interface{}) *gremlingo.GraphTraversal {return g.V().As("a").Out().As("a").Out().As("a").Select(gremlingo.Pop.Mixed, "a").By(gremlingo.T__.Unfold().Values("name").Fold()).Tail(gremlingo.Scope.Local, 2)}},
419419
"g_VX1X_valuesXageX_tailXlocal_5X": {func(g *gremlingo.GraphTraversalSource, p map[string]interface{}) *gremlingo.GraphTraversal {return g.V(p["vid1"]).Values("age").Tail(gremlingo.Scope.Local, 50)}},
420420
"g_injectXlistX1_2_3XX_tailXlocal_1X": {func(g *gremlingo.GraphTraversalSource, p map[string]interface{}) *gremlingo.GraphTraversal {return g.Inject([]interface{}{1, 2, 3}).Tail(gremlingo.Scope.Local, 1)}},
421-
"g_injectXa1_b2_c3X_tailXlocal_1X": {func(g *gremlingo.GraphTraversalSource, p map[string]interface{}) *gremlingo.GraphTraversal {return g.Inject(map[interface{}]interface{}{"a": 1, "b": 2, "c": 3 }).Tail(gremlingo.Scope.Local, 1)}},
421+
"g_VX1X_valueMapXnameX_tailXlocal_1X": {func(g *gremlingo.GraphTraversalSource, p map[string]interface{}) *gremlingo.GraphTraversal {return g.V(p["vid1"]).ValueMap("name").Tail(gremlingo.Scope.Local, 1)}},
422422
"g_injectX1_2_3X_tailXlocal_1X_unfold": {func(g *gremlingo.GraphTraversalSource, p map[string]interface{}) *gremlingo.GraphTraversal {return g.Inject([]interface{}{1, 2, 3}).Tail(gremlingo.Scope.Local, 1).Unfold()}},
423423
"g_injectX1_2_3_4_5_6X_tailXlocal_1X": {func(g *gremlingo.GraphTraversalSource, p map[string]interface{}) *gremlingo.GraphTraversal {return g.Inject([]interface{}{1, 2, 3}, []interface{}{4, 5, 6}).Tail(gremlingo.Scope.Local, 1)}},
424424
"g_injectX1_2_3_4_5X_tailXlocal_2X": {func(g *gremlingo.GraphTraversalSource, p map[string]interface{}) *gremlingo.GraphTraversal {return g.Inject([]interface{}{1, 2, 3, 4, 5}).Tail(gremlingo.Scope.Local, 2)}},

gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/gremlin.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gremlin-python/src/main/python/radish/gremlin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@
421421
'g_V_asXaX_out_asXaX_out_asXaX_selectXmixed_aX_byXunfold_valuesXnameX_foldX_tailXlocal_2X': [(lambda g:g.V().as_('a').out().as_('a').out().as_('a').select(Pop.mixed, 'a').by(__.unfold().values('name').fold()).tail(Scope.local, 2))],
422422
'g_VX1X_valuesXageX_tailXlocal_5X': [(lambda g, vid1=None:g.V(vid1).values('age').tail(Scope.local, 50))],
423423
'g_injectXlistX1_2_3XX_tailXlocal_1X': [(lambda g:g.inject([1, 2, 3]).tail(Scope.local, 1))],
424-
'g_injectXa1_b2_c3X_tailXlocal_1X': [(lambda g:g.inject({ 'a': 1, 'b': 2, 'c': 3 }).tail(Scope.local, 1))],
424+
'g_VX1X_valueMapXnameX_tailXlocal_1X': [(lambda g, vid1=None:g.V(vid1).value_map('name').tail(Scope.local, 1))],
425425
'g_injectX1_2_3X_tailXlocal_1X_unfold': [(lambda g:g.inject([1, 2, 3]).tail(Scope.local, 1).unfold())],
426426
'g_injectX1_2_3_4_5_6X_tailXlocal_1X': [(lambda g:g.inject([1, 2, 3], [4, 5, 6]).tail(Scope.local, 1))],
427427
'g_injectX1_2_3_4_5X_tailXlocal_2X': [(lambda g:g.inject([1, 2, 3, 4, 5]).tail(Scope.local, 2))],

gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/test/features/filter/Tail.feature

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,17 @@ Feature: Step - tail()
239239
| l[d[3].i] |
240240

241241
# Test that Map local tail 1 - should still return single entry
242-
Scenario: g_injectXa1_b2_c3X_tailXlocal_1X
243-
Given the empty graph
242+
Scenario: g_VX1X_valueMapXnameX_tailXlocal_1X
243+
Given the modern graph
244+
And using the parameter vid1 defined as "v[marko].id"
244245
And the traversal of
245246
"""
246-
g.inject(["a": 1, "b": 2, "c": 3]).tail(Scope.local, 1)
247+
g.V(vid1).valueMap("name").tail(Scope.local, 1)
247248
"""
248249
When iterated to list
249250
Then the result should be unordered
250251
| result |
251-
| m[{"c": 3}] |
252+
| m[{"name":["marko"]}] |
252253

253254
# Test unfold() can be used to extract single elements from collections for tail
254255
Scenario: g_injectX1_2_3X_tailXlocal_1X_unfold

0 commit comments

Comments
 (0)