Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,32 @@ public Connection getConnection(ConnectorSession session, JdbcSplit split)
return connection;
}

@Override
public PreparedQuery prepareQuery(
ConnectorSession session,
JdbcTableHandle table,
Optional<List<List<JdbcColumnHandle>>> groupingSets,
List<JdbcColumnHandle> columns,
Map<String, String> columnExpressions)
{
try (Connection connection = connectionFactory.openConnection(session)) {
PreparedQuery preparedQuery = new QueryBuilder(this).prepareQuery(
session,
connection,
table.getRelationHandle(),
groupingSets,
columns,
columnExpressions,
table.getConstraint(),
Optional.empty());
preparedQuery = preparedQuery.transformQuery(tryApplyLimit(table.getLimit()));
return preparedQuery;
}
catch (SQLException e) {
throw new TrinoException(JDBC_ERROR, e);
}
}

@Override
public PreparedStatement buildSql(ConnectorSession session, Connection connection, JdbcSplit split, JdbcTableHandle table, List<JdbcColumnHandle> columns)
throws SQLException
Expand All @@ -428,9 +454,10 @@ public PreparedStatement buildSql(ConnectorSession session, Connection connectio
PreparedQuery preparedQuery = queryBuilder.prepareQuery(
session,
connection,
table.getRemoteTableName(),
table.getGroupingSets(),
table.getRelationHandle(),
Optional.empty(),
columns,
ImmutableMap.of(),
table.getConstraint(),
split.getAdditionalPredicate());
preparedQuery = preparedQuery.transformQuery(tryApplyLimit(table.getLimit()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ public void abortReadConnection(Connection connection)
delegate.abortReadConnection(connection);
}

@Override
public PreparedQuery prepareQuery(
ConnectorSession session,
JdbcTableHandle table,
Optional<List<List<JdbcColumnHandle>>> groupingSets,
List<JdbcColumnHandle> columns,
Map<String, String> columnExpressions)
{
return delegate.prepareQuery(session, table, groupingSets, columns, columnExpressions);
}

@Override
public PreparedStatement buildSql(ConnectorSession session, Connection connection, JdbcSplit split, JdbcTableHandle table, List<JdbcColumnHandle> columns)
throws SQLException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ public void abortReadConnection(Connection connection)
delegate().abortReadConnection(connection);
}

@Override
public PreparedQuery prepareQuery(
ConnectorSession session,
JdbcTableHandle table,
Optional<List<List<JdbcColumnHandle>>> groupingSets,
List<JdbcColumnHandle> columns,
Map<String, String> columnExpressions)
{
return delegate().prepareQuery(session, table, groupingSets, columns, columnExpressions);
}

@Override
public PreparedStatement buildSql(ConnectorSession session, Connection connection, JdbcSplit split, JdbcTableHandle tableHandle, List<JdbcColumnHandle> columnHandles)
throws SQLException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ default void abortReadConnection(Connection connection)
// most drivers do not need this
}

PreparedQuery prepareQuery(
ConnectorSession session,
JdbcTableHandle table,
Optional<List<List<JdbcColumnHandle>>> groupingSets,
List<JdbcColumnHandle> columns,
Map<String, String> columnExpressions);

PreparedStatement buildSql(ConnectorSession session, Connection connection, JdbcSplit split, JdbcTableHandle table, List<JdbcColumnHandle> columns)
throws SQLException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package io.trino.plugin.jdbc;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Joiner;
import io.trino.spi.connector.ColumnHandle;
Expand All @@ -23,14 +22,12 @@

import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;

import static java.util.Objects.requireNonNull;

public final class JdbcColumnHandle
implements ColumnHandle
{
private final Optional<String> expression;
private final String columnName;
private final JdbcTypeHandle jdbcTypeHandle;
private final Type columnType;
Expand All @@ -40,7 +37,7 @@ public final class JdbcColumnHandle
// All and only required fields
public JdbcColumnHandle(String columnName, JdbcTypeHandle jdbcTypeHandle, Type columnType)
{
this(Optional.empty(), columnName, jdbcTypeHandle, columnType, true, Optional.empty());
this(columnName, jdbcTypeHandle, columnType, true, Optional.empty());
}

/**
Expand All @@ -49,7 +46,7 @@ public JdbcColumnHandle(String columnName, JdbcTypeHandle jdbcTypeHandle, Type c
@Deprecated
public JdbcColumnHandle(String columnName, JdbcTypeHandle jdbcTypeHandle, Type columnType, boolean nullable)
{
this(Optional.empty(), columnName, jdbcTypeHandle, columnType, nullable, Optional.empty());
this(columnName, jdbcTypeHandle, columnType, nullable, Optional.empty());
}

/**
Expand All @@ -58,27 +55,19 @@ public JdbcColumnHandle(String columnName, JdbcTypeHandle jdbcTypeHandle, Type c
@Deprecated
@JsonCreator
public JdbcColumnHandle(
@JsonProperty("expression") Optional<String> expression,
@JsonProperty("columnName") String columnName,
@JsonProperty("jdbcTypeHandle") JdbcTypeHandle jdbcTypeHandle,
@JsonProperty("columnType") Type columnType,
@JsonProperty("nullable") boolean nullable,
@JsonProperty("comment") Optional<String> comment)
{
this.expression = requireNonNull(expression, "expression is null");
this.columnName = requireNonNull(columnName, "columnName is null");
this.jdbcTypeHandle = requireNonNull(jdbcTypeHandle, "jdbcTypeHandle is null");
this.columnType = requireNonNull(columnType, "columnType is null");
this.nullable = nullable;
this.comment = requireNonNull(comment, "comment is null");
}

@JsonProperty
public Optional<String> getExpression()
{
return expression;
}

@JsonProperty
public String getColumnName()
{
Expand Down Expand Up @@ -109,12 +98,6 @@ public Optional<String> getComment()
return comment;
}

@JsonIgnore
public boolean isSynthetic()
{
return expression.isPresent();
}

public ColumnMetadata getColumnMetadata()
{
return ColumnMetadata.builder()
Expand Down Expand Up @@ -148,19 +131,11 @@ public int hashCode()
public String toString()
{
return Joiner.on(":").skipNulls().join(
expression.orElse(null),
columnName,
columnType.getDisplayName(),
jdbcTypeHandle.getJdbcTypeName().orElse(null));
}

public String toSqlExpression(Function<String, String> identifierQuote)
{
requireNonNull(identifierQuote, "identifierQuote is null");
return expression
.orElseGet(() -> identifierQuote.apply(columnName));
}

public static Builder builder()
{
return new Builder();
Expand All @@ -173,7 +148,6 @@ public static Builder builderFrom(JdbcColumnHandle handle)

public static final class Builder
{
private Optional<String> expression = Optional.empty();
private String columnName;
private JdbcTypeHandle jdbcTypeHandle;
private Type columnType;
Expand All @@ -184,20 +158,13 @@ public Builder() {}

private Builder(JdbcColumnHandle handle)
{
this.expression = handle.getExpression();
this.columnName = handle.getColumnName();
this.jdbcTypeHandle = handle.getJdbcTypeHandle();
this.columnType = handle.getColumnType();
this.nullable = handle.isNullable();
this.comment = handle.getComment();
}

public Builder setExpression(Optional<String> expression)
{
this.expression = expression;
return this;
}

public Builder setColumnName(String columnName)
{
this.columnName = columnName;
Expand Down Expand Up @@ -231,7 +198,6 @@ public Builder setComment(Optional<String> comment)
public JdbcColumnHandle build()
{
return new JdbcColumnHandle(
expression,
columnName,
jdbcTypeHandle,
columnType,
Expand Down
Loading