Search in sources :

Example 1 with FlinkLogicalWindowAggregate

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

the class StreamPhysicalPythonGroupWindowAggregateRule method matches.

@Override
public boolean matches(RelOptRuleCall call) {
    FlinkLogicalWindowAggregate agg = call.rel(0);
    List<AggregateCall> aggCalls = agg.getAggCallList();
    // check if we have grouping sets
    if (agg.getGroupType() != Aggregate.Group.SIMPLE || agg.indicator) {
        throw new TableException("GROUPING SETS are currently not supported.");
    }
    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) && !PythonUtil.isBuiltInAggregate(x));
    if (existPandasFunction && existGeneralPythonFunction) {
        throw new TableException("Pandas UDAFs and General Python UDAFs are not supported in used together currently.");
    }
    if (existPandasFunction || existGeneralPythonFunction) {
        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) FlinkLogicalWindowAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWindowAggregate)

Example 2 with FlinkLogicalWindowAggregate

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

the class StreamPhysicalPythonGroupWindowAggregateRule method convert.

@Override
public RelNode convert(RelNode rel) {
    FlinkLogicalWindowAggregate agg = (FlinkLogicalWindowAggregate) rel;
    LogicalWindow window = agg.getWindow();
    List<AggregateCall> aggCalls = agg.getAggCallList();
    boolean isPandasPythonUDAF = aggCalls.stream().anyMatch(x -> PythonUtil.isPythonAggregate(x, PythonFunctionKind.PANDAS));
    if (isPandasPythonUDAF && window instanceof SessionGroupWindow) {
        throw new TableException("Session Group Window is currently not supported for Pandas UDAF.");
    }
    RelNode input = agg.getInput();
    RelOptCluster cluster = rel.getCluster();
    FlinkRelDistribution requiredDistribution;
    if (agg.getGroupCount() != 0) {
        requiredDistribution = FlinkRelDistribution.hash(agg.getGroupSet().asList(), true);
    } else {
        requiredDistribution = FlinkRelDistribution.SINGLETON();
    }
    RelTraitSet requiredTraitSet = input.getTraitSet().replace(FlinkConventions.STREAM_PHYSICAL()).replace(requiredDistribution);
    RelTraitSet providedTraitSet = rel.getTraitSet().replace(FlinkConventions.STREAM_PHYSICAL());
    RelNode newInput = RelOptRule.convert(input, requiredTraitSet);
    ReadableConfig config = ShortcutUtils.unwrapTableConfig(rel);
    WindowEmitStrategy emitStrategy = WindowEmitStrategy.apply(config, agg.getWindow());
    if (emitStrategy.produceUpdates()) {
        throw new TableException("Python Group Window Aggregate Function is currently not supported for early fired or lately fired.");
    }
    return new StreamPhysicalPythonGroupWindowAggregate(cluster, providedTraitSet, newInput, rel.getRowType(), agg.getGroupSet().toArray(), JavaScalaConversionUtil.toScala(aggCalls), agg.getWindow(), agg.getNamedProperties(), emitStrategy);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) StreamPhysicalPythonGroupWindowAggregate(org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalPythonGroupWindowAggregate) TableException(org.apache.flink.table.api.TableException) RelTraitSet(org.apache.calcite.plan.RelTraitSet) AggregateCall(org.apache.calcite.rel.core.AggregateCall) FlinkRelDistribution(org.apache.flink.table.planner.plan.trait.FlinkRelDistribution) ReadableConfig(org.apache.flink.configuration.ReadableConfig) LogicalWindow(org.apache.flink.table.planner.plan.logical.LogicalWindow) RelNode(org.apache.calcite.rel.RelNode) WindowEmitStrategy(org.apache.flink.table.planner.plan.utils.WindowEmitStrategy) FlinkLogicalWindowAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWindowAggregate) SessionGroupWindow(org.apache.flink.table.planner.plan.logical.SessionGroupWindow)

Example 3 with FlinkLogicalWindowAggregate

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

the class BatchPhysicalPythonWindowAggregateRule method matches.

@Override
public boolean matches(RelOptRuleCall call) {
    FlinkLogicalWindowAggregate 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) FlinkLogicalWindowAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWindowAggregate)

Example 4 with FlinkLogicalWindowAggregate

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

the class RelTimeIndicatorConverter method visitWindowAggregate.

private FlinkLogicalWindowAggregate visitWindowAggregate(FlinkLogicalWindowAggregate agg) {
    RelNode newInput = convertAggInput(agg);
    List<AggregateCall> updatedAggCalls = convertAggregateCalls(agg);
    return new FlinkLogicalWindowAggregate(agg.getCluster(), agg.getTraitSet(), newInput, agg.getGroupSet(), updatedAggCalls, agg.getWindow(), agg.getNamedProperties());
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) RelNode(org.apache.calcite.rel.RelNode) FlinkLogicalWindowAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWindowAggregate)

Example 5 with FlinkLogicalWindowAggregate

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

the class RelTimeIndicatorConverter method visitWindowTableAggregate.

private RelNode visitWindowTableAggregate(FlinkLogicalWindowTableAggregate tableAgg) {
    FlinkLogicalWindowAggregate correspondingAgg = new FlinkLogicalWindowAggregate(tableAgg.getCluster(), tableAgg.getTraitSet(), tableAgg.getInput(), tableAgg.getGroupSet(), tableAgg.getAggCallList(), tableAgg.getWindow(), tableAgg.getNamedProperties());
    FlinkLogicalWindowAggregate convertedWindowAgg = visitWindowAggregate(correspondingAgg);
    return new FlinkLogicalWindowTableAggregate(tableAgg.getCluster(), tableAgg.getTraitSet(), convertedWindowAgg.getInput(), tableAgg.getGroupSet(), tableAgg.getGroupSets(), convertedWindowAgg.getAggCallList(), tableAgg.getWindow(), tableAgg.getNamedProperties());
}
Also used : FlinkLogicalWindowTableAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWindowTableAggregate) FlinkLogicalWindowAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWindowAggregate)

Aggregations

FlinkLogicalWindowAggregate (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWindowAggregate)6 AggregateCall (org.apache.calcite.rel.core.AggregateCall)5 TableException (org.apache.flink.table.api.TableException)4 RelNode (org.apache.calcite.rel.RelNode)3 RelTraitSet (org.apache.calcite.plan.RelTraitSet)2 LogicalWindow (org.apache.flink.table.planner.plan.logical.LogicalWindow)2 SessionGroupWindow (org.apache.flink.table.planner.plan.logical.SessionGroupWindow)2 FlinkRelDistribution (org.apache.flink.table.planner.plan.trait.FlinkRelDistribution)2 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelCollation (org.apache.calcite.rel.RelCollation)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 ReadableConfig (org.apache.flink.configuration.ReadableConfig)1 UserDefinedFunction (org.apache.flink.table.functions.UserDefinedFunction)1 SlidingGroupWindow (org.apache.flink.table.planner.plan.logical.SlidingGroupWindow)1 TumblingGroupWindow (org.apache.flink.table.planner.plan.logical.TumblingGroupWindow)1 FlinkLogicalWindowTableAggregate (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWindowTableAggregate)1 BatchPhysicalPythonGroupWindowAggregate (org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalPythonGroupWindowAggregate)1 StreamPhysicalPythonGroupWindowAggregate (org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalPythonGroupWindowAggregate)1 WindowEmitStrategy (org.apache.flink.table.planner.plan.utils.WindowEmitStrategy)1 DataType (org.apache.flink.table.types.DataType)1