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