Skip to content

Commit ebc8fad

Browse files
committed
optimizes SpillingGrouper
1 parent cbe3629 commit ebc8fad

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/SpillingGrouper.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,20 @@ private Iterator<Entry<KeyType>> combineByKey(
485485
{
486486
return new AbstractIterator<>()
487487
{
488-
private Entry<KeyType> current = sortedIterator.hasNext() ? sortedIterator.next() : null;
488+
private final ReusableEntry<KeyType> current = ReusableEntry.create(keySerde, aggregatorFactories.length);
489+
private boolean hasCurrent = false;
490+
491+
{
492+
if (sortedIterator.hasNext()) {
493+
copyEntry(sortedIterator.next(), current);
494+
hasCurrent = true;
495+
}
496+
}
489497

490498
@Override
491499
protected Entry<KeyType> computeNext()
492500
{
493-
if (current == null) {
501+
if (!hasCurrent) {
494502
return endOfData();
495503
}
496504

@@ -501,18 +509,24 @@ protected Entry<KeyType> computeNext()
501509

502510
while (sortedIterator.hasNext()) {
503511
final Entry<KeyType> next = sortedIterator.next();
504-
if (comparator.compare(current, next) != 0) {
505-
current = next;
512+
if (comparator.compare(combined, next) != 0) {
513+
copyEntry(next, current);
506514
return combined;
507515
}
508516
for (int i = 0; i < combinedValues.length; i++) {
509517
combinedValues[i] = aggregatorFactories[i].combine(combinedValues[i], next.getValues()[i]);
510518
}
511519
}
512520

513-
current = null;
521+
hasCurrent = false;
514522
return combined;
515523
}
524+
525+
private void copyEntry(Entry<KeyType> from, ReusableEntry<KeyType> to)
526+
{
527+
to.setKey(from.getKey());
528+
System.arraycopy(from.getValues(), 0, to.getValues(), 0, aggregatorFactories.length);
529+
}
516530
};
517531
}
518532

0 commit comments

Comments
 (0)