somu-imply commented on code in PR #12493:
URL: https://github.com/apache/druid/pull/12493#discussion_r868283733


##########
processing/src/main/java/org/apache/druid/query/aggregation/last/StringLastVectorAggregator.java:
##########
@@ -69,47 +68,48 @@ public void aggregate(ByteBuffer buf, int position, int 
startRow, int endRow)
     Object[] objectsWhichMightBeStrings = valueSelector.getObjectVector();
 
     lastTime = buf.getLong(position);
-    int index = endRow - 1;
+    int index;
     for (int i = endRow - 1; i >= startRow; i--) {
-      if (objectsWhichMightBeStrings[i] != null) {
-        index = i;
+      if (times[i] < lastTime && objectsWhichMightBeStrings[i] != null) {
         break;
       }
-    }
-    final boolean foldNeeded = 
StringFirstLastUtils.objectNeedsFoldCheck(objectsWhichMightBeStrings[index]);
-    if (foldNeeded) {
-      // Less efficient code path when folding is a possibility (we must read 
the value selector first just in case
-      // it's a foldable object).
-      final SerializablePairLongString inPair = 
StringFirstLastUtils.readPairFromVectorSelectorsAtIndex(
-          timeSelector,
-          valueSelector,
-          index
-      );
-      if (inPair != null) {
-        final long lastTime = buf.getLong(position);
-        if (inPair.lhs >= lastTime) {
+      index = i;
+      final boolean foldNeeded = 
StringFirstLastUtils.objectNeedsFoldCheck(objectsWhichMightBeStrings[index]);

Review Comment:
   After the change, we are not hitting this function unless 
`objectsWhichMightBeStrings[index]` is non null. We are setting up a loop to 
continue if there is a null object. This guarantees that the function 
`objectNeedsFoldCheck` always accepts a non null object. 



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