nonbinaryprogrammer commented on a change in pull request #6861:
URL: https://github.com/apache/geode/pull/6861#discussion_r715231251
##########
File path:
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSortedSet.java
##########
@@ -288,6 +289,54 @@ long zcount(SortedSetScoreRangeOptions rangeOptions) {
return byteIncr;
}
+ long zinterstore(RegionProvider regionProvider, RedisKey key,
List<ZKeyWeight> keyWeights,
+ ZAggregator aggregator) {
+ List<RedisSortedSet> sets = new ArrayList<>(keyWeights.size());
+ for (ZKeyWeight keyWeight : keyWeights) {
+ RedisSortedSet set =
+ regionProvider.getTypedRedisData(REDIS_SORTED_SET,
keyWeight.getKey(), false);
+
+ if (set == NULL_REDIS_SORTED_SET) {
+ continue;
+ }
+
+ double weight = keyWeight.getWeight();
+ RedisSortedSet weightedSet = new RedisSortedSet(Collections.emptyList());
+
+ for (AbstractOrderedSetEntry entry : set.members.values()) {
+ OrderedSetEntry existingValue = members.get(entry.member);
+ if (existingValue == null) {
+ double score;
+ // Redis math and Java math are different when handling infinity.
Specifically:
+ // Java: INFINITY * 0 = NaN
+ // Redis: INFINITY * 0 = 0
+ if (weight == 0) {
+ score = 0;
+ } else if (weight == 1) {
+ score = entry.getScore();
+ } else if (Double.isInfinite(weight) && entry.score == 0D) {
+ score = 0D;
+ } else {
+ double newScore = entry.score * weight;
+ if (Double.isNaN(newScore)) {
+ throw new ArithmeticException(ERROR_OPERATION_PRODUCED_NAN);
Review comment:
I can handle this case specifically, but I don't like it. with the
special case of `-infinity + infinity = 0`, this sequence of events `-infinity
+ infinity + 3` is not equal to `-infinity + 3 + infinity`, which means that
the result of our sum will be dependent on the ordering of the sorted sets
we're looking through. But that's a problem that native redis has, so we must
as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]