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.










share|improve this question


























    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.










    share|improve this question
























      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.










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      Sony Joseph

      96




      96
























          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.






          share|improve this answer





















          • -> 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 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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
































          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.






          share|improve this answer





















          • -> 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 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















          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.






          share|improve this answer





















          • -> 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 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













          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 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


















          • -> 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 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
















          -> 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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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




















































































          Popular posts from this blog

          Landwehr

          Reims

          Schenkenzell