Search in sources :

Example 1 with TargetMapping

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;
}
Also used : TargetMapping(org.apache.calcite.util.mapping.Mappings.TargetMapping) RelHint(org.apache.calcite.rel.hint.RelHint)

Example 2 with TargetMapping

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)));
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) LogicalAggregate(org.apache.calcite.rel.logical.LogicalAggregate) RelBuilder(org.apache.calcite.tools.RelBuilder) TargetMapping(org.apache.calcite.util.mapping.Mappings.TargetMapping) RelNode(org.apache.calcite.rel.RelNode)

Aggregations

TargetMapping (org.apache.calcite.util.mapping.Mappings.TargetMapping)2 RelNode (org.apache.calcite.rel.RelNode)1 AggregateCall (org.apache.calcite.rel.core.AggregateCall)1 RelHint (org.apache.calcite.rel.hint.RelHint)1 LogicalAggregate (org.apache.calcite.rel.logical.LogicalAggregate)1 RelBuilder (org.apache.calcite.tools.RelBuilder)1