You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/07/14 22:28:39 UTC

[GitHub] [pinot] Jackie-Jiang commented on a diff in pull request #9059: Fix string length in MutableColumnStatistics

Jackie-Jiang commented on code in PR #9059:
URL: https://github.com/apache/pinot/pull/9059#discussion_r921625117


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/realtime/converter/stats/MutableColumnStatistics.java:
##########
@@ -70,46 +76,57 @@ public int getCardinality() {
 
   @Override
   public int getLengthOfShortestElement() {
-    // Length of longest string
-    int minStringLength = Integer.MAX_VALUE;
-
-    // If this column is a string/bytes column, iterate over the dictionary to find the maximum length
-    FieldSpec.DataType dataType = _dataSource.getDataSourceMetadata().getDataType();
-    int length = _dictionary.length();
-
-    if (dataType.equals(FieldSpec.DataType.STRING)) {
-      for (int i = 0; i < length; i++) {
-        minStringLength = Math.min(_dictionary.getStringValue(i).length(), minStringLength);
-      }
-    } else if (dataType.equals(FieldSpec.DataType.BYTES)) {
-      for (int i = 0; i < length; i++) {
-        minStringLength = Math.min(_dictionary.getBytesValue(i).length, minStringLength);
-      }
-    }
-
-    return minStringLength;
+    collectElementLengthIfNeeded();
+    return _minElementLength;
   }
 
   @Override
   public int getLengthOfLargestElement() {
-    // Length of longest string
-    int maximumStringLength = 0;
+    collectElementLengthIfNeeded();
+    return _maxElementLength;
+  }
 
-    // If this column is a string/bytes column, iterate over the dictionary to find the maximum length
-    FieldSpec.DataType dataType = _dataSource.getDataSourceMetadata().getDataType();
-    int length = _dictionary.length();
+  private void collectElementLengthIfNeeded() {
+    if (_minElementLength >= 0) {

Review Comment:
   Yes. Currently we scan the dictionary multiple times because we call `getLengthOfShortestElement()` and `getLengthOfLargestElement()` multiple times. This avoids that.



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org