Combining results of two subqueries

130 visninger
Gå til det første ulæste opslag

Rob Simpson

ulæst,
17. jan. 2018, 12.43.4517.01.2018
til Gremlin-users

I don't have access to math() (Tinkerpop 3.4), but am trying to do a computation on two independent queries.

I can do:

g.V().has('name','marko').sack(assign).by('age').sack(sum).by(constant(10)).sack()

to get Marko's age plus 10,

and 

g.V().has('name','marko').sack(assign).by('age').sack(minus).by(constant(10)).sack()

to get Marko's age minus 10.

How can I embed both calculations in a query so that I can, for instance, take the ratio of them?   In my use case two different fields are used, not 'age' twice.

Thanks in anticipation,  

Rob

Stephen Mallette

ulæst,
17. jan. 2018, 12.47.1517.01.2018
til Gremlin-users
Can you just union() them?

gremlin> g.V().has('name','marko').union(sack(assign).by('age').sack(minus).by(constant(10)).sack(),sack(assign).by('age').sack(sum).by(constant(10)).sack())
==>19
==>39


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/84b66b34-8c8f-441d-808f-e72543f8abf6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rob Simpson

ulæst,
17. jan. 2018, 12.52.3517.01.2018
til gremli...@googlegroups.com
I want to do a further operation on them, and for many verticies also.

You received this message because you are subscribed to a topic in the Google Groups "Gremlin-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gremlin-users/wxtQd6e_VWQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CAA-H43_T32ZMh7aiU3H2Gsvfnqx6op5jdyeQ4pPFqgPBi2hL4w%40mail.gmail.com.

Rob Simpson

ulæst,
17. jan. 2018, 15.23.5517.01.2018
til Gremlin-users


To clarify, I tried using a sideEffect in this manner:

g.V().has(label,'person').sideEffect(<do calc and store in 'a'.>).sideEffect(<do calc and store in 'b'.>).<do something with a and b>...

but I cannot access the results of my sideEffect outside of it:  i.e. 

g.V().has(label,'person').sideEffect(sack(assign).by('age').sack(sum).by(constant(10)).sack().as('a')).project().by('a')

does not pass out the 'age+10' calculations as I expected.

Hope this makes it clearer. 

Stephen Mallette

ulæst,
17. jan. 2018, 16.30.2417.01.2018
til Gremlin-users
I'm still not sure I follow - perhaps I'm too focused on your use of sack() and your use of sideEffect() step with sack(). Perhaps you're just trying to form an example and I'm taking it too literally. Also, note that project().by('a') is incorrect syntax and won't run. And going back to your first post, math() step is available on 3.3.1 which is currently released (not 3.4.x which we've not started developing). 

Anyway, not sure if this helps, but is this getting closer to what you're trying to do? you mentioned calculating a ratio which i just did with a bit of union() and some added sack() usage:

gremlin> g.V().
......1>   has(label,'person').
......2>   local(union(sack(assign).by('age').sack(sum).by(constant(10d)).sack(),
......3>               sack(assign).by('age').sack(minus).by(constant(10d)).sack()).
......4>         fold().
......5>         sack(assign).by(tail(local,1)).sack(div).by(limit(local,1)).sack())
==>0.48717948717948717
==>0.4594594594594595
==>0.5238095238095238
==>0.5555555555555556




--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.

Rob Simpson

ulæst,
18. jan. 2018, 10.58.4618.01.2018
til Gremlin-users

There was a typo in the original post - we are on 3.2 so no maths. 

Yes, I can probably adapt this for my needs, many thanks.

I think the whole side effect thing was because I was doing multiple independent calcs, and wanting to combine downstream, but can't find a way to store the intermediate results.

I will play with your construct and report back - thanks again, much appreciated!

 
Svar alle
Svar til forfatter
Videresend
0 nye opslag