Search in sources :

Example 1 with FunctionId

use of io.trino.metadata.FunctionId in project trino by trinodb.

the class PruneCountAggregationOverScalar method apply.

@Override
public Result apply(AggregationNode parent, Captures captures, Context context) {
    if (!parent.hasDefaultOutput() || parent.getOutputSymbols().size() != 1) {
        return Result.empty();
    }
    FunctionId countFunctionId = metadata.resolveFunction(context.getSession(), QualifiedName.of("count"), ImmutableList.of()).getFunctionId();
    Map<Symbol, AggregationNode.Aggregation> assignments = parent.getAggregations();
    for (Map.Entry<Symbol, AggregationNode.Aggregation> entry : assignments.entrySet()) {
        AggregationNode.Aggregation aggregation = entry.getValue();
        requireNonNull(aggregation, "aggregation is null");
        ResolvedFunction resolvedFunction = aggregation.getResolvedFunction();
        if (!countFunctionId.equals(resolvedFunction.getFunctionId())) {
            return Result.empty();
        }
    }
    if (!assignments.isEmpty() && isScalar(parent.getSource(), context.getLookup())) {
        return Result.ofPlanNode(new ValuesNode(parent.getId(), parent.getOutputSymbols(), ImmutableList.of(new Row(ImmutableList.of(new GenericLiteral("BIGINT", "1"))))));
    }
    return Result.empty();
}
Also used : FunctionId(io.trino.metadata.FunctionId) ValuesNode(io.trino.sql.planner.plan.ValuesNode) Symbol(io.trino.sql.planner.Symbol) ResolvedFunction(io.trino.metadata.ResolvedFunction) AggregationNode(io.trino.sql.planner.plan.AggregationNode) Row(io.trino.sql.tree.Row) Map(java.util.Map) GenericLiteral(io.trino.sql.tree.GenericLiteral)

Aggregations

FunctionId (io.trino.metadata.FunctionId)1 ResolvedFunction (io.trino.metadata.ResolvedFunction)1 Symbol (io.trino.sql.planner.Symbol)1 AggregationNode (io.trino.sql.planner.plan.AggregationNode)1 ValuesNode (io.trino.sql.planner.plan.ValuesNode)1 GenericLiteral (io.trino.sql.tree.GenericLiteral)1 Row (io.trino.sql.tree.Row)1 Map (java.util.Map)1