0

I am using Java with Tinkerpop v. 3.5.1

I have a graph DB that contains many "smaller" graphs in it. I want to traverse the graph from a starting point (it could be different depending on the query) and collect some properties from different vertices along the way.

The basic outline of a "smaller" graph looks like:

             Admin
               |
               v
 Student --> School --> Class <-- ClassReq

edited: (I made some small progress, so here is where I am at now)

Here is an example graph from gremlify:

g.addV('Student').as('1').
  property(single, 'name', 'Peter').
  property(single, 'age', 22).addV('School').
    as('2').
  property(single, 'name', 'Jefferson').
  property(single, 'address', '1234 Jefferson St.').
  addV('Administration').as('3').
  property(single, 'status', 'AFW').
  property(single, 'level', '4.2A').
  addV('Class').as('4').
  property(single, 'name', 'Math').
  property(single, 'level', 2).addV('ClassReq').
    as('5').
  property(single, 'name', 'Math').
  property(single, 'level', 1).addV('Student').
    as('6').
  property(single, 'name', 'Sam').
  property(single, 'age', 24).addV('Class').
    as('7').
  property(single, 'name', 'English').
  property(single, 'level', 2).addE('attends').
  from('1').to('2').addE('administers').
  from('3').to('2').addE('isReqsFor').from('5').
  to('4').addE('offers').from('2').to('4').
  addE('attends').from('6').to('2').
  addE('offers').from('2').to('7')

I am trying to use .aggregate() with .by(), but I am not getting all of the values out that I am expecting.

g.V().has("name", "Jefferson").out("offers").aggregate("x").by("level").by("name").cap("x")

If I do that, I only get the last .by() fields returned:

[
  [
    "English",
    1,
    "Math",
    1
  ]
]

I don't know what those 1 fields are, because the level that I was expecting are 2. But even if I don't include the level as a .by(), I get the exact same result.

From the Tinkerpop docs, it looks like I should be able to use .by("someField").by("someOtherField") and it would return both fields...but I am not getting them.

gremlin> g.V().out().out().path().by('name').by('age')
==>[marko,32,ripple]
==>[marko,32,lop]

Edit: Sorry, forgot to add a desired result. I would like to have something like:

g.V().has("name", "Jefferson").out("offers").aggregate("x").by("level").by("name").cap("x").in("offers").out("administers").aggregate("y").by("status").cap("y").in("administers").out("attends").aggregate("z").by("name").by("age").cap("z)

And have it return the data, preferably as key/value pairs, but I am unsure how to get the data with .valueMap() when I use .aggregate() and .cap(). So a result something like:

[
   [
      "level": 2,
      "name": "English
   ],
   [
      "level": 2,
      "name": "Math
   ],
   [
      "status": "AFW"
   ],
   [
      "name": "Peter",
      "age": 22
   ],
   [
      "name": "Sam",
      "age": 24
   ]
]
Ebad
  • 131
  • 11
  • It will help people to provide you tested answers if you can provide the `addV` and `addE` steps that build a small example graph. It is likely that all you need is the `path` step, but a sample graph and an example of the desired output will help. An example of building a sample graph can be found in the answer to this post https://stackoverflow.com/questions/73433016/gremlin-traverse-path-along-the-same-property/73449813#73449813 – Kelvin Lawrence Aug 28 '22 at 12:35
  • It is also fun to read Kelvin's book on gremlin, in particular, see: https://www.kelvinlawrence.net/book/PracticalGremlin.html#aselproj – HadoopMarc Aug 28 '22 at 12:40
  • @KelvinLawrence I edited my question and added an example graph. I made some small progress, but still can't get multiple values from multiple vertices. – Ebad Sep 13 '22 at 13:28
  • 1
    Thanks will take a look. I also answered your other question and explained what those "1" values are in that answer: https://stackoverflow.com/questions/73709078/tinkerpop-multiple-by-only-returning-the-last-by-value – Kelvin Lawrence Sep 14 '22 at 00:02

0 Answers0