Search in sources :

Example 16 with JdbcExpression

use of io.trino.plugin.jdbc.JdbcExpression in project trino by trinodb.

the class ImplementStddevPop method rewrite.

@Override
public Optional<JdbcExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<String> context) {
    Variable argument = captures.get(ARGUMENT);
    JdbcColumnHandle columnHandle = (JdbcColumnHandle) context.getAssignment(argument.getName());
    verify(aggregateFunction.getOutputType() == columnHandle.getColumnType());
    return Optional.of(new JdbcExpression(format("stddev_pop(%s)", context.rewriteExpression(argument).orElseThrow()), columnHandle.getJdbcTypeHandle()));
}
Also used : Variable(io.trino.spi.expression.Variable) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) JdbcExpression(io.trino.plugin.jdbc.JdbcExpression)

Example 17 with JdbcExpression

use of io.trino.plugin.jdbc.JdbcExpression in project trino by trinodb.

the class ImplementSum method rewrite.

@Override
public Optional<JdbcExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<String> context) {
    Variable argument = captures.get(ARGUMENT);
    JdbcColumnHandle columnHandle = (JdbcColumnHandle) context.getAssignment(argument.getName());
    JdbcTypeHandle resultTypeHandle;
    if (columnHandle.getColumnType().equals(aggregateFunction.getOutputType())) {
        resultTypeHandle = columnHandle.getJdbcTypeHandle();
    } else if (aggregateFunction.getOutputType() instanceof DecimalType) {
        Optional<JdbcTypeHandle> decimalTypeHandle = this.decimalTypeHandle.apply(((DecimalType) aggregateFunction.getOutputType()));
        if (decimalTypeHandle.isEmpty()) {
            return Optional.empty();
        }
        resultTypeHandle = decimalTypeHandle.get();
    } else {
        return Optional.empty();
    }
    return Optional.of(new JdbcExpression(format("sum(%s)", context.rewriteExpression(argument).orElseThrow()), resultTypeHandle));
}
Also used : JdbcTypeHandle(io.trino.plugin.jdbc.JdbcTypeHandle) Variable(io.trino.spi.expression.Variable) Optional(java.util.Optional) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) DecimalType(io.trino.spi.type.DecimalType) JdbcExpression(io.trino.plugin.jdbc.JdbcExpression)

Example 18 with JdbcExpression

use of io.trino.plugin.jdbc.JdbcExpression in project trino by trinodb.

the class ImplementVariancePop method rewrite.

@Override
public Optional<JdbcExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<String> context) {
    Variable argument = captures.get(ARGUMENT);
    JdbcColumnHandle columnHandle = (JdbcColumnHandle) context.getAssignment(argument.getName());
    verify(aggregateFunction.getOutputType() == columnHandle.getColumnType());
    return Optional.of(new JdbcExpression(format("var_pop(%s)", context.rewriteExpression(argument).orElseThrow()), columnHandle.getJdbcTypeHandle()));
}
Also used : Variable(io.trino.spi.expression.Variable) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) JdbcExpression(io.trino.plugin.jdbc.JdbcExpression)

Example 19 with JdbcExpression

use of io.trino.plugin.jdbc.JdbcExpression in project trino by trinodb.

the class ImplementVarianceSamp method rewrite.

@Override
public Optional<JdbcExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<String> context) {
    Variable argument = captures.get(ARGUMENT);
    JdbcColumnHandle columnHandle = (JdbcColumnHandle) context.getAssignment(argument.getName());
    verify(aggregateFunction.getOutputType() == columnHandle.getColumnType());
    return Optional.of(new JdbcExpression(format("var_samp(%s)", context.rewriteExpression(argument).orElseThrow()), columnHandle.getJdbcTypeHandle()));
}
Also used : Variable(io.trino.spi.expression.Variable) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) JdbcExpression(io.trino.plugin.jdbc.JdbcExpression)

Example 20 with JdbcExpression

use of io.trino.plugin.jdbc.JdbcExpression in project trino by trinodb.

the class ImplementSqlServerStdev method rewrite.

@Override
public Optional<JdbcExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<String> context) {
    Variable argument = captures.get(ARGUMENT);
    JdbcColumnHandle columnHandle = (JdbcColumnHandle) context.getAssignment(argument.getName());
    verify(columnHandle.getColumnType().equals(DOUBLE));
    verify(aggregateFunction.getOutputType().equals(DOUBLE));
    return Optional.of(new JdbcExpression(format("STDEV(%s)", context.rewriteExpression(argument).orElseThrow()), columnHandle.getJdbcTypeHandle()));
}
Also used : Variable(io.trino.spi.expression.Variable) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) JdbcExpression(io.trino.plugin.jdbc.JdbcExpression)

Aggregations

JdbcExpression (io.trino.plugin.jdbc.JdbcExpression)21 Variable (io.trino.spi.expression.Variable)21 JdbcColumnHandle (io.trino.plugin.jdbc.JdbcColumnHandle)18 JdbcTypeHandle (io.trino.plugin.jdbc.JdbcTypeHandle)2 CharType (io.trino.spi.type.CharType)2 DecimalType (io.trino.spi.type.DecimalType)2 VarcharType (io.trino.spi.type.VarcharType)2 Optional (java.util.Optional)1