Skip to content

Commit

Permalink
Review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
timoninmaxim committed Dec 28, 2024
1 parent 329f8f7 commit 1aefdd9
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.util.ImmutableBitSet;
Expand Down Expand Up @@ -247,6 +248,9 @@ private class Grouping {
/** */
private GroupKey.Builder grpKeyBld;

/** */
private final BiFunction<GroupKey, List<AccumulatorWrapper<Row>>, List<AccumulatorWrapper<Row>>> getOrCreateGroup;

/** */
private Grouping(byte grpId, ImmutableBitSet grpFields) {
this.grpId = grpId;
Expand All @@ -255,6 +259,19 @@ private Grouping(byte grpId, ImmutableBitSet grpFields) {
grpKeyBld = GroupKey.builder(grpFields.cardinality());
handler = context().rowHandler();

getOrCreateGroup = (k, v) -> {
if (v == null) {
grpKeyBld = GroupKey.builder(grpFields.cardinality());

return create();
}
else {
grpKeyBld.clear();

return v;
}
};

init();
}

Expand Down Expand Up @@ -300,20 +317,7 @@ private void addOnMapper(Row row) {
for (Integer field : grpFields)
grpKeyBld.add(handler.get(field, row));

GroupKey grpKey = grpKeyBld.build();

List<AccumulatorWrapper<Row>> wrappers = groups.compute(grpKey, (k, v) -> {
if (v == null) {
grpKeyBld = GroupKey.builder(grpFields.cardinality());

return create();
}
else {
grpKeyBld.clear();

return v;
}
});
List<AccumulatorWrapper<Row>> wrappers = groups.compute(grpKeyBld.build(), getOrCreateGroup);

for (AccumulatorWrapper<Row> wrapper : wrappers)
wrapper.add(row);
Expand Down

0 comments on commit 1aefdd9

Please sign in to comment.