Search in sources :

Example 1 with SqlAuxiliaryGroupAggFunction

use of org.apache.flink.table.planner.functions.sql.internal.SqlAuxiliaryGroupAggFunction in project flink by apache.

the class FlinkAggregateRemoveRule method matches.

@Override
public boolean matches(RelOptRuleCall call) {
    final Aggregate aggregate = call.rel(0);
    final RelNode input = call.rel(1);
    if (aggregate.getGroupCount() == 0 || aggregate.indicator || aggregate.getGroupType() != Aggregate.Group.SIMPLE) {
        return false;
    }
    for (AggregateCall aggCall : aggregate.getAggCallList()) {
        SqlKind aggCallKind = aggCall.getAggregation().getKind();
        // TODO supports more AggregateCalls
        boolean isAllowAggCall = aggCallKind == SqlKind.SUM || aggCallKind == SqlKind.MIN || aggCallKind == SqlKind.MAX || aggCall.getAggregation() instanceof SqlAuxiliaryGroupAggFunction;
        if (!isAllowAggCall || aggCall.filterArg >= 0 || aggCall.getArgList().size() != 1) {
            return false;
        }
    }
    final RelMetadataQuery mq = call.getMetadataQuery();
    return SqlFunctions.isTrue(mq.areColumnsUnique(input, aggregate.getGroupSet()));
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelNode(org.apache.calcite.rel.RelNode) SqlAuxiliaryGroupAggFunction(org.apache.flink.table.planner.functions.sql.internal.SqlAuxiliaryGroupAggFunction) Aggregate(org.apache.calcite.rel.core.Aggregate) LogicalAggregate(org.apache.calcite.rel.logical.LogicalAggregate) SqlKind(org.apache.calcite.sql.SqlKind)

Aggregations

RelNode (org.apache.calcite.rel.RelNode)1 Aggregate (org.apache.calcite.rel.core.Aggregate)1 AggregateCall (org.apache.calcite.rel.core.AggregateCall)1 LogicalAggregate (org.apache.calcite.rel.logical.LogicalAggregate)1 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)1 SqlKind (org.apache.calcite.sql.SqlKind)1 SqlAuxiliaryGroupAggFunction (org.apache.flink.table.planner.functions.sql.internal.SqlAuxiliaryGroupAggFunction)1