Copilot commented on code in PR #17186:
URL: https://github.com/apache/pinot/pull/17186#discussion_r2513653611


##########
pinot-segment-local/src/test/java/org/apache/pinot/segment/local/segment/creator/impl/stats/NoDictColumnStatisticsCollectorTest.java:
##########
@@ -781,9 +781,12 @@ private void 
compareCollectorStats(NoDictColumnStatisticsCollector noDictCollect
     String context = String.format("Iteration %d, DataType: %s, SingleValue: 
%s, Data: %s",
         iteration, dataType, isSingleValue, Arrays.deepToString(testData));
 
-    assertTrue(noDictCollector.getCardinality() >= 
expectedCollector.getCardinality(),
-        "Approx Cardinality " + noDictCollector.getCardinality() + " is lower 
than actual cardinality "
-            + expectedCollector.getCardinality() + " for " + context);
+    int approx = noDictCollector.getCardinality();
+    int exact = expectedCollector.getCardinality();
+    int tolerance = Math.max(1, (int) Math.ceil(0.1 * exact)); // allow 10% or 
at least 1

Review Comment:
   The tolerance calculation could overflow when `exact` is very large. For 
example, if `exact` is close to `Integer.MAX_VALUE`, multiplying by 0.1 and 
casting could produce unexpected results. Consider using `(int) 
Math.min(Integer.MAX_VALUE, Math.ceil(0.1 * exact))` or handling the 
calculation in long arithmetic before casting.
   ```suggestion
       int tolerance = Math.max(1, (int) Math.min(Integer.MAX_VALUE, 
Math.ceil(0.1 * exact))); // allow 10% or at least 1, prevent overflow
   ```



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

Reply via email to