Search in sources :

Example 11 with LogicalAggregate

use of org.apache.calcite.rel.logical.LogicalAggregate 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

LogicalAggregate (org.apache.calcite.rel.logical.LogicalAggregate)11 RelNode (org.apache.calcite.rel.RelNode)7 LogicalFilter (org.apache.calcite.rel.logical.LogicalFilter)4 RelTraitSet (org.apache.calcite.plan.RelTraitSet)3 LogicalJoin (org.apache.calcite.rel.logical.LogicalJoin)3 RelDataType (org.apache.calcite.rel.type.RelDataType)3 RexBuilder (org.apache.calcite.rex.RexBuilder)3 ArrayList (java.util.ArrayList)2 InvalidRelException (org.apache.calcite.rel.InvalidRelException)2 AggregateCall (org.apache.calcite.rel.core.AggregateCall)2 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)2 LogicalTableScan (org.apache.calcite.rel.logical.LogicalTableScan)2 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)2 RexNode (org.apache.calcite.rex.RexNode)2 Test (org.junit.Test)2 Function (com.google.common.base.Function)1 ImmutableList (com.google.common.collect.ImmutableList)1 Duration (java.time.Duration)1 List (java.util.List)1 ReflectiveSchema (org.apache.calcite.adapter.java.ReflectiveSchema)1