Reputation: 16147
I have this query that it is working as expected for me.
g.V().or(hasLabel("poi"),hasLabel("business")).as("dest")
.outE().inV().hasLabel("region").as("reg")
.select("dest").values("name").as("dest_name")
.select("dest").values("budget").as("dest_budget")
.select("reg").values("name").as("reg_name")
.select("reg_name","dest_name","dest_budget")
This query yields this result.
As I have expected. However I need to retrieve more properties from the "destination" I need to retrieve more 10 properties. This will me into something like this
g.V().or(hasLabel("poi"),hasLabel("business")).as("dest")
.outE().inV().hasLabel("region").as("reg")
.select("dest").values("name").as("dest_name")
.select("dest").values("budget").as("dest_budget")
.select("dest").values("property3").as("property3")
.select("dest").values("property4").as("property4")
//insert more queries like from the above
.select("reg").values("name").as("reg_name")
.select("reg_name","dest_name","dest_budget","property3","property4")
The query will grow long eventually which I am trying to avoid since I need to select values as well from the region as well. So My initial thought was to use select to select multiple values and label them each with an alias like this
g.V().
or(hasLabel("poi"),hasLabel("business"))
.as("destination")
.outE().inV().as("region")
.select("destination").values("name","budget").as("dest_name","dest_budget")
.select("region").values("name").as("reg_name")
.select("dest_name","reg_name","dest_budget")
However I was surprised with this result. Which I was not expecting.
To my understanding the names in values will be mapped to each values passed in the as step. Am I wrong?
Is there anyway for me to retrieve the result from the first screenshot without writing a long query?
Upvotes: 3
Views: 720
Reputation: 46226
The as()
labels the step, not the values within that step. So by doing:
.select("destination").values("name","budget").as("dest_name","dest_budget")
you're just naming the values()
step twice. I think that you can drastically simplify this traversal for what you want to get as the result though and it doesn't involve stringing together a lot of select()
steps:
g.V().or(hasLabel("poi"),hasLabel("business")).
project('dest_name','dest_budget','reg_name').
by('name').
by('budget').
by(out().hasLabel("region").values('name').fold())
You will get a slightly different structure in that "reg_name" will be a list of all the region names rather than having a flattened structure, but you could unroll that I imagine if needed.
Upvotes: 2