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


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/creator/impl/stats/NoDictColumnStatisticsCollector.java:
##########
@@ -208,8 +222,12 @@ public int getMaxRowLengthInBytes() {
 
   @Override
   public int getCardinality() {
-    // Get approximate distinct count estimate using HLL++
-    // Increase by 10% to increase probability of not returning lower than 
actual cardinality
+    // If we are still tracking exact uniques, return exact cardinality
+    Set<Object> exact = _exactUniquesRef.get(); // local snapshot to avoid 
races
+    if (exact != null) {
+      return exact.size();

Review Comment:
   The exact set can become null between the `get()` and `size()` calls due to 
concurrent modification in `trackExactUnique()`. Although unlikely in practice 
due to the timing window, this could result in a `NullPointerException`. 
Consider using a local variable pattern with a null check after reading the set 
reference.
   ```suggestion
         // Defensive: exact can become null between get() and size() due to 
concurrent modification
         return exact != null ? exact.size() : (int) 
Math.round(_hllPlus.cardinality() * 1.1);
   ```



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