Search in sources :

Example 1 with JdbcColumnHandle

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

the class ImplementAvgDecimal 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());
    DecimalType type = (DecimalType) columnHandle.getColumnType();
    verify(aggregateFunction.getOutputType().equals(type));
    return Optional.of(new JdbcExpression(format("CAST(avg(%s) AS decimal(%s, %s))", context.rewriteExpression(argument).orElseThrow(), type.getPrecision(), type.getScale()), columnHandle.getJdbcTypeHandle()));
}
Also used : Variable(io.trino.spi.expression.Variable) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) DecimalType(io.trino.spi.type.DecimalType) JdbcExpression(io.trino.plugin.jdbc.JdbcExpression)

Example 2 with JdbcColumnHandle

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

the class ImplementCovariancePop 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_pop(%s, %s)", context.rewriteExpression(argument1).orElseThrow(), context.rewriteExpression(argument2).orElseThrow()), columnHandle1.getJdbcTypeHandle()));
}
Also used : Variable(io.trino.spi.expression.Variable) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) JdbcExpression(io.trino.plugin.jdbc.JdbcExpression)

Example 3 with JdbcColumnHandle

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

the class ImplementMinMax 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(aggregateFunction.getOutputType()));
    // Remote database is case insensitive or sorts values differently from Trino
    if (!isRemoteCollationSensitive && (columnHandle.getColumnType() instanceof CharType || columnHandle.getColumnType() instanceof VarcharType)) {
        return Optional.empty();
    }
    return Optional.of(new JdbcExpression(format("%s(%s)", aggregateFunction.getFunctionName(), context.rewriteExpression(argument).orElseThrow()), columnHandle.getJdbcTypeHandle()));
}
Also used : Variable(io.trino.spi.expression.Variable) VarcharType(io.trino.spi.type.VarcharType) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) JdbcExpression(io.trino.plugin.jdbc.JdbcExpression) CharType(io.trino.spi.type.CharType)

Example 4 with JdbcColumnHandle

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

the class ImplementStddevSamp 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_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 5 with JdbcColumnHandle

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

the class PhoenixMetadata method beginInsert.

@Override
public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle tableHandle, List<ColumnHandle> columns) {
    JdbcTableHandle handle = (JdbcTableHandle) tableHandle;
    Optional<String> rowkeyColumn = phoenixClient.getColumns(session, handle).stream().map(JdbcColumnHandle::getColumnName).filter(ROWKEY::equalsIgnoreCase).findFirst();
    List<JdbcColumnHandle> columnHandles = columns.stream().map(JdbcColumnHandle.class::cast).collect(toImmutableList());
    return new PhoenixOutputTableHandle(handle.getSchemaName(), handle.getTableName(), columnHandles.stream().map(JdbcColumnHandle::getColumnName).collect(toImmutableList()), columnHandles.stream().map(JdbcColumnHandle::getColumnType).collect(toImmutableList()), Optional.of(columnHandles.stream().map(JdbcColumnHandle::getJdbcTypeHandle).collect(toImmutableList())), rowkeyColumn);
}
Also used : JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle)

Aggregations

JdbcColumnHandle (io.trino.plugin.jdbc.JdbcColumnHandle)27 JdbcExpression (io.trino.plugin.jdbc.JdbcExpression)18 Variable (io.trino.spi.expression.Variable)18 JdbcTableHandle (io.trino.plugin.jdbc.JdbcTableHandle)8 TrinoException (io.trino.spi.TrinoException)3 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Lists (com.google.common.collect.Lists)2 Logger (io.airlift.log.Logger)2 JdbcTypeHandle (io.trino.plugin.jdbc.JdbcTypeHandle)2 HostAddress (io.trino.spi.HostAddress)2 ConnectorSession (io.trino.spi.connector.ConnectorSession)2 ConnectorSplit (io.trino.spi.connector.ConnectorSplit)2 ConnectorSplitManager (io.trino.spi.connector.ConnectorSplitManager)2 ConnectorSplitSource (io.trino.spi.connector.ConnectorSplitSource)2 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)2 ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)2