Search in sources :

Example 6 with FlinkRelDistribution

use of org.apache.flink.table.planner.plan.trait.FlinkRelDistribution in project flink by apache.

the class BatchPhysicalPythonAggregateRule method convert.

@Override
public RelNode convert(RelNode relNode) {
    FlinkLogicalAggregate agg = (FlinkLogicalAggregate) relNode;
    RelNode input = agg.getInput();
    int[] groupSet = agg.getGroupSet().toArray();
    RelTraitSet traitSet = relNode.getTraitSet().replace(FlinkConventions.BATCH_PHYSICAL());
    Tuple2<int[], Seq<AggregateCall>> auxGroupSetAndCallsTuple = AggregateUtil.checkAndSplitAggCalls(agg);
    int[] auxGroupSet = auxGroupSetAndCallsTuple._1;
    Seq<AggregateCall> aggCallsWithoutAuxGroupCalls = auxGroupSetAndCallsTuple._2;
    Tuple3<int[][], DataType[][], UserDefinedFunction[]> aggBufferTypesAndFunctions = AggregateUtil.transformToBatchAggregateFunctions(FlinkTypeFactory.toLogicalRowType(input.getRowType()), aggCallsWithoutAuxGroupCalls, null);
    UserDefinedFunction[] aggFunctions = aggBufferTypesAndFunctions._3();
    RelTraitSet requiredTraitSet = input.getTraitSet().replace(FlinkConventions.BATCH_PHYSICAL());
    if (groupSet.length != 0) {
        FlinkRelDistribution requiredDistribution = FlinkRelDistribution.hash(groupSet, false);
        requiredTraitSet = requiredTraitSet.replace(requiredDistribution);
        RelCollation sortCollation = createRelCollation(groupSet);
        requiredTraitSet = requiredTraitSet.replace(sortCollation);
    } else {
        requiredTraitSet = requiredTraitSet.replace(FlinkRelDistribution.SINGLETON());
    }
    RelNode convInput = RelOptRule.convert(input, requiredTraitSet);
    return new BatchPhysicalPythonGroupAggregate(relNode.getCluster(), traitSet, convInput, agg.getRowType(), convInput.getRowType(), convInput.getRowType(), groupSet, auxGroupSet, aggCallsWithoutAuxGroupCalls, aggFunctions);
}
Also used : UserDefinedFunction(org.apache.flink.table.functions.UserDefinedFunction) RelTraitSet(org.apache.calcite.plan.RelTraitSet) AggregateCall(org.apache.calcite.rel.core.AggregateCall) FlinkRelDistribution(org.apache.flink.table.planner.plan.trait.FlinkRelDistribution) RelCollation(org.apache.calcite.rel.RelCollation) RelNode(org.apache.calcite.rel.RelNode) BatchPhysicalPythonGroupAggregate(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalPythonGroupAggregate) FlinkLogicalAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalAggregate) DataType(org.apache.flink.table.types.DataType) Seq(scala.collection.Seq)

Example 7 with FlinkRelDistribution

use of org.apache.flink.table.planner.plan.trait.FlinkRelDistribution in project flink by apache.

the class BatchPhysicalPythonWindowAggregateRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    FlinkLogicalWindowAggregate agg = call.rel(0);
    RelNode input = agg.getInput();
    LogicalWindow window = agg.getWindow();
    if (!(window instanceof TumblingGroupWindow && AggregateUtil.hasTimeIntervalType(((TumblingGroupWindow) window).size()) || window instanceof SlidingGroupWindow && AggregateUtil.hasTimeIntervalType(((SlidingGroupWindow) window).size()) || window instanceof SessionGroupWindow)) {
        // sliding & tumbling count window and session window not supported
        throw new TableException("Window " + window + " is not supported right now.");
    }
    int[] groupSet = agg.getGroupSet().toArray();
    RelTraitSet traitSet = agg.getTraitSet().replace(FlinkConventions.BATCH_PHYSICAL());
    Tuple2<int[], Seq<AggregateCall>> auxGroupSetAndCallsTuple = AggregateUtil.checkAndSplitAggCalls(agg);
    int[] auxGroupSet = auxGroupSetAndCallsTuple._1;
    Seq<AggregateCall> aggCallsWithoutAuxGroupCalls = auxGroupSetAndCallsTuple._2;
    Tuple3<int[][], DataType[][], UserDefinedFunction[]> aggBufferTypesAndFunctions = AggregateUtil.transformToBatchAggregateFunctions(FlinkTypeFactory.toLogicalRowType(input.getRowType()), aggCallsWithoutAuxGroupCalls, null);
    UserDefinedFunction[] aggFunctions = aggBufferTypesAndFunctions._3();
    int inputTimeFieldIndex = AggregateUtil.timeFieldIndex(input.getRowType(), call.builder(), window.timeAttribute());
    RelDataType inputTimeFieldType = input.getRowType().getFieldList().get(inputTimeFieldIndex).getType();
    boolean inputTimeIsDate = inputTimeFieldType.getSqlTypeName() == SqlTypeName.DATE;
    RelTraitSet requiredTraitSet = agg.getTraitSet().replace(FlinkConventions.BATCH_PHYSICAL());
    if (groupSet.length != 0) {
        FlinkRelDistribution requiredDistribution = FlinkRelDistribution.hash(groupSet, false);
        requiredTraitSet = requiredTraitSet.replace(requiredDistribution);
    } else {
        requiredTraitSet = requiredTraitSet.replace(FlinkRelDistribution.SINGLETON());
    }
    RelCollation sortCollation = createRelCollation(groupSet, inputTimeFieldIndex);
    requiredTraitSet = requiredTraitSet.replace(sortCollation);
    RelNode newInput = RelOptRule.convert(input, requiredTraitSet);
    BatchPhysicalPythonGroupWindowAggregate windowAgg = new BatchPhysicalPythonGroupWindowAggregate(agg.getCluster(), traitSet, newInput, agg.getRowType(), newInput.getRowType(), groupSet, auxGroupSet, aggCallsWithoutAuxGroupCalls, aggFunctions, window, inputTimeFieldIndex, inputTimeIsDate, agg.getNamedProperties());
    call.transformTo(windowAgg);
}
Also used : TableException(org.apache.flink.table.api.TableException) UserDefinedFunction(org.apache.flink.table.functions.UserDefinedFunction) BatchPhysicalPythonGroupWindowAggregate(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalPythonGroupWindowAggregate) RelDataType(org.apache.calcite.rel.type.RelDataType) RelTraitSet(org.apache.calcite.plan.RelTraitSet) AggregateCall(org.apache.calcite.rel.core.AggregateCall) FlinkRelDistribution(org.apache.flink.table.planner.plan.trait.FlinkRelDistribution) RelCollation(org.apache.calcite.rel.RelCollation) LogicalWindow(org.apache.flink.table.planner.plan.logical.LogicalWindow) TumblingGroupWindow(org.apache.flink.table.planner.plan.logical.TumblingGroupWindow) RelNode(org.apache.calcite.rel.RelNode) FlinkLogicalWindowAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWindowAggregate) DataType(org.apache.flink.table.types.DataType) RelDataType(org.apache.calcite.rel.type.RelDataType) SlidingGroupWindow(org.apache.flink.table.planner.plan.logical.SlidingGroupWindow) SessionGroupWindow(org.apache.flink.table.planner.plan.logical.SessionGroupWindow) Seq(scala.collection.Seq)

Example 8 with FlinkRelDistribution

use of org.apache.flink.table.planner.plan.trait.FlinkRelDistribution in project flink by apache.

the class StreamPhysicalPythonGroupTableAggregateRule method convert.

@Override
public RelNode convert(RelNode rel) {
    FlinkLogicalTableAggregate agg = (FlinkLogicalTableAggregate) rel;
    FlinkRelDistribution requiredDistribution;
    if (agg.getGroupSet().cardinality() != 0) {
        requiredDistribution = FlinkRelDistribution.hash(agg.getGroupSet().asList(), true);
    } else {
        requiredDistribution = FlinkRelDistribution.SINGLETON();
    }
    RelTraitSet requiredTraitSet = rel.getCluster().getPlanner().emptyTraitSet().replace(requiredDistribution).replace(FlinkConventions.STREAM_PHYSICAL());
    RelTraitSet providedTraitSet = rel.getTraitSet().replace(FlinkConventions.STREAM_PHYSICAL());
    RelNode newInput = RelOptRule.convert(agg.getInput(), requiredTraitSet);
    return new StreamPhysicalPythonGroupTableAggregate(rel.getCluster(), providedTraitSet, newInput, rel.getRowType(), agg.getGroupSet().toArray(), JavaScalaConversionUtil.toScala(agg.getAggCallList()));
}
Also used : StreamPhysicalPythonGroupTableAggregate(org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalPythonGroupTableAggregate) FlinkRelDistribution(org.apache.flink.table.planner.plan.trait.FlinkRelDistribution) FlinkLogicalTableAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableAggregate) RelNode(org.apache.calcite.rel.RelNode) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Aggregations

FlinkRelDistribution (org.apache.flink.table.planner.plan.trait.FlinkRelDistribution)8 RelTraitSet (org.apache.calcite.plan.RelTraitSet)7 RelNode (org.apache.calcite.rel.RelNode)7 AggregateCall (org.apache.calcite.rel.core.AggregateCall)3 TableException (org.apache.flink.table.api.TableException)3 RelCollation (org.apache.calcite.rel.RelCollation)2 UserDefinedFunction (org.apache.flink.table.functions.UserDefinedFunction)2 LogicalWindow (org.apache.flink.table.planner.plan.logical.LogicalWindow)2 SessionGroupWindow (org.apache.flink.table.planner.plan.logical.SessionGroupWindow)2 FlinkLogicalAggregate (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalAggregate)2 FlinkLogicalWindowAggregate (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWindowAggregate)2 DataType (org.apache.flink.table.types.DataType)2 Seq (scala.collection.Seq)2 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)1 ReadableConfig (org.apache.flink.configuration.ReadableConfig)1 SliceAttachedWindowingStrategy (org.apache.flink.table.planner.plan.logical.SliceAttachedWindowingStrategy)1 SlidingGroupWindow (org.apache.flink.table.planner.plan.logical.SlidingGroupWindow)1 TimeAttributeWindowingStrategy (org.apache.flink.table.planner.plan.logical.TimeAttributeWindowingStrategy)1