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()));
}
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;
}
}
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());
}
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);
}
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;
}
}
Aggregations