This is an automated email from the ASF dual-hosted git repository.
xiangfu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new dea0cd3c04 [multistage] fix the logic of parsing float literal (#11466)
dea0cd3c04 is described below
commit dea0cd3c04d6a4a5a615c89b1fb9b293df51a0a9
Author: Haitao Zhang <[email protected]>
AuthorDate: Thu Aug 31 04:02:06 2023 -0700
[multistage] fix the logic of parsing float literal (#11466)
* fix the logic of passing float literal
* address comments
---
.../pinot/common/utils/request/RequestUtils.java | 11 ++++++--
.../common/utils/request/RequestUtilsTest.java | 33 ++++++++++++++++++++++
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git
a/pinot-common/src/main/java/org/apache/pinot/common/utils/request/RequestUtils.java
b/pinot-common/src/main/java/org/apache/pinot/common/utils/request/RequestUtils.java
index 6ac7845c9d..c2edab51ec 100644
---
a/pinot-common/src/main/java/org/apache/pinot/common/utils/request/RequestUtils.java
+++
b/pinot-common/src/main/java/org/apache/pinot/common/utils/request/RequestUtils.java
@@ -191,8 +191,15 @@ public class RequestUtils {
if (object instanceof Integer || object instanceof Long) {
return RequestUtils.getLiteralExpression(((Number) object).longValue());
}
- if (object instanceof Float || object instanceof Double) {
- return RequestUtils.getLiteralExpression(((Number)
object).doubleValue());
+ if (object instanceof Float) {
+ // We need to use Double.parseDouble(object.toString()) instead of
((Number) object).doubleValue()
+ // or ((Float) object).doubleValue() because the latter two will return
slightly different values
+ // For example, if object is 0.06f,
Double.parseDouble(object.toString()) will return 0.06, while
+ // ((Number) object).doubleValue() or ((Float) object).doubleValue()
will return 0.05999999865889549
+ return
RequestUtils.getLiteralExpression(Double.parseDouble(object.toString()));
+ }
+ if (object instanceof Double) {
+ return RequestUtils.getLiteralExpression(((Double)
object).doubleValue());
}
if (object instanceof byte[]) {
return RequestUtils.getLiteralExpression((byte[]) object);
diff --git
a/pinot-common/src/test/java/org/apache/pinot/common/utils/request/RequestUtilsTest.java
b/pinot-common/src/test/java/org/apache/pinot/common/utils/request/RequestUtilsTest.java
new file mode 100644
index 0000000000..edd2822751
--- /dev/null
+++
b/pinot-common/src/test/java/org/apache/pinot/common/utils/request/RequestUtilsTest.java
@@ -0,0 +1,33 @@
+/**
+ * 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.common.utils.request;
+
+import org.apache.pinot.common.request.Expression;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class RequestUtilsTest {
+ // please check comments inside RequestUtils.getLiteralExpression() for why
we need this test
+ @Test
+ public void testGetLiteralExpressionForObject() {
+ Expression literalExpression =
RequestUtils.getLiteralExpression(Float.valueOf(0.06f));
+ Assert.assertEquals((literalExpression.getLiteral().getDoubleValue()),
0.06);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]