You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by jo...@apache.org on 2017/11/30 09:20:02 UTC

[18/33] tinkerpop git commit: Edge and Path result parsing

Edge and Path result parsing


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

Branch: refs/heads/TINKERPOP-1827
Commit: 17d6876b48632dd24c57d681476b1232adea8d1d
Parents: f38c2d0
Author: Jorge Bay Gondra <jo...@gmail.com>
Authored: Fri Nov 3 16:00:50 2017 +0100
Committer: Jorge Bay Gondra <jo...@gmail.com>
Committed: Thu Nov 30 10:00:08 2017 +0100

----------------------------------------------------------------------
 .../Gherkin/CommonSteps.cs                      |  8 +++----
 .../Gherkin/ScenarioData.cs                     | 25 +++++++++++++++++---
 .../ModernGraphTypeInformation.cs               |  4 ++++
 .../TraversalEvaluationTests.cs                 |  3 ++-
 .../TraversalEvaluation/TraversalParser.cs      | 17 +++++++++++--
 5 files changed, 47 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/17d6876b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
index 235f1ba..8b27567 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs
@@ -182,14 +182,14 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
             return ScenarioData.Instance.ModernVertices[name];
         }
 
-        private static Edge ToEdge(string s)
+        private static Edge ToEdge(string name)
         {
-            throw new NotImplementedException();
+            return ScenarioData.Instance.ModernEdges[name];
         }
 
-        private static Path ToPath(string arg)
+        private static Path ToPath(string value)
         {
-            throw new NotImplementedException();
+            return new Path(new List<List<string>>(0), value.Split(',').Select(ParseValue).ToList());
         }
 
         private static object ParseValue(string stringValue)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/17d6876b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/ScenarioData.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/ScenarioData.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/ScenarioData.cs
index c45ed12..d9f66ff 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/ScenarioData.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/ScenarioData.cs
@@ -24,6 +24,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Text.RegularExpressions;
 using Gremlin.Net.IntegrationTest.Process.Traversal.DriverRemoteConnection;
 using Gremlin.Net.Process.Traversal;
 using Gremlin.Net.Structure;
@@ -35,6 +36,10 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
         private static readonly Lazy<ScenarioData> Lazy = new Lazy<ScenarioData>(Load);
         
         public static ScenarioData Instance => Lazy.Value;
+        
+        private static readonly Regex EdgeORegex = new Regex("o=(.+?)[,}]", RegexOptions.Compiled);
+        private static readonly Regex EdgeLRegex = new Regex("l=(.+?)[,}]", RegexOptions.Compiled);
+        private static readonly Regex EdgeIRegex = new Regex("i=(.+?)[,}]", RegexOptions.Compiled);
 
         public IDictionary<string, Vertex> ModernVertices { get; }
         
@@ -50,10 +55,24 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
         {
             var connectionFactory = new RemoteConnectionFactory();
             var g = new Graph().Traversal().WithRemote(connectionFactory.CreateRemoteConnection());
-            //TODO: Remove workaround once Group() is fixed TINKERPOP-1752
-            var vertices = g.V().ToList().ToDictionary(v => g.V(v.Id).Values<string>("name").Next(), v => v);
+            var vertices = g.V().Group<string, object>().By("name").By(__.Tail<Vertex>()).Next()
+                .ToDictionary(kv => kv.Key, kv => (Vertex)kv.Value);
+            var edges = g.E().Group<string, object>()
+                .By(__.Project<Edge>("o", "l", "i")
+                    .By(__.OutV().Values<string>("name")).By(__.Label()).By(__.InV().Values<string>("name")))
+                .By(__.Tail<object>())
+                .Next()
+                .ToDictionary(kv => GetEdgeKey(kv.Key), kv => (Edge)kv.Value);
             connectionFactory.Dispose();
-            return new ScenarioData(vertices, null);
+            return new ScenarioData(vertices, edges);
+        }
+
+        private static string GetEdgeKey(string key)
+        {
+            var o = EdgeORegex.Match(key).Groups[1].Value;
+            var l = EdgeLRegex.Match(key).Groups[1].Value;
+            var i = EdgeIRegex.Match(key).Groups[1].Value;
+            return o + "-" + l + "->" + i;
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/17d6876b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs
index e26ec5f..7e2bee1 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs
@@ -59,6 +59,10 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                 case nameof(GraphTraversal<object,object>.ValueMap):
                     // Use IDictionary<string, object> for value maps
                     return typeof(object);
+                case nameof(GraphTraversal<object,object>.Limit):
+                case nameof(GraphTraversal<object,object>.Optional):
+                    // Maintain the same type
+                    return method.DeclaringType.GetGenericArguments()[1];
             }
             return null;
         }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/17d6876b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs
index d2a62b4..aaca93f 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs
@@ -81,7 +81,8 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                 Tuple.Create("g.V().valueMap(true, \"name\", \"age\")", 2),
                 Tuple.Create("g.V().where(__.in(\"created\").count().is(1)).values(\"name\")", 3),
                 Tuple.Create("g.V().count(Scope.local)", 2),
-                Tuple.Create("g.V().values(\"age\").is(P.lte(30))", 3)
+                Tuple.Create("g.V().values(\"age\").is(P.lte(30))", 3),
+                Tuple.Create("g.V().optional(__.out().optional(__.out())).path().limit(1)", 4)
             };
             var g = new Graph().Traversal();
             foreach (var tuple in traversalTexts)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/17d6876b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs
index bb0aac8..b5efb8d 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs
@@ -44,6 +44,11 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
         private static readonly Regex RegexEnum = new Regex(@"\w+\.\w+", RegexOptions.Compiled);
 
         private static readonly Regex RegexParam = new Regex(@"\w+", RegexOptions.Compiled);
+        
+        private static readonly HashSet<Type> NumericTypes = new HashSet<Type>
+        {
+            typeof(int), typeof(long), typeof(double), typeof(float), typeof(short), typeof(decimal), typeof(byte)
+        };
 
         internal static ITraversal GetTraversal(string traversalText, GraphTraversalSource g,
                                                 IDictionary<string, object> contextParameterValues)
@@ -151,9 +156,15 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                     }
                     else
                     {
-                        if (!methodParameter.ParameterType.GetTypeInfo().IsAssignableFrom(tokenParameterType))
+                        if (IsNumeric(methodParameter.ParameterType) && IsNumeric(tokenParameterType))
                         {
-                            break;   
+                            // Acount for implicit conversion of numeric values as an exact match 
+                            exactMatches++;
+                        }
+                        else if (!methodParameter.ParameterType.GetTypeInfo().IsAssignableFrom(tokenParameterType))
+                        {
+                            // Not a match
+                            break;
                         }
                         // Is assignable to the parameter type
                         matched = true;
@@ -169,6 +180,8 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation
                    lastMethod;
         }
 
+        private static bool IsNumeric(Type t) => NumericTypes.Contains(t);
+
         private static bool IsParamsArray(ParameterInfo methodParameter)
         {
             return methodParameter.IsDefined(typeof(ParamArrayAttribute), false);