lostinplace
lostinplace

Reputation: 1518

Gremlin where query won't use values from labeled vertices

I'm trying to find the edge between 2 vertexes in a single query on Neptun, but something is really weird.

Here's the query

g.V().has("PRINCIPAL", "principal id", "Test User").as("principal").id().as("principal_id")
.select("principal").out().hasLabel("LICENSE").as("license").valueMap(true).as("license_vm")
.select("license").in("is attached to").as("attachments")
.select("license").inE().where(outV().hasId(select("principal").id()))

.valueMap(true)

I know it's complicated, but here's the idea:

  1. Visit a PRINCIPAL vertex, save a reference to is as "principal" and a reference to its id as "principal_id"
  2. Visit its out() vertices and label them as "license", I'm also saving their valuemaps for later
  3. return to license, and get all of the in() vertices that are associated by an edge labelled "is attached to", save a reference to those as "attachments"
  4. return to license, but now, I want to get the in-edge that points to my "principal" (from earlier). This is where it gets weird, no matter what I do here, I can't get it to recognize the principal in a where clause. THe above example fails, but if I copy-paste the literal id, it works fine

What am I missing?

Upvotes: 1

Views: 386

Answers (1)

Kelvin Lawrence
Kelvin Lawrence

Reputation: 14371

Replace the where step on the second to last line of the query with:

filter(out().where(eq('principal')).by(T.id))

That should get it working.

The hasId step can take either a predicate such as gt(123) or a list of one or more ID values. That's why it works when you use the ID value.

Upvotes: 1

Related Questions