use of org.apache.calcite.rel.core.AggregateCall 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);
}
use of org.apache.calcite.rel.core.AggregateCall 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.calcite.rel.core.AggregateCall 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;
}
}
use of org.apache.calcite.rel.core.AggregateCall 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());
}
use of org.apache.calcite.rel.core.AggregateCall in project beam by apache.
the class AggregateScanConverter method convert.
@Override
public RelNode convert(ResolvedAggregateScan zetaNode, List<RelNode> inputs) {
LogicalProject input = convertAggregateScanInputScanToLogicalProject(zetaNode, inputs.get(0));
// Calcite LogicalAggregate's GroupSet is indexes of group fields starting from 0.
int groupFieldsListSize = zetaNode.getGroupByList().size();
ImmutableBitSet groupSet;
if (groupFieldsListSize != 0) {
groupSet = ImmutableBitSet.of(IntStream.rangeClosed(0, groupFieldsListSize - 1).boxed().collect(Collectors.toList()));
} else {
groupSet = ImmutableBitSet.of();
}
// TODO: add support for indicator
List<AggregateCall> aggregateCalls;
if (zetaNode.getAggregateList().isEmpty()) {
aggregateCalls = ImmutableList.of();
} else {
aggregateCalls = new ArrayList<>();
// For aggregate calls, their input ref follow after GROUP BY input ref.
int columnRefoff = groupFieldsListSize;
for (ResolvedComputedColumn computedColumn : zetaNode.getAggregateList()) {
AggregateCall aggCall = convertAggCall(computedColumn, columnRefoff, groupSet.size(), input);
aggregateCalls.add(aggCall);
if (!aggCall.getArgList().isEmpty()) {
// Only increment column reference offset when aggregates use them (BEAM-8042).
// Ex: COUNT(*) does not have arguments, while COUNT(`field`) does.
columnRefoff++;
}
}
}
LogicalAggregate logicalAggregate = new LogicalAggregate(getCluster(), input.getTraitSet(), input, groupSet, ImmutableList.of(groupSet), aggregateCalls);
return logicalAggregate;
}
Aggregations