Copilot commented on code in PR #7948:
URL: https://github.com/apache/ignite-3/pull/7948#discussion_r3046090653
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/exp/IgniteExpressions.java:
##########
@@ -182,4 +201,25 @@ private static Type larger(Type type0, Type type1) {
return Double.TYPE;
}
}
+
+ /**
+ * Generates a comparison expression for floating-point types using {@link
Float#compare(float, float)}
+ * or {@link Double#compare(double, double)} instead of primitive
comparison operators.
+ */
+ private static @Nullable Expression compareFloatingPoint(ExpressionType
binaryType, Expression left, Expression right) {
+ Type leftType = left.getType();
+ Type rightType = right.getType();
+
+ boolean isFloat = leftType == Float.TYPE || rightType == Float.TYPE;
+ boolean isDouble = leftType == Double.TYPE || rightType == Double.TYPE;
+
+ if (!isFloat && !isDouble) {
+ return null;
+ }
+
+ Class<?> targetClass = isDouble ? Double.class : Float.class;
+ Expression cmp = Expressions.call(targetClass, "compare", left, right);
+
Review Comment:
compareFloatingPoint() only detects primitive float/double types
(Float.TYPE/Double.TYPE). If both operands are boxed (Float.class/Double.class)
— which is the typical representation for nullable FLOAT/DOUBLE columns — this
method returns null and the code falls back to primitive operators after
unboxing, reintroducing the old semantics for NaN and -0.0. Consider detecting
boxed types too (e.g., via Primitive.ofBoxOr) and unboxing/casting both
operands to the chosen primitive (float or double) before calling
Float/Double.compare, so comparisons are consistent regardless of
nullability/coercion.
```suggestion
Primitive leftPrimitive = Primitive.ofBoxOr(left.getType());
Primitive rightPrimitive = Primitive.ofBoxOr(right.getType());
boolean isFloat = leftPrimitive == Primitive.FLOAT || rightPrimitive
== Primitive.FLOAT;
boolean isDouble = leftPrimitive == Primitive.DOUBLE ||
rightPrimitive == Primitive.DOUBLE;
if (!isFloat && !isDouble) {
return null;
}
Primitive targetPrimitive = isDouble ? Primitive.DOUBLE :
Primitive.FLOAT;
Class<?> targetClass = isDouble ? Double.class : Float.class;
Expression leftArg = Expressions.convert_(left,
targetPrimitive.primitiveClass);
Expression rightArg = Expressions.convert_(right,
targetPrimitive.primitiveClass);
Expression cmp = Expressions.call(targetClass, "compare", leftArg,
rightArg);
```
--
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]