Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -238,7 +238,7 @@ public Optional<JdbcTableHandle> getTableHandle(ConnectorSession session, Schema
try (ResultSet resultSet = getTables(connection, Optional.of(remoteSchema), Optional.of(remoteTable))) {
List<JdbcTableHandle> tableHandles = new ArrayList<>();
while (resultSet.next()) {
tableHandles.add(new JdbcTableHandle(schemaTableName, getRemoteTable(resultSet), getTableComment(resultSet)));
tableHandles.add(new JdbcTableHandle(schemaTableName, getRemoteTable(resultSet), getTableComment(resultSet), connectionFactory.getConnectionUrl()));
}
if (tableHandles.isEmpty()) {
return Optional.empty();
Expand Down Expand Up @@ -1229,7 +1229,7 @@ public JdbcMergeTableHandle beginMerge(

List<JdbcColumnHandle> columns = getColumns(session, schemaTableName, remoteTableName);

JdbcTableHandle plainTable = new JdbcTableHandle(schemaTableName, remoteTableName, Optional.empty());
JdbcTableHandle plainTable = new JdbcTableHandle(schemaTableName, remoteTableName, Optional.empty(), handle.getTableLocation());

JdbcOutputTableHandle outputTableHandle = beginInsertTable(session, plainTable, columns);
rollbackActions.add(() -> rollbackCreateTable(session, outputTableHandle));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Optional;

@FunctionalInterface
public interface ConnectionFactory
Expand All @@ -26,6 +27,11 @@ public interface ConnectionFactory
Connection openConnection(ConnectorSession session)
throws SQLException;

default Optional<String> getConnectionUrl()
{
return Optional.empty();
}

@Override
@PreDestroy
default void close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ public Optional<ConstraintApplicationResult<ConnectorTableHandle>> applyFilter(C
handle.getOtherReferencedTables(),
handle.getNextSyntheticColumnId(),
handle.getAuthorization(),
handle.getUpdateAssignments());
handle.getUpdateAssignments(),
handle.getTableLocation());

return Optional.of(new ConstraintApplicationResult<>(handle, remainingFilter, remainingExpression, precalculateStatisticsForPushdown));
}
Expand All @@ -308,7 +309,8 @@ private JdbcTableHandle flushAttributesAsQuery(ConnectorSession session, JdbcTab
handle.getAllReferencedTables(),
handle.getNextSyntheticColumnId(),
handle.getAuthorization(),
handle.getUpdateAssignments());
handle.getUpdateAssignments(),
handle.getTableLocation());
}

@Override
Expand Down Expand Up @@ -367,7 +369,8 @@ public Optional<ProjectionApplicationResult<ConnectorTableHandle>> applyProjecti
handle.getOtherReferencedTables(),
handle.getNextSyntheticColumnId(),
handle.getAuthorization(),
handle.getUpdateAssignments()),
handle.getUpdateAssignments(),
handle.getTableLocation()),
projections,
assignments.entrySet().stream()
.map(assignment -> new Assignment(
Expand Down Expand Up @@ -927,7 +930,8 @@ public Optional<LimitApplicationResult<ConnectorTableHandle>> applyLimit(Connect
handle.getOtherReferencedTables(),
handle.getNextSyntheticColumnId(),
handle.getAuthorization(),
handle.getUpdateAssignments());
handle.getUpdateAssignments(),
handle.getTableLocation());

return Optional.of(new LimitApplicationResult<>(handle, jdbcClient.isLimitGuaranteed(session), precalculateStatisticsForPushdown));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.Optional;
import java.util.Properties;

import static com.google.common.base.Preconditions.checkState;
Expand Down Expand Up @@ -52,6 +53,12 @@ public DriverConnectionFactory(
this.dataSource = new TracingDataSource(requireNonNull(openTelemetry, "openTelemetry is null"), driver, connectionUrl);
}

@Override
public Optional<String> getConnectionUrl()
{
return Optional.of(connectionUrl);
}

@Override
public Connection openConnection(ConnectorSession session)
throws SQLException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ private MergeJdbcPageSource createMergePageSource(
tableHandle.getOtherReferencedTables(),
tableHandle.getNextSyntheticColumnId(),
tableHandle.getAuthorization(),
tableHandle.getUpdateAssignments());
tableHandle.getUpdateAssignments(),
tableHandle.getTableLocation());
return new MergeJdbcPageSource(
createPageSource(session, jdbcSplit, newTableHandle, scanColumns),
columnAdaptationsBuilder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableSet;
import io.trino.plugin.jdbc.expression.ParameterizedExpression;
import io.trino.spi.connector.ColumnHandle;
import io.trino.spi.connector.ConnectorTableLocation;
import io.trino.spi.connector.SchemaTableName;
import io.trino.spi.expression.Constant;
import io.trino.spi.predicate.TupleDomain;
Expand All @@ -38,6 +39,7 @@

public final class JdbcTableHandle
extends BaseJdbcConnectorTableHandle
implements ConnectorTableLocation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we have a SPI specific API in ConnectorMetadata which would resolve location based on ConnectorTableHandle ?

{
private final JdbcRelationHandle relationHandle;

Expand All @@ -63,8 +65,14 @@ public final class JdbcTableHandle
private final int nextSyntheticColumnId;
private final Optional<String> authorization;
private final List<JdbcAssignmentItem> updateAssignments;
private final Optional<String> connectionUrl;

public JdbcTableHandle(SchemaTableName schemaTableName, RemoteTableName remoteTableName, Optional<String> comment)
{
this(schemaTableName, remoteTableName, comment, Optional.empty());
}

public JdbcTableHandle(SchemaTableName schemaTableName, RemoteTableName remoteTableName, Optional<String> comment, Optional<String> connectionUrl)
{
this(
new JdbcNamedRelationHandle(schemaTableName, remoteTableName, comment),
Expand All @@ -76,7 +84,8 @@ public JdbcTableHandle(SchemaTableName schemaTableName, RemoteTableName remoteTa
Optional.of(ImmutableSet.of()),
0,
Optional.empty(),
ImmutableList.of());
ImmutableList.of(),
connectionUrl);
}

@JsonCreator
Expand All @@ -90,7 +99,8 @@ public JdbcTableHandle(
@JsonProperty("otherReferencedTables") Optional<Set<SchemaTableName>> otherReferencedTables,
@JsonProperty("nextSyntheticColumnId") int nextSyntheticColumnId,
@JsonProperty("authorization") Optional<String> authorization,
@JsonProperty("updateAssignments") List<JdbcAssignmentItem> updateAssignments)
@JsonProperty("updateAssignments") List<JdbcAssignmentItem> updateAssignments,
@JsonProperty("connectionUrl") Optional<String> connectionUrl)
{
this.relationHandle = requireNonNull(relationHandle, "relationHandle is null");
this.constraint = requireNonNull(constraint, "constraint is null");
Expand All @@ -103,6 +113,7 @@ public JdbcTableHandle(
this.nextSyntheticColumnId = nextSyntheticColumnId;
this.authorization = requireNonNull(authorization, "authorization is null");
this.updateAssignments = requireNonNull(updateAssignments, "updateAssignments is null");
this.connectionUrl = requireNonNull(connectionUrl, "connectionUrl is null");
}

public JdbcTableHandle intersectedWithConstraint(TupleDomain<ColumnHandle> newConstraint)
Expand All @@ -117,7 +128,8 @@ public JdbcTableHandle intersectedWithConstraint(TupleDomain<ColumnHandle> newCo
otherReferencedTables,
nextSyntheticColumnId,
authorization,
updateAssignments);
updateAssignments,
connectionUrl);
}

public JdbcTableHandle withAssignments(Map<ColumnHandle, Constant> assignments)
Expand All @@ -137,7 +149,8 @@ public JdbcTableHandle withAssignments(Map<ColumnHandle, Constant> assignments)
.map(e -> {
return new JdbcAssignmentItem((JdbcColumnHandle) e.getKey(), new QueryParameter(e.getValue().getType(), Optional.ofNullable(e.getValue().getValue())));
})
.collect(toImmutableList()));
.collect(toImmutableList()),
connectionUrl);
}

public JdbcNamedRelationHandle asPlainTable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ public void testApplyTableScanRedirect()
Optional.of(ImmutableSet.of()),
0,
Optional.empty(),
ImmutableList.of());
ImmutableList.of(),
baseTableHandle.getTableLocation());

// redirection is not applied if constraintExpressions is present
assertThat(metadata.applyTableScanRedirect(session, filterWithConstraintExpressionResult)).isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ private ConnectorPageSource getCursor(JdbcTableHandle jdbcTableHandle, List<Colu
jdbcTableHandle.getOtherReferencedTables(),
jdbcTableHandle.getNextSyntheticColumnId(),
Optional.empty(),
ImmutableList.of());
ImmutableList.of(),
jdbcTableHandle.getTableLocation());

ConnectorSplitSource splits = jdbcClient.getSplits(SESSION, jdbcTableHandle);
JdbcSplit split = (JdbcSplit) getOnlyElement(getFutureValue(splits.getNextBatch(1000)).getSplits());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public ConnectorMergeTableHandle beginMerge(ConnectorSession session, ConnectorT
handle.getOtherReferencedTables(),
handle.getNextSyntheticColumnId(),
handle.getAuthorization(),
handle.getUpdateAssignments());
handle.getUpdateAssignments(),
handle.getTableLocation());
}

return new IgniteMergeTableHandle(
Expand Down
Loading