Search in sources :

Example 1 with AggregateExpression

use of io.trino.plugin.pinot.query.AggregateExpression in project trino by trinodb.

the class PinotMetadata method resolveAggregateExpressionWithAlias.

private static PinotColumnHandle resolveAggregateExpressionWithAlias(PinotColumnHandle aggregateColumn, Map<String, PinotColumnHandle> projectionsMap) {
    checkState(aggregateColumn.isAggregate() && aggregateColumn.getPushedDownAggregateFunctionName().isPresent() && aggregateColumn.getPushedDownAggregateFunctionArgument().isPresent(), "Column is not a pushed down aggregate column");
    PinotColumnHandle selection = projectionsMap.get(aggregateColumn.getPushedDownAggregateFunctionArgument().get());
    if (selection != null && selection.isAliased()) {
        AggregateExpression pushedDownAggregateExpression = new AggregateExpression(aggregateColumn.getPushedDownAggregateFunctionName().get(), aggregateColumn.getPushedDownAggregateFunctionArgument().get(), aggregateColumn.isReturnNullOnEmptyGroup());
        AggregateExpression newPushedDownAggregateExpression = replaceIdentifier(pushedDownAggregateExpression, selection);
        return new PinotColumnHandle(pushedDownAggregateExpression.toFieldName(), aggregateColumn.getDataType(), newPushedDownAggregateExpression.toExpression(), true, aggregateColumn.isAggregate(), aggregateColumn.isReturnNullOnEmptyGroup(), aggregateColumn.getPushedDownAggregateFunctionName(), Optional.of(newPushedDownAggregateExpression.getArgument()));
    }
    return aggregateColumn;
}
Also used : AggregateExpression(io.trino.plugin.pinot.query.AggregateExpression)

Example 2 with AggregateExpression

use of io.trino.plugin.pinot.query.AggregateExpression in project trino by trinodb.

the class ImplementAvg method rewrite.

@Override
public Optional<AggregateExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<Void> context) {
    Variable argument = captures.get(ARGUMENT);
    PinotColumnHandle columnHandle = (PinotColumnHandle) context.getAssignment(argument.getName());
    return Optional.of(new AggregateExpression(aggregateFunction.getFunctionName(), identifierQuote.apply(columnHandle.getColumnName()), true));
}
Also used : PinotColumnHandle(io.trino.plugin.pinot.PinotColumnHandle) Variable(io.trino.spi.expression.Variable) AggregateExpression(io.trino.plugin.pinot.query.AggregateExpression)

Example 3 with AggregateExpression

use of io.trino.plugin.pinot.query.AggregateExpression in project trino by trinodb.

the class ImplementCountDistinct method rewrite.

@Override
public Optional<AggregateExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<Void> context) {
    if (!isCountDistinctPushdownEnabled(context.getSession())) {
        return Optional.empty();
    }
    Variable argument = captures.get(ARGUMENT);
    verify(aggregateFunction.getOutputType() == BIGINT);
    return Optional.of(new AggregateExpression("distinctcount", identifierQuote.apply(argument.getName()), false));
}
Also used : Variable(io.trino.spi.expression.Variable) AggregateExpression(io.trino.plugin.pinot.query.AggregateExpression)

Example 4 with AggregateExpression

use of io.trino.plugin.pinot.query.AggregateExpression in project trino by trinodb.

the class ImplementMinMax method rewrite.

@Override
public Optional<AggregateExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<Void> context) {
    Variable argument = captures.get(ARGUMENT);
    PinotColumnHandle columnHandle = (PinotColumnHandle) context.getAssignment(argument.getName());
    verify(columnHandle.getDataType().equals(aggregateFunction.getOutputType()));
    return Optional.of(new AggregateExpression(aggregateFunction.getFunctionName(), identifierQuote.apply(columnHandle.getColumnName()), true));
}
Also used : PinotColumnHandle(io.trino.plugin.pinot.PinotColumnHandle) Variable(io.trino.spi.expression.Variable) AggregateExpression(io.trino.plugin.pinot.query.AggregateExpression)

Example 5 with AggregateExpression

use of io.trino.plugin.pinot.query.AggregateExpression in project trino by trinodb.

the class ImplementApproxDistinct method rewrite.

@Override
public Optional<AggregateExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<Void> context) {
    Variable argument = captures.get(ARGUMENT);
    PinotColumnHandle columnHandle = (PinotColumnHandle) context.getAssignment(argument.getName());
    return Optional.of(new AggregateExpression("distinctcounthll", identifierQuote.apply(columnHandle.getColumnName()), false));
}
Also used : PinotColumnHandle(io.trino.plugin.pinot.PinotColumnHandle) Variable(io.trino.spi.expression.Variable) AggregateExpression(io.trino.plugin.pinot.query.AggregateExpression)

Aggregations

AggregateExpression (io.trino.plugin.pinot.query.AggregateExpression)7 Variable (io.trino.spi.expression.Variable)6 PinotColumnHandle (io.trino.plugin.pinot.PinotColumnHandle)4 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 DynamicTable (io.trino.plugin.pinot.query.DynamicTable)1 AggregateFunction (io.trino.spi.connector.AggregateFunction)1 Assignment (io.trino.spi.connector.Assignment)1 ConnectorExpression (io.trino.spi.expression.ConnectorExpression)1 ArrayType (io.trino.spi.type.ArrayType)1 OptionalLong (java.util.OptionalLong)1