-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support aggregation function in extended expression from/to poj…
…o/proto
- Loading branch information
1 parent
3d9b927
commit e790492
Showing
7 changed files
with
297 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
core/src/main/java/io/substrait/relation/AggregateFunctionProtoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.substrait.relation; | ||
|
||
import io.substrait.expression.FunctionArg; | ||
import io.substrait.expression.proto.ExpressionProtoConverter; | ||
import io.substrait.extension.ExtensionCollector; | ||
import io.substrait.proto.AggregateFunction; | ||
import io.substrait.type.proto.TypeProtoConverter; | ||
import java.util.stream.IntStream; | ||
|
||
/** | ||
* Converts from {@link io.substrait.relation.Aggregate.Measure} to {@link | ||
* io.substrait.proto.AggregateFunction} | ||
*/ | ||
public class AggregateFunctionProtoController { | ||
|
||
private final ExpressionProtoConverter exprProtoConverter; | ||
private final TypeProtoConverter typeProtoConverter; | ||
private final ExtensionCollector functionCollector; | ||
|
||
public AggregateFunctionProtoController(ExtensionCollector functionCollector) { | ||
this.functionCollector = functionCollector; | ||
this.exprProtoConverter = new ExpressionProtoConverter(functionCollector, null); | ||
this.typeProtoConverter = new TypeProtoConverter(functionCollector); | ||
} | ||
|
||
public AggregateFunction toProto(Aggregate.Measure measure) { | ||
var argVisitor = FunctionArg.toProto(typeProtoConverter, exprProtoConverter); | ||
var args = measure.getFunction().arguments(); | ||
var aggFuncDef = measure.getFunction().declaration(); | ||
|
||
return AggregateFunction.newBuilder() | ||
.setPhase(measure.getFunction().aggregationPhase().toProto()) | ||
.setInvocation(measure.getFunction().invocation().toProto()) | ||
.setOutputType(measure.getFunction().getType().accept(typeProtoConverter)) | ||
.addAllArguments( | ||
IntStream.range(0, args.size()) | ||
.mapToObj(i -> args.get(i).accept(aggFuncDef, i, argVisitor)) | ||
.collect(java.util.stream.Collectors.toList())) | ||
.setFunctionReference( | ||
functionCollector.getFunctionReference(measure.getFunction().declaration())) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 0 additions & 67 deletions
67
core/src/test/java/io/substrait/extendedexpression/ExtendedExpressionProtoConverterTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.