This is an automated email from the ASF dual-hosted git repository.

jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 82cfbdd  Fix a formatting bug in AggregationFunctionUtils (#5148)
82cfbdd is described below

commit 82cfbdda87767587f80544ea4b01b65cae1b54e8
Author: Xiaotian (Jackie) Jiang <[email protected]>
AuthorDate: Fri Mar 13 18:13:40 2020 -0700

    Fix a formatting bug in AggregationFunctionUtils (#5148)
---
 .../function/AggregationFunctionUtils.java         | 11 ++--
 .../function/AggregationFunctionUtilsTest.java     | 66 ++++++++++++++++++++++
 2 files changed, 72 insertions(+), 5 deletions(-)

diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionUtils.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionUtils.java
index 00c534d..133867a 100644
--- 
a/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionUtils.java
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionUtils.java
@@ -111,12 +111,13 @@ public class AggregationFunctionUtils {
 
   public static String formatValue(Object value) {
     if (value instanceof Double) {
-      Double doubleValue = (Double) value;
+      double doubleValue = (double) value;
 
-      // String.format is very expensive, so avoid it for whole numbers that 
can fit in Long.
-      // We simply append ".00000" to long, in order to keep the existing 
behavior.
-      if (doubleValue <= Long.MAX_VALUE && 
DoubleMath.isMathematicalInteger(doubleValue)) {
-        return doubleValue.longValue() + ".00000";
+      // NOTE: String.format() is very expensive, so avoid it for whole 
numbers that can fit in Long.
+      //       We simply append ".00000" to long, in order to keep the 
existing behavior.
+      if (doubleValue <= Long.MAX_VALUE && doubleValue >= Long.MIN_VALUE && 
DoubleMath
+          .isMathematicalInteger(doubleValue)) {
+        return (long) doubleValue + ".00000";
       } else {
         return String.format(Locale.US, "%1.5f", doubleValue);
       }
diff --git 
a/pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionUtilsTest.java
 
b/pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionUtilsTest.java
new file mode 100644
index 0000000..ff74df9
--- /dev/null
+++ 
b/pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/AggregationFunctionUtilsTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.pinot.core.query.aggregation.function;
+
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+
+public class AggregationFunctionUtilsTest {
+
+  @Test
+  public void testFormatValue() {
+    double value = Long.MAX_VALUE;
+    assertEquals(AggregationFunctionUtils.formatValue(value), 
"9223372036854775807.00000");
+
+    value = Long.MIN_VALUE;
+    assertEquals(AggregationFunctionUtils.formatValue(value), 
"-9223372036854775808.00000");
+
+    value = 1e30;
+    assertEquals(AggregationFunctionUtils.formatValue(value), 
"1000000000000000000000000000000.00000");
+
+    value = -1e30;
+    assertEquals(AggregationFunctionUtils.formatValue(value), 
"-1000000000000000000000000000000.00000");
+
+    value = 1e-3;
+    assertEquals(AggregationFunctionUtils.formatValue(value), "0.00100");
+
+    value = -1e-3;
+    assertEquals(AggregationFunctionUtils.formatValue(value), "-0.00100");
+
+    value = 1e-10;
+    assertEquals(AggregationFunctionUtils.formatValue(value), "0.00000");
+
+    value = -1e-10;
+    assertEquals(AggregationFunctionUtils.formatValue(value), "-0.00000");
+
+    value = 123.456789;
+    assertEquals(AggregationFunctionUtils.formatValue(value), "123.45679");
+
+    value = Double.POSITIVE_INFINITY;
+    assertEquals(AggregationFunctionUtils.formatValue(value), "Infinity");
+
+    value = Double.NEGATIVE_INFINITY;
+    assertEquals(AggregationFunctionUtils.formatValue(value), "-Infinity");
+
+    value = Double.NaN;
+    assertEquals(AggregationFunctionUtils.formatValue(value), "NaN");
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to