Search in sources :

Example 1 with FlinkLogicalOverAggregate

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

the class StreamPhysicalPythonOverAggregateRule method convert.

@Override
public RelNode convert(RelNode rel) {
    FlinkLogicalOverAggregate logicWindow = (FlinkLogicalOverAggregate) rel;
    if (logicWindow.groups.size() > 1) {
        throw new TableException("Over Agg: Unsupported use of OVER windows. " + "All aggregates must be computed on the same window. " + "please re-check the over window statement.");
    }
    ImmutableBitSet keys = logicWindow.groups.get(0).keys;
    FlinkRelDistribution requiredDistribution;
    if (!keys.isEmpty()) {
        requiredDistribution = FlinkRelDistribution.hash(keys.asList(), true);
    } else {
        requiredDistribution = FlinkRelDistribution.SINGLETON();
    }
    RelNode input = logicWindow.getInput();
    RelTraitSet requiredTraitSet = input.getTraitSet().replace(FlinkConventions.STREAM_PHYSICAL()).replace(requiredDistribution);
    RelTraitSet providedTraitSet = rel.getTraitSet().replace(FlinkConventions.STREAM_PHYSICAL());
    RelNode newInput = RelOptRule.convert(input, requiredTraitSet);
    return new StreamPhysicalPythonOverAggregate(rel.getCluster(), providedTraitSet, newInput, rel.getRowType(), logicWindow);
}
Also used : TableException(org.apache.flink.table.api.TableException) FlinkRelDistribution(org.apache.flink.table.planner.plan.trait.FlinkRelDistribution) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) RelNode(org.apache.calcite.rel.RelNode) FlinkLogicalOverAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalOverAggregate) StreamPhysicalPythonOverAggregate(org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalPythonOverAggregate) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 2 with FlinkLogicalOverAggregate

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

the class StreamPhysicalPythonOverAggregateRule method matches.

@Override
public boolean matches(RelOptRuleCall call) {
    FlinkLogicalOverAggregate logicWindow = call.rel(0);
    List<AggregateCall> aggCalls = logicWindow.groups.get(0).getAggregateCalls(logicWindow);
    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 Python UDAFs are not supported in stream 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) FlinkLogicalOverAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalOverAggregate)

Aggregations

TableException (org.apache.flink.table.api.TableException)2 FlinkLogicalOverAggregate (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalOverAggregate)2 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 RelNode (org.apache.calcite.rel.RelNode)1 AggregateCall (org.apache.calcite.rel.core.AggregateCall)1 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)1 StreamPhysicalPythonOverAggregate (org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalPythonOverAggregate)1 FlinkRelDistribution (org.apache.flink.table.planner.plan.trait.FlinkRelDistribution)1