Gremlin Query to return multiple Result in a ResultSet
up vote
1
down vote
favorite
May be my understanding of gremlin query is wrong :). I am trying to execute a query from Java client and the query is: g.V().hasLabel('MYLABEL').
Have multiple (say 20) vertices that match the label and the ResultSet just have one Result with the data of all twenty vertices included. I would like to have the ResultSet with 20 Results. What way that I need to rearrange the query. please suggest.
gremlin tinkerpop
add a comment |
up vote
1
down vote
favorite
May be my understanding of gremlin query is wrong :). I am trying to execute a query from Java client and the query is: g.V().hasLabel('MYLABEL').
Have multiple (say 20) vertices that match the label and the ResultSet just have one Result with the data of all twenty vertices included. I would like to have the ResultSet with 20 Results. What way that I need to rearrange the query. please suggest.
gremlin tinkerpop
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
May be my understanding of gremlin query is wrong :). I am trying to execute a query from Java client and the query is: g.V().hasLabel('MYLABEL').
Have multiple (say 20) vertices that match the label and the ResultSet just have one Result with the data of all twenty vertices included. I would like to have the ResultSet with 20 Results. What way that I need to rearrange the query. please suggest.
gremlin tinkerpop
May be my understanding of gremlin query is wrong :). I am trying to execute a query from Java client and the query is: g.V().hasLabel('MYLABEL').
Have multiple (say 20) vertices that match the label and the ResultSet just have one Result with the data of all twenty vertices included. I would like to have the ResultSet with 20 Results. What way that I need to rearrange the query. please suggest.
gremlin tinkerpop
gremlin tinkerpop
asked yesterday
Sony Joseph
96
96
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
Just use fold() as in - you can see my example here:
gremlin> cluster = Cluster.open()
==>localhost/127.0.0.1:8182
gremlin> client = cluster.connect()
==>org.apache.tinkerpop.gremlin.driver.Client$ClusteredClient@51efb731
gremlin> r = client.submit("g.V().hasLabel('person')").all().get()
==>result{object=v[1] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[2] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[4] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[6] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
gremlin> r = client.submit("g.V().hasLabel('person').fold()").all().get()
==>result{object=[v[1], v[2], v[4], v[6]] class=java.util.ArrayList}
Note that the downside to fold() in this example is that the result won't be streamed back to the client. You will build the entire list in memory on the server and then it will serialize that list as a single payload. If that list is sufficiently large and you generate enough of such lists you may hit memory/GC issues.
-> What I expect to get is moe number of Results in the resultset instead of a whole big list of vertices in a single Map. So if it works like in your first query, it is great. But, the problem is, from a gremlin console I too get similar resp and not when I use a java client. probably due to groovy vs java thing.
– Sony Joseph
yesterday
I'm sorry, but i don't follow your comment. There should be no difference in this case with Groovy vs Java in this case - the behavior should be the same. If I've not answered your question I think you will need to clarify further.
– stephen mallette
yesterday
your understanding of my comment is correct. Ideally, with both groovy and Java the query resulstset must be of same kind. But unfortunately, I get them as different. I ran the query from both java and console to the same remote DB.
– Sony Joseph
12 hours ago
when I ran from groovy I got a resultset with multiple results but from Java I got one result with entire data in it.
– Sony Joseph
12 hours ago
client.submit()always returns oneResultSetobject - same for Groovy and Java. However,ResultSetis anIterable. So, in the first example above that usessubmit()you get oneResultSetwith 4 items in it. You would get the same in Java. In the Gremlin Console however, it notices theResultSetis anIterableand shows you what's inside. It does the same for the secondsubmit()example, but in that case we usedfold()and thus created a result with only oneListso when the Console iterates theResultSetyou only get one result.
– stephen mallette
5 hours ago
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Just use fold() as in - you can see my example here:
gremlin> cluster = Cluster.open()
==>localhost/127.0.0.1:8182
gremlin> client = cluster.connect()
==>org.apache.tinkerpop.gremlin.driver.Client$ClusteredClient@51efb731
gremlin> r = client.submit("g.V().hasLabel('person')").all().get()
==>result{object=v[1] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[2] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[4] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[6] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
gremlin> r = client.submit("g.V().hasLabel('person').fold()").all().get()
==>result{object=[v[1], v[2], v[4], v[6]] class=java.util.ArrayList}
Note that the downside to fold() in this example is that the result won't be streamed back to the client. You will build the entire list in memory on the server and then it will serialize that list as a single payload. If that list is sufficiently large and you generate enough of such lists you may hit memory/GC issues.
-> What I expect to get is moe number of Results in the resultset instead of a whole big list of vertices in a single Map. So if it works like in your first query, it is great. But, the problem is, from a gremlin console I too get similar resp and not when I use a java client. probably due to groovy vs java thing.
– Sony Joseph
yesterday
I'm sorry, but i don't follow your comment. There should be no difference in this case with Groovy vs Java in this case - the behavior should be the same. If I've not answered your question I think you will need to clarify further.
– stephen mallette
yesterday
your understanding of my comment is correct. Ideally, with both groovy and Java the query resulstset must be of same kind. But unfortunately, I get them as different. I ran the query from both java and console to the same remote DB.
– Sony Joseph
12 hours ago
when I ran from groovy I got a resultset with multiple results but from Java I got one result with entire data in it.
– Sony Joseph
12 hours ago
client.submit()always returns oneResultSetobject - same for Groovy and Java. However,ResultSetis anIterable. So, in the first example above that usessubmit()you get oneResultSetwith 4 items in it. You would get the same in Java. In the Gremlin Console however, it notices theResultSetis anIterableand shows you what's inside. It does the same for the secondsubmit()example, but in that case we usedfold()and thus created a result with only oneListso when the Console iterates theResultSetyou only get one result.
– stephen mallette
5 hours ago
|
show 1 more comment
up vote
1
down vote
Just use fold() as in - you can see my example here:
gremlin> cluster = Cluster.open()
==>localhost/127.0.0.1:8182
gremlin> client = cluster.connect()
==>org.apache.tinkerpop.gremlin.driver.Client$ClusteredClient@51efb731
gremlin> r = client.submit("g.V().hasLabel('person')").all().get()
==>result{object=v[1] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[2] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[4] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[6] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
gremlin> r = client.submit("g.V().hasLabel('person').fold()").all().get()
==>result{object=[v[1], v[2], v[4], v[6]] class=java.util.ArrayList}
Note that the downside to fold() in this example is that the result won't be streamed back to the client. You will build the entire list in memory on the server and then it will serialize that list as a single payload. If that list is sufficiently large and you generate enough of such lists you may hit memory/GC issues.
-> What I expect to get is moe number of Results in the resultset instead of a whole big list of vertices in a single Map. So if it works like in your first query, it is great. But, the problem is, from a gremlin console I too get similar resp and not when I use a java client. probably due to groovy vs java thing.
– Sony Joseph
yesterday
I'm sorry, but i don't follow your comment. There should be no difference in this case with Groovy vs Java in this case - the behavior should be the same. If I've not answered your question I think you will need to clarify further.
– stephen mallette
yesterday
your understanding of my comment is correct. Ideally, with both groovy and Java the query resulstset must be of same kind. But unfortunately, I get them as different. I ran the query from both java and console to the same remote DB.
– Sony Joseph
12 hours ago
when I ran from groovy I got a resultset with multiple results but from Java I got one result with entire data in it.
– Sony Joseph
12 hours ago
client.submit()always returns oneResultSetobject - same for Groovy and Java. However,ResultSetis anIterable. So, in the first example above that usessubmit()you get oneResultSetwith 4 items in it. You would get the same in Java. In the Gremlin Console however, it notices theResultSetis anIterableand shows you what's inside. It does the same for the secondsubmit()example, but in that case we usedfold()and thus created a result with only oneListso when the Console iterates theResultSetyou only get one result.
– stephen mallette
5 hours ago
|
show 1 more comment
up vote
1
down vote
up vote
1
down vote
Just use fold() as in - you can see my example here:
gremlin> cluster = Cluster.open()
==>localhost/127.0.0.1:8182
gremlin> client = cluster.connect()
==>org.apache.tinkerpop.gremlin.driver.Client$ClusteredClient@51efb731
gremlin> r = client.submit("g.V().hasLabel('person')").all().get()
==>result{object=v[1] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[2] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[4] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[6] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
gremlin> r = client.submit("g.V().hasLabel('person').fold()").all().get()
==>result{object=[v[1], v[2], v[4], v[6]] class=java.util.ArrayList}
Note that the downside to fold() in this example is that the result won't be streamed back to the client. You will build the entire list in memory on the server and then it will serialize that list as a single payload. If that list is sufficiently large and you generate enough of such lists you may hit memory/GC issues.
Just use fold() as in - you can see my example here:
gremlin> cluster = Cluster.open()
==>localhost/127.0.0.1:8182
gremlin> client = cluster.connect()
==>org.apache.tinkerpop.gremlin.driver.Client$ClusteredClient@51efb731
gremlin> r = client.submit("g.V().hasLabel('person')").all().get()
==>result{object=v[1] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[2] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[4] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[6] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
gremlin> r = client.submit("g.V().hasLabel('person').fold()").all().get()
==>result{object=[v[1], v[2], v[4], v[6]] class=java.util.ArrayList}
Note that the downside to fold() in this example is that the result won't be streamed back to the client. You will build the entire list in memory on the server and then it will serialize that list as a single payload. If that list is sufficiently large and you generate enough of such lists you may hit memory/GC issues.
answered yesterday
stephen mallette
24k32675
24k32675
-> What I expect to get is moe number of Results in the resultset instead of a whole big list of vertices in a single Map. So if it works like in your first query, it is great. But, the problem is, from a gremlin console I too get similar resp and not when I use a java client. probably due to groovy vs java thing.
– Sony Joseph
yesterday
I'm sorry, but i don't follow your comment. There should be no difference in this case with Groovy vs Java in this case - the behavior should be the same. If I've not answered your question I think you will need to clarify further.
– stephen mallette
yesterday
your understanding of my comment is correct. Ideally, with both groovy and Java the query resulstset must be of same kind. But unfortunately, I get them as different. I ran the query from both java and console to the same remote DB.
– Sony Joseph
12 hours ago
when I ran from groovy I got a resultset with multiple results but from Java I got one result with entire data in it.
– Sony Joseph
12 hours ago
client.submit()always returns oneResultSetobject - same for Groovy and Java. However,ResultSetis anIterable. So, in the first example above that usessubmit()you get oneResultSetwith 4 items in it. You would get the same in Java. In the Gremlin Console however, it notices theResultSetis anIterableand shows you what's inside. It does the same for the secondsubmit()example, but in that case we usedfold()and thus created a result with only oneListso when the Console iterates theResultSetyou only get one result.
– stephen mallette
5 hours ago
|
show 1 more comment
-> What I expect to get is moe number of Results in the resultset instead of a whole big list of vertices in a single Map. So if it works like in your first query, it is great. But, the problem is, from a gremlin console I too get similar resp and not when I use a java client. probably due to groovy vs java thing.
– Sony Joseph
yesterday
I'm sorry, but i don't follow your comment. There should be no difference in this case with Groovy vs Java in this case - the behavior should be the same. If I've not answered your question I think you will need to clarify further.
– stephen mallette
yesterday
your understanding of my comment is correct. Ideally, with both groovy and Java the query resulstset must be of same kind. But unfortunately, I get them as different. I ran the query from both java and console to the same remote DB.
– Sony Joseph
12 hours ago
when I ran from groovy I got a resultset with multiple results but from Java I got one result with entire data in it.
– Sony Joseph
12 hours ago
client.submit()always returns oneResultSetobject - same for Groovy and Java. However,ResultSetis anIterable. So, in the first example above that usessubmit()you get oneResultSetwith 4 items in it. You would get the same in Java. In the Gremlin Console however, it notices theResultSetis anIterableand shows you what's inside. It does the same for the secondsubmit()example, but in that case we usedfold()and thus created a result with only oneListso when the Console iterates theResultSetyou only get one result.
– stephen mallette
5 hours ago
-> What I expect to get is moe number of Results in the resultset instead of a whole big list of vertices in a single Map. So if it works like in your first query, it is great. But, the problem is, from a gremlin console I too get similar resp and not when I use a java client. probably due to groovy vs java thing.
– Sony Joseph
yesterday
-> What I expect to get is moe number of Results in the resultset instead of a whole big list of vertices in a single Map. So if it works like in your first query, it is great. But, the problem is, from a gremlin console I too get similar resp and not when I use a java client. probably due to groovy vs java thing.
– Sony Joseph
yesterday
I'm sorry, but i don't follow your comment. There should be no difference in this case with Groovy vs Java in this case - the behavior should be the same. If I've not answered your question I think you will need to clarify further.
– stephen mallette
yesterday
I'm sorry, but i don't follow your comment. There should be no difference in this case with Groovy vs Java in this case - the behavior should be the same. If I've not answered your question I think you will need to clarify further.
– stephen mallette
yesterday
your understanding of my comment is correct. Ideally, with both groovy and Java the query resulstset must be of same kind. But unfortunately, I get them as different. I ran the query from both java and console to the same remote DB.
– Sony Joseph
12 hours ago
your understanding of my comment is correct. Ideally, with both groovy and Java the query resulstset must be of same kind. But unfortunately, I get them as different. I ran the query from both java and console to the same remote DB.
– Sony Joseph
12 hours ago
when I ran from groovy I got a resultset with multiple results but from Java I got one result with entire data in it.
– Sony Joseph
12 hours ago
when I ran from groovy I got a resultset with multiple results but from Java I got one result with entire data in it.
– Sony Joseph
12 hours ago
client.submit() always returns one ResultSet object - same for Groovy and Java. However, ResultSet is an Iterable. So, in the first example above that uses submit() you get one ResultSet with 4 items in it. You would get the same in Java. In the Gremlin Console however, it notices the ResultSet is an Iterable and shows you what's inside. It does the same for the second submit() example, but in that case we used fold() and thus created a result with only one List so when the Console iterates the ResultSet you only get one result.– stephen mallette
5 hours ago
client.submit() always returns one ResultSet object - same for Groovy and Java. However, ResultSet is an Iterable. So, in the first example above that uses submit() you get one ResultSet with 4 items in it. You would get the same in Java. In the Gremlin Console however, it notices the ResultSet is an Iterable and shows you what's inside. It does the same for the second submit() example, but in that case we used fold() and thus created a result with only one List so when the Console iterates the ResultSet you only get one result.– stephen mallette
5 hours ago
|
show 1 more comment
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203394%2fgremlin-query-to-return-multiple-result-in-a-resultset%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password