Copilot commented on code in PR #17677:
URL: https://github.com/apache/pinot/pull/17677#discussion_r2796651987
##########
pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/TruncateDecimalTransformFunctionTest.java:
##########
@@ -62,12 +63,46 @@ public void testTruncateDecimalTransformFunction() {
expectedValues[i] = truncate(_doubleSVValues[i], 0);
}
testTransformFunction(transformFunction, expectedValues);
+
+ // Regression for signed-zero handling: truncate(value) should match
truncate(value, 0).
+ expression = RequestContextUtils.getExpression("truncate(-0.4)");
+ transformFunction = TransformFunctionFactory.get(expression,
_dataSourceMap);
+ Assert.assertTrue(transformFunction instanceof
TruncateDecimalTransformFunction);
+ Arrays.fill(expectedValues, 0.0d);
+ testTransformFunction(transformFunction, expectedValues);
+
+ long positiveZeroBits = Double.doubleToRawLongBits(0.0d);
+ double[] actualValues =
transformFunction.transformToDoubleValuesSV(_projectionBlock);
+ for (double actualValue : actualValues) {
+ Assert.assertEquals(Double.doubleToRawLongBits(actualValue),
positiveZeroBits);
+ }
+ }
+
+ @Test
+ public void testTruncateNaNAndInfinity() {
+ testTruncateLiteralNoScale(
+ String.format("truncate((%s - %s) / (%s - %s))", INT_SV_COLUMN,
INT_SV_COLUMN, INT_SV_COLUMN, INT_SV_COLUMN),
Review Comment:
The NaN test expression uses only integer operands (`INT_SV_COLUMN`), which
may result in integer division semantics and/or a divide-by-zero error rather
than producing `Double.NaN`. To reliably generate NaN in the expression engine,
force floating-point division (e.g., introduce a `1.0` multiplier/cast in the
numerator/denominator) so the evaluated value is guaranteed to be `NaN` instead
of an exception or truncated integer behavior.
```suggestion
String.format("truncate((1.0 * (%s - %s)) / (1.0 * (%s - %s)))",
INT_SV_COLUMN, INT_SV_COLUMN,
INT_SV_COLUMN, INT_SV_COLUMN),
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]