0

I have a Gremlin API Cosmos DB. In the DB I have one type of Vertice with Label User that are connected to Vertices labeled Companies. I then want to show all connected companies. I do the query g.V('id-of-User').outE() and gets all connected Companies. The result might look something like this:

[
  {
    "id": "08f97a1d-9e81-4ccc-a498-90eb502b1879",
    "label": "AuthorizedSignatory",
    "type": "edge",
    "inVLabel": "Company",
    "outVLabel": "User",
    "inV": "abd51134-1524-44fe-8a49-60d2d449a1f3",
    "outV": "103bf1b9-464f-4f68-a4ca-7dfdbe94ae84"
  },
  {
    "id": "c36b640b-9574-403b-8ab6-fcce695caa90",
    "label": "AuthorizedSignatory",
    "type": "edge",
    "inVLabel": "Company",
    "outVLabel": "User",
    "inV": "2c14d279-00a4-41ad-a8c0-f3b882864568",
    "outV": "103bf1b9-464f-4f68-a4ca-7dfdbe94ae84"
  }
]

This is absolutely as expected. Now I want to take this a bit further and instead of just showing the GUID in the inV parameter I also want to include the Company Name in the result object, but I do not understand how to do the equivalent to a SQL join here.

Can someone please help me!!

What I want is something similar to the example below:

[
  {
    "id": "08f97a1d-9e81-4ccc-a498-90eb502b1879",
    "label": "AuthorizedSignatory",
    "type": "edge",
    "inVLabel": "Company",
    "outVLabel": "User",
    "inV": "abd51134-1524-44fe-8a49-60d2d449a1f3",
    "outV": "103bf1b9-464f-4f68-a4ca-7dfdbe94ae84",
    "CompanyName": "ACME CORP"
  },
  {
    "id": "c36b640b-9574-403b-8ab6-fcce695caa90",
    "label": "AuthorizedSignatory",
    "type": "edge",
    "inVLabel": "Company",
    "outVLabel": "User",
    "inV": "2c14d279-00a4-41ad-a8c0-f3b882864568",
    "outV": "103bf1b9-464f-4f68-a4ca-7dfdbe94ae84",
    "CompanyName": "Giganticorp"
  }
]

Where the CompanyName is one of the properties in the Company Vertice with the guid in inV prop.

Kamal Panhwar
  • 2,345
  • 3
  • 21
  • 37

1 Answers1

0

There is no "join". The data is already connected by way of the edge, so you simply need to traverse further along your graph to get the "CompanyName".

g.V('id-of-User').out().values("CompanyName")

That shows you all of the names of the companies related to that user. If you're saying that you still want to show the data from the edge in addition to company name as you had in your examples, then no problem, project() the edge being specific about what you want:

g.V('id-of-User').outE().
  project('eid','label','companyName').
    by(T.id).
    by(T.label).
    by(inV().values("CompanyName"))

Again, note that there is no "join" for the "CompanyName". As the data is implicitly joined by way of the edge you just need to traverse over inV() to reach the data there.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • Thank you. This did exactly what I wanted. :D I know that there are no "joins" therefore I said equivalent to be clear of what I wanted. Thank you very much Stephen... – Magnus Jansson Apr 12 '19 at 12:38
  • ok - i only hammered on "join" because we get a lot of questions where folks try to do SQL-like joins without edges, like matching two unconnected vertices by way of their property values. that doesn't work well for graph queries in most cases unless you've severely restricted the vertices you want to match that way. – stephen mallette Apr 12 '19 at 13:33