suneet-s commented on code in PR #12493:
URL: https://github.com/apache/druid/pull/12493#discussion_r868099233
##########
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:
if `objectsWhichMightBeStrings[index]` is null, then the
`objectNeedsFoldCheck(...)` call returns false. even though the array might
contain `SerializablePairLongString` objects.
Can we make it so that `objectNeedsFoldCheck` accepts a NonNull object or
have it return true if the object is null. If the object is null, I don't think
we need to do anything in this function, so I think only checking `foldNeeded`
if the object is non null will be more efficient.
##########
processing/src/main/java/org/apache/druid/query/aggregation/last/StringLastVectorAggregator.java:
##########
@@ -123,13 +123,14 @@ public void aggregate(
{
long[] timeVector = timeSelector.getLongVector();
Object[] objectsWhichMightBeStrings = valueSelector.getObjectVector();
+ // one time check on first element to judge if elements are serializable
pairs or not
+ final int startRow = rows == null ? 0 : rows[0];
+ final boolean foldNeeded =
StringFirstLastUtils.objectNeedsFoldCheck(objectsWhichMightBeStrings[startRow]);
Review Comment:
Similar comment to line 77
##########
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;
}
Review Comment:
```suggestion
if (times[i] < lastTime) {
break;
}
if (objectsWhichMightBeStrings[i] == null) {
continue;
}
```
--
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]