I'm using sorted sets for some live stats counters, and it would be useful to merge 2 sorted sets together, multiplying or dividing the scores by one of them. This would also require another option like WEIGHTS, but called EXPONENTS instead, to allow -1 for a divide.
I've looked at the ZUNIONSTORE code and am willing to try this myself, but I wanted some feedback about the merge chances before I started this. If the consensus is going to be "wait for scripting", I'll probably just do that.
Comment From: dunedain289
I hate to write a bump comment, but I'd really like some feedback about this patch. Any chance of a merge or should this be done with scripting?
Comment From: antirez
Hello, it is very unlikely that this will get implemented since with 2.6 we have scripting and either it is possible to implement the command with scripting, or pass a script to the AGGREGATE option, like AGGREGATE SCRIPT "return a*b" or alike that will call lua populating "a" and "b" with the two scores and will use the result of the script as result.
Comment From: dunedain289
Re-implementing the entire ZUNIONSTORE or ZINTERSTORE commands in Lua just to change the aggregation function seems very painful, which is part of why I wrote the patch above. However, being able to provide the aggregation function in Lua would work extremely well.
Comment From: adkatrit
antirez, Can you provide an example of this AGGREGATE SCRIPT "return a*b" syntax or is this not implemented yet?
Thank You
Comment From: electric-al
Hi there. Any news on this?
In my opinion a multiplicative AGGREGATE is a common use case (inner product calculation) so it would be really really useful to add without the use of scripts (which would be slower I assume).
Comment From: Prinzhorn
Hi,
I'm very interested in this feature as well. Any news? How would I do this with scripting (of course I don't want to implemented the logic completely in Lua, just the aggregate part)?
Comment From: treystout
So I've stumbled into a similar situation as the author of this issue. I'd really love to be able to do a zunionstore where the aggregation method is multiplying component scores together. The original patch is a bit old, but would still be trivial to add.
The author of the patch was told to wait for a scripting aggregation method, but I don't see that added yet either. Is this a case of perfect being the enemy of good? I'd rather have the C implemented multiplication method now, than a scripting aggregation method in the future.
If the patch were updated to add multiplication as an alternate method, what are the odds it would be pulled?
Comment From: Prinzhorn
Workaround for some use cases: store ln(score) (calculate on client or lua) and use SUM. Then do e^sum on the result.
Comment From: treystout
@Prinzhorn Let me know where I can send you some cash. I had no idea that that law existed. Thank you!
for other math noobs like me:
Comment From: Prinzhorn
@treystout You're welcome
Comment From: MoritzGoeckel
I really what that feature too. Is there any chances, that it will be implemented soon?