[ 
https://issues.apache.org/jira/browse/GEODE-8624?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17278111#comment-17278111
 ] 

ASF GitHub Bot commented on GEODE-8624:
---------------------------------------

jdeppe-pivotal commented on a change in pull request #5986:
URL: https://github.com/apache/geode/pull/5986#discussion_r569546128



##########
File path: 
geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/hash/AbstractHincrByFloatIntegrationTest.java
##########
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+
+package org.apache.geode.redis.internal.executor.hash;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.offset;
+
+import java.math.BigDecimal;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.exceptions.JedisDataException;
+
+import org.apache.geode.redis.ConcurrentLoopingThreads;
+import org.apache.geode.test.dunit.rules.RedisPortSupplier;
+
+public abstract class AbstractHincrByFloatIntegrationTest implements 
RedisPortSupplier {
+
+  private Jedis jedis;
+  private Jedis jedis2;
+  private static int ITERATION_COUNT = 4000;
+
+  @Before
+  public void setUp() {
+    jedis = new Jedis("localhost", getPort(), 10000000);
+    jedis2 = new Jedis("localhost", getPort(), 10000000);
+  }
+
+  @After
+  public void flushAll() {
+    jedis.flushAll();
+  }
+
+  @After
+  public void tearDown() {
+    jedis.close();
+    jedis2.close();
+  }
+
+  @Test
+  public void givenKeyNotProvided_returnsWrongNumberOfArgumentsError() {
+    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT))
+        .hasMessageContaining("ERR wrong number of arguments for 
'hincrbyfloat' command");
+  }
+
+  @Test
+  public void givenHashNotProvided_returnsWrongNumberOfArgumentsError() {
+    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, 
"key"))
+        .hasMessageContaining("ERR wrong number of arguments for 
'hincrbyfloat' command");
+  }
+
+  @Test
+  public void givenIncrementNotProvided_returnsWrongNumberOfArgumentsError() {
+    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, 
"key", "hash"))
+        .hasMessageContaining("ERR wrong number of arguments for 
'hincrbyfloat' command");
+  }
+
+  @Test
+  public void 
givenMoreThanFourArgumentsProvided_returnsWrongNumberOfArgumentsError() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", "hash", 
"5", "extraArg"))
+            .hasMessageContaining("ERR wrong number of arguments for 
'hincrbyfloat' command");
+  }
+
+  @Test
+  public void testHincrByFloat_withInfinityAndVariants() {
+    jedis.hset("key", "number", "1.4");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", 
"number", "+inf"))
+            .hasMessage("ERR increment would produce NaN or Infinity");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", 
"number", "-inf"))
+            .hasMessage("ERR increment would produce NaN or Infinity");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", 
"number", "inf"))
+            .hasMessage("ERR increment would produce NaN or Infinity");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", 
"number", "+infinity"))
+            .hasMessage("ERR increment would produce NaN or Infinity");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", 
"number", "-infinity"))
+            .hasMessage("ERR increment would produce NaN or Infinity");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", 
"number", "infinity"))
+            .hasMessage("ERR increment would produce NaN or Infinity");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", 
"number", "nan"))
+            .hasMessage("ERR value is not a valid float");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", 
"number", "infant"))
+            .hasMessage("ERR value is not a valid float");
+  }
+
+  @Test
+  public void testHincrByFloat() {
+    double incr = 0.37373;
+    String key = "key";
+    String field = "field";
+    jedis.hset(key, field, "1.0");
+
+    double response = jedis.hincrByFloat(key, field, incr);
+    assertThat(response).isEqualTo(incr + 1, offset(.00001));

Review comment:
       Redis' floating point precision is not precise.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Improve INCRBYFLOAT accuracy for very large values
> --------------------------------------------------
>
>                 Key: GEODE-8624
>                 URL: https://issues.apache.org/jira/browse/GEODE-8624
>             Project: Geode
>          Issue Type: Improvement
>          Components: redis
>            Reporter: Jens Deppe
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.14.0
>
>
> Currently native redis appears to be able to apply {{INCRBYFLOAT}} on values 
> that are below the max of unsigned long long (18446744073709551615). However, 
> since we're treating numbers as {{double}}s we can lose precision for very 
> large values. For example:
> {noformat}
> set val 18446744073709551614
> incrbyfloat val 1{noformat}
> incorrectly returns {{18446744073709552000}}
> Native redis produces a correct result.
> We should consider switching to using {{BigInteger}} for all commands which 
> perform calculations: {{INCR, INCR, INCRBYFLOAT, HINCRBY, HINCRBYFLOAT}}.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to