Search in sources :

Example 1 with FlinkLogicalAggregate

use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalAggregate in project flink by apache.

the class StreamPhysicalPythonGroupAggregateRule method convert.

@Override
public RelNode convert(RelNode rel) {
    FlinkLogicalAggregate agg = (FlinkLogicalAggregate) rel;
    FlinkRelDistribution requiredDistribution;
    if (agg.getGroupCount() != 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 StreamPhysicalPythonGroupAggregate(rel.getCluster(), providedTraitSet, newInput, rel.getRowType(), agg.getGroupSet().toArray(), JavaScalaConversionUtil.toScala(agg.getAggCallList()));
}
Also used : FlinkRelDistribution(org.apache.flink.table.planner.plan.trait.FlinkRelDistribution) RelNode(org.apache.calcite.rel.RelNode) FlinkLogicalAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalAggregate) RelTraitSet(org.apache.calcite.plan.RelTraitSet) StreamPhysicalPythonGroupAggregate(org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalPythonGroupAggregate)

Example 2 with FlinkLogicalAggregate

use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalAggregate in project flink by apache.

the class BatchPhysicalPythonAggregateRule method matches.

@Override
public boolean matches(RelOptRuleCall call) {
    FlinkLogicalAggregate agg = call.rel(0);
    List<AggregateCall> aggCalls = agg.getAggCallList();
    boolean existGeneralPythonFunction = aggCalls.stream().anyMatch(x -> PythonUtil.isPythonAggregate(x, PythonFunctionKind.GENERAL));
    boolean existPandasFunction = aggCalls.stream().anyMatch(x -> PythonUtil.isPythonAggregate(x, PythonFunctionKind.PANDAS));
    boolean existJavaFunction = aggCalls.stream().anyMatch(x -> !PythonUtil.isPythonAggregate(x, null));
    if (existPandasFunction || existGeneralPythonFunction) {
        if (existGeneralPythonFunction) {
            throw new TableException("non-Pandas UDAFs are not supported in batch mode currently.");
        }
        if (existJavaFunction) {
            throw new TableException("Python UDAF and Java/Scala UDAF cannot be used together.");
        }
        return true;
    } else {
        return false;
    }
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) TableException(org.apache.flink.table.api.TableException) FlinkLogicalAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalAggregate)

Example 3 with FlinkLogicalAggregate

use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalAggregate in project flink by apache.

the class RelTimeIndicatorConverter method visitTableAggregate.

private RelNode visitTableAggregate(FlinkLogicalTableAggregate tableAgg) {
    FlinkLogicalAggregate correspondingAgg = FlinkLogicalAggregate.create(tableAgg.getInput(), tableAgg.getGroupSet(), tableAgg.getGroupSets(), tableAgg.getAggCallList());
    FlinkLogicalAggregate convertedAgg = visitAggregate(correspondingAgg);
    return new FlinkLogicalTableAggregate(tableAgg.getCluster(), tableAgg.getTraitSet(), convertedAgg.getInput(), convertedAgg.getGroupSet(), convertedAgg.getGroupSets(), convertedAgg.getAggCallList());
}
Also used : FlinkLogicalTableAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableAggregate) FlinkLogicalAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalAggregate)

Example 4 with FlinkLogicalAggregate

use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalAggregate 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 5 with FlinkLogicalAggregate

use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalAggregate in project flink by apache.

the class StreamPhysicalPythonGroupAggregateRule method matches.

@Override
public boolean matches(RelOptRuleCall call) {
    FlinkLogicalAggregate agg = call.rel(0);
    // check if we have grouping sets
    if (agg.getGroupType() != Aggregate.Group.SIMPLE || agg.indicator) {
        throw new TableException("GROUPING SETS are currently not supported.");
    }
    List<AggregateCall> aggCalls = agg.getAggCallList();
    boolean existGeneralPythonFunction = aggCalls.stream().anyMatch(x -> PythonUtil.isPythonAggregate(x, PythonFunctionKind.GENERAL));
    boolean existPandasFunction = aggCalls.stream().anyMatch(x -> PythonUtil.isPythonAggregate(x, PythonFunctionKind.PANDAS));
    boolean existJavaUserDefinedFunction = aggCalls.stream().anyMatch(x -> !PythonUtil.isPythonAggregate(x, null) && !PythonUtil.isBuiltInAggregate(x));
    if (existPandasFunction || existGeneralPythonFunction) {
        if (existPandasFunction) {
            throw new TableException("Pandas UDAFs are not supported in streaming mode currently.");
        }
        if (existJavaUserDefinedFunction) {
            throw new TableException("Python UDAF and Java/Scala UDAF cannot be used together.");
        }
        return true;
    } else {
        return false;
    }
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) TableException(org.apache.flink.table.api.TableException) FlinkLogicalAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalAggregate)

Aggregations

FlinkLogicalAggregate (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalAggregate)6 AggregateCall (org.apache.calcite.rel.core.AggregateCall)4 RelNode (org.apache.calcite.rel.RelNode)3 RelTraitSet (org.apache.calcite.plan.RelTraitSet)2 TableException (org.apache.flink.table.api.TableException)2 FlinkRelDistribution (org.apache.flink.table.planner.plan.trait.FlinkRelDistribution)2 RelCollation (org.apache.calcite.rel.RelCollation)1 UserDefinedFunction (org.apache.flink.table.functions.UserDefinedFunction)1 FlinkLogicalTableAggregate (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableAggregate)1 BatchPhysicalPythonGroupAggregate (org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalPythonGroupAggregate)1 StreamPhysicalPythonGroupAggregate (org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalPythonGroupAggregate)1 DataType (org.apache.flink.table.types.DataType)1 Seq (scala.collection.Seq)1