use of io.trino.plugin.jdbc.JdbcColumnHandle in project trino by trinodb.
the class ImplementAvgFloatingPoint 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("avg(%s)", context.rewriteExpression(argument).orElseThrow()), columnHandle.getJdbcTypeHandle()));
}
use of io.trino.plugin.jdbc.JdbcColumnHandle in project trino by trinodb.
the class ImplementCorr method rewrite.
@Override
public Optional<JdbcExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<String> context) {
List<Variable> arguments = captures.get(ARGUMENTS);
verify(arguments.size() == 2);
Variable argument1 = arguments.get(0);
Variable argument2 = arguments.get(1);
JdbcColumnHandle columnHandle1 = (JdbcColumnHandle) context.getAssignment(argument1.getName());
verify(aggregateFunction.getOutputType().equals(columnHandle1.getColumnType()));
return Optional.of(new JdbcExpression(format("corr(%s, %s)", context.rewriteExpression(argument1).orElseThrow(), context.rewriteExpression(argument2).orElseThrow()), columnHandle1.getJdbcTypeHandle()));
}
use of io.trino.plugin.jdbc.JdbcColumnHandle in project trino by trinodb.
the class ImplementCountDistinct 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() == BIGINT);
boolean isCaseSensitiveType = columnHandle.getColumnType() instanceof CharType || columnHandle.getColumnType() instanceof VarcharType;
if (aggregateFunction.isDistinct() && !isRemoteCollationSensitive && isCaseSensitiveType) {
// Remote database is case insensitive or compares values differently from Trino
return Optional.empty();
}
return Optional.of(new JdbcExpression(format("count(DISTINCT %s)", context.rewriteExpression(argument).orElseThrow()), bigintTypeHandle));
}
use of io.trino.plugin.jdbc.JdbcColumnHandle in project trino by trinodb.
the class ImplementCovarianceSamp method rewrite.
@Override
public Optional<JdbcExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<String> context) {
List<Variable> arguments = captures.get(ARGUMENTS);
verify(arguments.size() == 2);
Variable argument1 = arguments.get(0);
Variable argument2 = arguments.get(1);
JdbcColumnHandle columnHandle1 = (JdbcColumnHandle) context.getAssignment(argument1.getName());
verify(aggregateFunction.getOutputType().equals(columnHandle1.getColumnType()));
return Optional.of(new JdbcExpression(format("covar_samp(%s, %s)", context.rewriteExpression(argument1).orElseThrow(), context.rewriteExpression(argument2).orElseThrow()), columnHandle1.getJdbcTypeHandle()));
}
use of io.trino.plugin.jdbc.JdbcColumnHandle in project trino by trinodb.
the class ImplementRegrIntercept method rewrite.
@Override
public Optional<JdbcExpression> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext<String> context) {
List<Variable> arguments = captures.get(ARGUMENTS);
verify(arguments.size() == 2);
Variable argument1 = arguments.get(0);
Variable argument2 = arguments.get(1);
JdbcColumnHandle columnHandle1 = (JdbcColumnHandle) context.getAssignment(argument1.getName());
verify(aggregateFunction.getOutputType().equals(columnHandle1.getColumnType()));
return Optional.of(new JdbcExpression(format("regr_intercept(%s, %s)", context.rewriteExpression(argument1).orElseThrow(), context.rewriteExpression(argument2).orElseThrow()), columnHandle1.getJdbcTypeHandle()));
}
Aggregations