Copilot commented on code in PR #7944:
URL: https://github.com/apache/ignite-3/pull/7944#discussion_r3045922279


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/externalize/RelJson.java:
##########
@@ -420,7 +420,19 @@ private Object toJson(RexNode node) {
                 RexLiteral literal = (RexLiteral) node;
                 Object value = literal.getValue3();
                 map = map();
-                map.put("literal", toJson(value));
+                // Convert the approximate numeric negative zero (-0.0) value 
to a string to preserve the minus sign,
+                // otherwise due to USE_BIG_DECIMAL_FOR_FLOATS jackson will 
create a BigDecimal from a double (-0.0)
+                // and this will result in the loss of the minus sign.
+                // Other special values +Infinity/-Infinity/NaN are serialized 
by jackson as strings.
+                // The value in RexLiteral for approximate types is always of 
type Double (see RexLiteral#valueMatchesType).
+                if (value instanceof Double
+                        && isApproximateNumeric(node.getType())
+                        && ((Double) value == -0.0d)) {
+                    map.put("literal", "-0.0");
+                } else {
+                    map.put("literal", toJson(value));
+                }

Review Comment:
   The negative-zero detection uses `((Double) value == -0.0d)`, but `-0.0d == 
0.0d` is `true`, so this branch will also match positive zero and serialize 
`0.0` as the string "-0.0". That would change semantics after deserialization 
now that comparisons distinguish +0.0 and -0.0. Use a sign-preserving check 
(e.g., `Double.doubleToRawLongBits((Double) value) == 
Double.doubleToRawLongBits(-0.0d)` or `Double.compare(...) == 0` plus raw-bits) 
so only negative zero is converted to the string form.



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

Reply via email to