Skip to content

Commit

Permalink
[core] Improve performance of dinstinct collect agg. (#3772)
Browse files Browse the repository at this point in the history
  • Loading branch information
leaves12138 authored Jul 18, 2024
1 parent f457d35 commit 6da33cb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private void updateWithSequenceGroup(KeyValue kv) {
row.setField(
i, aggregator == null ? field : aggregator.agg(accumulator, field));
} else if (aggregator != null) {
row.setField(i, aggregator.agg(field, accumulator));
row.setField(i, aggregator.aggReversed(accumulator, field));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ private static FieldAggregator createFieldNestedUpdateAgg(

public abstract Object agg(Object accumulator, Object inputField);

public Object aggReversed(Object accumulator, Object inputField) {
return agg(inputField, accumulator);
}

/** reset the aggregator to a clean start state. */
public void reset() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ String name() {
return NAME;
}

@Override
public Object aggReversed(Object accumulator, Object inputField) {
// we don't need to actually do the reverse here for this agg
// because accumulator has been distinct, just let accumulator be accumulator will speed up
// dinstinct process
return agg(accumulator, inputField);
}

@Override
public Object agg(Object accumulator, Object inputField) {
if (accumulator == null && inputField == null) {
Expand All @@ -99,7 +107,9 @@ public Object agg(Object accumulator, Object inputField) {

if (equaliser != null) {
List<Object> collection = new ArrayList<>();
collectWithEqualiser(collection, accumulator);
// do not need to distinct accumulator, because the accumulator is always distinct, no
// need to distinct it every time
collect(collection, accumulator);
collectWithEqualiser(collection, inputField);
return new GenericArray(collection.toArray());
} else {
Expand Down

0 comments on commit 6da33cb

Please sign in to comment.