use of org.apache.calcite.util.mapping.Mappings.TargetMapping in project flink by apache.
the class WrapJsonAggFunctionArgumentsRule method getAggArgsMapping.
/**
* Returns a {@link TargetMapping} that defines how the arguments of the aggregation must be
* mapped such that the wrapped arguments are used instead.
*/
private TargetMapping getAggArgsMapping(int inputCount, List<Integer> affectedArgs) {
final int newCount = inputCount + affectedArgs.size();
final TargetMapping argsMapping = Mappings.create(MappingType.BIJECTION, newCount, newCount);
for (int i = 0; i < affectedArgs.size(); i++) {
argsMapping.set(affectedArgs.get(i), inputCount + i);
}
return argsMapping;
}
use of org.apache.calcite.util.mapping.Mappings.TargetMapping in project flink by apache.
the class WrapJsonAggFunctionArgumentsRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
final LogicalAggregate aggregate = call.rel(0);
final AggregateCall aggCall = aggregate.getAggCallList().get(0);
final RelNode aggInput = aggregate.getInput();
final RelBuilder relBuilder = call.builder().push(aggInput);
final List<Integer> affectedArgs = getAffectedArgs(aggCall);
addProjections(aggregate.getCluster(), relBuilder, affectedArgs);
final TargetMapping argsMapping = getAggArgsMapping(aggInput.getRowType().getFieldCount(), affectedArgs);
final AggregateCall newAggregateCall = aggCall.transform(argsMapping);
final LogicalAggregate newAggregate = aggregate.copy(aggregate.getTraitSet(), relBuilder.build(), aggregate.getGroupSet(), aggregate.getGroupSets(), Collections.singletonList(newAggregateCall));
call.transformTo(newAggregate.withHints(Collections.singletonList(MARKER_HINT)));
}
Aggregations