0

I have imported a graph and can confirm that the number of vertex and edges matches the number that should be present. I run the simplepath() compute on the graph and my first question is how to access the path array or map whatever is returned, i think i understand as i add the .toList and print it to the console however i simply get [] an empty array?

What am i doing wrong i need to access the result set that comes back from the path?

my query which is run in Java not in the gramlin console is:

g.V().has("id", "FirstVertexIdValue").shortestPath().with(ShortestPath.target, __.has("id", "EndVertexIdValue")).with(ShortestPath.distance, "weight").toList();

I also run the following and still return an empty array:

g.V("startVertexId").out().simplePath().until(hasId("endVertexId").path().limit(1);

the response when systemOut printed is []

in addition the graphml doc sample is here, its a pretty big doc so i have just included 2 vertex and 2 edges:

<?xml version='1.0' encoding='utf-8'?>
<graphml xmlns='http://graphml.graphdrawing.org/xmlns' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd'>
  <key attr.name='weight' attr.type='double' for='edge' id='weight' />
  <key attr.name='edgeid' attr.type='string' for='edge' id='edgeid' />
  <key attr.name='alpha' attr.type='string' for='edge' id='alpha' />
  <key attr.name='intendedpathlonlat' attr.type='string' for='edge' id='intendedpathlonlat' />
  <key attr.name='levelid' attr.type='string' for='edge' id='levelid' />
  <key attr.name='type' attr.type='string' for='edge' id='type' />
  <key attr.name='relatedroutes' attr.type='string' for='node' id='relatedroutes' />
  <key attr.name='description' attr.type='string' for='node' id='description' />
  <key attr.name='title' attr.type='string' for='node' id='title' />
  <key attr.name='on_finish_route' attr.type='string' for='node' id='on_finish_route' />
  <key attr.name='on_starting_route' attr.type='string' for='node' id='on_starting_route' />
  <key attr.name='level_id' attr.type='string' for='node' id='level_id' />
  <key attr.name='waypoint_type' attr.type='string' for='node' id='waypoint_type' />
  <key attr.name='name' attr.type='string' for='node' id='name' />
  <key attr.name='lon' attr.type='string' for='node' id='lon' />
  <key attr.name='lat' attr.type='string' for='node' id='lat' />
  <graph edgedefault='directed' id='Station'>
    <node id='L08-022'>
      <data key='lat'>40.69330963</data>
      <data key='lon'>-73.98752537</data>
      <data key='name' />
      <data key='waypoint_type'>escalator</data>
      <data key='level_id'>1080000</data>
      <data key='on_starting_route' />
      <data key='on_finish_route' />
    </node>
    <node id='L08-023'>
      <data key='lat'>40.69318355</data>
      <data key='lon'>-73.98755793</data>
      <data key='name' />
      <data key='waypoint_type'>stairs</data>
      <data key='level_id'>1080000</data>
      <data key='on_starting_route' />
      <data key='on_finish_route' />
    </node>
    <edge source='WL10-054' target='L10-029'>
      <data key='type'>floor</data>
      <data key='weight'>4.22</data>
      <data key='levelid'>1100000</data>
      <data key='intendedpathlonlat'></data>
      <data key='alpha'>0.0</data>
      <data key='edgeid'>RL10-059</data>
    </edge>
    <edge source='WL10-054' target='WL10-053'>
      <data key='type'>floor</data>
      <data key='weight'>5.69</data>
      <data key='levelid'>1100000</data>
      <data key='intendedpathlonlat'></data>
      <data key='alpha'>0.0</data>
      <data key='edgeid'>RL10-060</data>
    </edge>
</graph>
</graphml>

A sample of the queries tried:

gremlin> g.V().has('T.id', 'L00-041').shortestPath().with(ShortestPath.target, __.has('T.id', 'L04-070')).with(ShortestPath.distance, 'weight').toList()
gremlin> g.V().has('T.id', 'L04-070').out().values('waypoint_type').fold()
==>[]
gremlin> g.V().has('T.id', 'L04-070').out().fold()
==>[]
gremlin> g.V().has('T.id', 'L04-070').out().values('lat').fold()
docker dev
  • 91
  • 3
  • 10

1 Answers1

1

Without some sample data it's hard to tell what might be completely wrong but here's some things to consider based on the Gremlin in your question:

  • shortestPath()-step is a an OLAP step and therefore requires that you define g using withComputer() - an example can be found here.
  • I notice that you search for your starting vertex in two different ways in each of your queries. In the first case you search by a property named "id" and in the second you search by the vertex identifier (referenced as T.id when used in has()). Perhaps that initial starting vertex isn't found properly?
  • The second traversal looks invalid as it tries to do a loop (i.e. it has an until() condition) but does not specify a repeat() operation.

When my traversals don't return what I expect, I try to simplify them to the point where I can see where the traversal is filtering away the traversers that I expected. In other words, have Gremlin Console open and your graph connected. Ensure that g.V("startVertexId") returns the vertex you expect. When satisfied of the result, add a step, run g.V("startVertexId").out() and validate that. Continue with that pattern until you find out where your results are not returning. You can also run your traversal with profile() step and it should show you where the traversers are filtering away, but sometimes it's easier to recognize by picking the traversal apart and simplifying.

I tested your traversal with the data you recently supplied in your question and when I make the adjustments as suggested in my answer and comments I don't seem to have a problem getting results:

gremlin> g.withComputer().V('WL10-054').shortestPath().with(ShortestPath.target, __.hasId('L10-029')).with(ShortestPath.distance, 'weight')
==>[v[WL10-054],v[L10-029]]
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • @stephenMallete Thank you i can certainly share more info, However the steps you have outlined to build the traversal piece by piece make great sense so i will go away and try that initially. Thank you for your advice. Much appreciated and i will update the question when i have been through that process. – docker dev Apr 09 '20 at 10:55
  • If my hints above don't lead you to an answer it would be helpful to have a small bit of sample data as a Gremlin script that can recreate the problem, as in this example: https://stackoverflow.com/questions/51388315/gremlin-choose-one-item-at-random – stephen mallette Apr 09 '20 at 11:00
  • I have taken steps through the gremlin console. vertex and edges are there, properties are there however if i try to run: g.V().has('T.id', 'L04-070').out().values('lat').fold() I get the [] zero array, it feels as if my edges are not connected to my vertices? my edges source and targets are the vertex id values 'L04-070' for example. how can i check its all connected? – docker dev Apr 09 '20 at 12:39
  • I will add sample data now – docker dev Apr 09 '20 at 12:41
  • I have a dded some extra info, my set up was: graph = TinkerGraph.open(), g = graph.traversal(), g = graph.traversal().withComputer() – docker dev Apr 09 '20 at 12:49
  • Quick one my vertices print out as: ==>v[L08-086], where as my edges print out as: ==>e[1000][31-route->3], are they using different id's? – docker dev Apr 09 '20 at 13:35
  • it's `T.id` not `"T.id"` - `T` is an enumeration - https://tinkerpop.apache.org/javadocs/current/core/org/apache/tinkerpop/gremlin/structure/T.html - i assume that's why you get no results. in your case though i would simple do: `g.V('L00-041')` and `hasId('L04-070')` – stephen mallette Apr 09 '20 at 14:47
  • As for your question about the edge id not matching "edgeId" in your graphml file, I think that's because the structure of your graphml should be such that the "edgeId" be added as an attribute of the `` element as in `` rather than making it a property key. – stephen mallette Apr 09 '20 at 15:58
  • Thank you, that was spot on. The g..V('L00-041') is the way to go for me. I will query the Graphml structure and see if any changes can be made but my traversals are returning edges now. I would consider that a fix for me. Thank you so much Stephen. – docker dev Apr 09 '20 at 18:53
  • Ran into another query, so i have started a new question, you may be able to help me with off the top of your head? Thanks: https://stackoverflow.com/questions/61177108/re-running-an-existing-route-in-a-tinkerpop-graph – docker dev Apr 12 '20 at 19:41