Skip to content

Commit 7861549

Browse files
gord02vbarua
authored andcommitted
fix: adding support for both deprecated and new proto of Groupings for the AggregateRel
1 parent b793c85 commit 7861549

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

core/src/main/java/io/substrait/relation/ProtoRelConverter.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -628,38 +628,38 @@ protected Aggregate newAggregate(AggregateRel rel) {
628628

629629
List<Aggregate.Grouping> groupings = new ArrayList<>(rel.getGroupingsCount());
630630

631-
// the deprecated form of Grouping is not used
632-
if (!rel.getGroupingExpressionsList().isEmpty()) {
633-
List<io.substrait.proto.Expression> allGroupingKeys = rel.getGroupingExpressionsList();
634-
635-
// for every grouping object on aggregate, it has a list of references into the aggregate's expressionList for the specific sorting set
636-
for (AggregateRel.Grouping grouping : rel.getGroupingsList()) {
637-
List<io.substrait.proto.Expression> groupingKeys = new ArrayList<>();
638-
for (int key: grouping.getExpressionReferencesList()) {
639-
groupingKeys.add(allGroupingKeys.get(key));
640-
}
641-
groupings.add(
642-
Aggregate.Grouping.builder()
643-
.expressions(
644-
groupingKeys.stream()
645-
.map(protoExprConverter::from)
646-
.collect(Collectors.toList()))
647-
.build());
648-
}
649-
Aggregate.builder().input(input).groupings(groupings);
650-
}else{
651-
// using the deprecated form of Grouping and Aggregate
652-
for (AggregateRel.Grouping grouping : rel.getGroupingsList()) {
653-
groupings.add(
654-
Aggregate.Grouping.builder()
655-
.expressions(
656-
grouping.getGroupingExpressionsList().stream()
657-
.map(protoExprConverter::from)
658-
.collect(Collectors.toList()))
659-
.build());
660-
}
631+
// the deprecated form of Grouping is not used
632+
if (!rel.getGroupingExpressionsList().isEmpty()) {
633+
List<io.substrait.proto.Expression> allGroupingKeys = rel.getGroupingExpressionsList();
634+
635+
// for every grouping object on aggregate, it has a list of references into the
636+
// aggregate's expressionList for the specific sorting set
637+
for (AggregateRel.Grouping grouping : rel.getGroupingsList()) {
638+
List<io.substrait.proto.Expression> groupingKeys = new ArrayList<>();
639+
for (int key : grouping.getExpressionReferencesList()) {
640+
groupingKeys.add(allGroupingKeys.get(key));
641+
}
642+
groupings.add(
643+
Aggregate.Grouping.builder()
644+
.expressions(
645+
groupingKeys.stream()
646+
.map(protoExprConverter::from)
647+
.collect(Collectors.toList()))
648+
.build());
661649
}
662-
650+
Aggregate.builder().input(input).groupings(groupings);
651+
} else {
652+
// using the deprecated form of Grouping and Aggregate
653+
for (AggregateRel.Grouping grouping : rel.getGroupingsList()) {
654+
groupings.add(
655+
Aggregate.Grouping.builder()
656+
.expressions(
657+
grouping.getGroupingExpressionsList().stream()
658+
.map(protoExprConverter::from)
659+
.collect(Collectors.toList()))
660+
.build());
661+
}
662+
}
663663

664664
List<Aggregate.Measure> measures = new ArrayList<>(rel.getMeasuresCount());
665665
for (AggregateRel.Measure measure : rel.getMeasuresList()) {

0 commit comments

Comments
 (0)