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 @@ -689,7 +689,8 @@ public void commitCreateTable(ConnectorSession session, JdbcOutputTableHandle ha
@Override
public void renameTable(ConnectorSession session, JdbcTableHandle handle, SchemaTableName newTableName)
{
renameTable(session, handle.getCatalogName(), handle.getSchemaName(), handle.getTableName(), newTableName);
RemoteTableName remoteTableName = handle.asPlainTable().getRemoteTableName();
renameTable(session, remoteTableName.getCatalogName().orElse(null), remoteTableName.getSchemaName().orElse(null), remoteTableName.getTableName(), newTableName);
}

protected void renameTable(ConnectorSession session, String catalogName, String remoteSchemaName, String remoteTableName, SchemaTableName newTable)
Expand Down Expand Up @@ -833,9 +834,8 @@ public void rollbackCreateTable(ConnectorSession session, JdbcOutputTableHandle
if (handle.getTemporaryTableName().isPresent()) {
dropTable(session, new JdbcTableHandle(
new SchemaTableName(handle.getSchemaName(), handle.getTemporaryTableName().get()),
handle.getCatalogName(),
handle.getSchemaName(),
handle.getTemporaryTableName().get()));
new RemoteTableName(Optional.ofNullable(handle.getCatalogName()), Optional.ofNullable(handle.getSchemaName()), handle.getTemporaryTableName().get()),
Optional.empty()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import io.trino.spi.connector.SchemaTableName;
import io.trino.spi.predicate.TupleDomain;

import javax.annotation.Nullable;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -61,12 +59,6 @@ public final class JdbcTableHandle

private final int nextSyntheticColumnId;

@Deprecated
public JdbcTableHandle(SchemaTableName schemaTableName, @Nullable String catalogName, @Nullable String schemaName, String tableName)
{
this(schemaTableName, new RemoteTableName(Optional.ofNullable(catalogName), Optional.ofNullable(schemaName), tableName), Optional.empty());
}

public JdbcTableHandle(SchemaTableName schemaTableName, RemoteTableName remoteTableName, Optional<String> comment)
{
this(
Expand Down Expand Up @@ -115,28 +107,6 @@ public JdbcTableHandle intersectedWithConstraint(TupleDomain<ColumnHandle> newCo
nextSyntheticColumnId);
}

/**
* @deprecated Use {@code asPlainTable().getSchemaTableName()} instead, but see those methods for more information, as this is not a drop-in replacement.
*/
@Deprecated
@JsonIgnore
// TODO (https://github.com/trinodb/trino/issues/6797) remove
public SchemaTableName getSchemaTableName()
{
return getRequiredNamedRelation().getSchemaTableName();
}

/**
* @deprecated Use {@code asPlainTable().getRemoteTableName()} instead, but see those methods for more information, as this is not a drop-in replacement.
*/
@Deprecated
@JsonIgnore
// TODO (https://github.com/trinodb/trino/issues/6797) remove
public RemoteTableName getRemoteTableName()
{
return getRequiredNamedRelation().getRemoteTableName();
}

public JdbcNamedRelationHandle asPlainTable()
{
checkState(!isSynthetic(), "The table handle does not represent a plain table: %s", this);
Expand All @@ -156,41 +126,6 @@ public JdbcRelationHandle getRelationHandle()
return relationHandle;
}

/**
* @deprecated Use {@code asPlainTable().getRemoteTableName().getCatalogName()} instead, but see those methods for more information, as this is not a drop-in replacement.
*/
@Deprecated
@JsonIgnore
@Nullable
// TODO (https://github.com/trinodb/trino/issues/6797) remove
public String getCatalogName()
{
return getRemoteTableName().getCatalogName().orElse(null);
}

/**
* @deprecated Use {@code asPlainTable().getRemoteTableName().getSchemaName()} instead, but see those methods for more information, as this is not a drop-in replacement.
*/
@Deprecated
@JsonIgnore
@Nullable
// TODO (https://github.com/trinodb/trino/issues/6797) remove
public String getSchemaName()
{
return getRemoteTableName().getSchemaName().orElse(null);
}

/**
* @deprecated Use {@code asPlainTable().getRemoteTableName().getTableName()} instead, but see those methods for more information, as this is not a drop-in replacement.
*/
@Deprecated
@JsonIgnore
// TODO (https://github.com/trinodb/trino/issues/6797) remove
public String getTableName()
{
return getRemoteTableName().getTableName();
}

@JsonProperty
public TupleDomain<ColumnHandle> getConstraint()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ public void testGetColumnHandles()
"value", new JdbcColumnHandle("VALUE", JDBC_BIGINT, BIGINT)));

// unknown table
unknownTableColumnHandle(new JdbcTableHandle(new SchemaTableName("unknown", "unknown"), "unknown", "unknown", "unknown"));
unknownTableColumnHandle(new JdbcTableHandle(new SchemaTableName("example", "numbers"), null, "example", "unknown"));
unknownTableColumnHandle(new JdbcTableHandle(new SchemaTableName("unknown", "unknown"), new RemoteTableName(Optional.of("unknown"), Optional.of("unknown"), "unknown"), Optional.empty()));
unknownTableColumnHandle(new JdbcTableHandle(new SchemaTableName("example", "numbers"), new RemoteTableName(Optional.empty(), Optional.of("example"), "unknown"), Optional.empty()));
}

private void unknownTableColumnHandle(JdbcTableHandle tableHandle)
{
assertThatThrownBy(() -> metadata.getColumnHandles(SESSION, tableHandle))
.isInstanceOf(TableNotFoundException.class)
.hasMessage("Table '%s' has no supported columns (all 0 columns are not supported)", tableHandle.getSchemaTableName());
.hasMessage("Table '%s' has no supported columns (all 0 columns are not supported)", tableHandle.asPlainTable().getSchemaTableName());
}

@Test
Expand All @@ -134,16 +134,16 @@ public void getTableMetadata()
new ColumnMetadata("va%ue", BIGINT)));

// unknown tables should produce null
unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("u", "numbers"), null, "unknown", "unknown"));
unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("example", "numbers"), null, "example", "unknown"));
unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("example", "numbers"), null, "unknown", "numbers"));
unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("u", "numbers"), new RemoteTableName(Optional.empty(), Optional.of("unknown"), "unknown"), Optional.empty()));
unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("example", "numbers"), new RemoteTableName(Optional.empty(), Optional.of("example"), "unknown"), Optional.empty()));
unknownTableMetadata(new JdbcTableHandle(new SchemaTableName("example", "numbers"), new RemoteTableName(Optional.empty(), Optional.of("unknown"), "numbers"), Optional.empty()));
}

private void unknownTableMetadata(JdbcTableHandle tableHandle)
{
assertThatThrownBy(() -> metadata.getTableMetadata(SESSION, tableHandle))
.isInstanceOf(TableNotFoundException.class)
.hasMessage("Table '%s' has no supported columns (all 0 columns are not supported)", tableHandle.getSchemaTableName());
.hasMessage("Table '%s' has no supported columns (all 0 columns are not supported)", tableHandle.asPlainTable().getSchemaTableName());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public void testMetadata()
SchemaTableName schemaTableName = new SchemaTableName("example", "numbers");
Optional<JdbcTableHandle> table = jdbcClient.getTableHandle(session, schemaTableName);
assertTrue(table.isPresent(), "table is missing");
assertEquals(table.get().getCatalogName(), catalogName.toUpperCase(ENGLISH));
assertEquals(table.get().getSchemaName(), "EXAMPLE");
assertEquals(table.get().getTableName(), "NUMBERS");
assertEquals(table.get().getRequiredNamedRelation().getRemoteTableName().getCatalogName().orElse(null), catalogName.toUpperCase(ENGLISH));
assertEquals(table.get().getRequiredNamedRelation().getRemoteTableName().getSchemaName().orElse(null), "EXAMPLE");
assertEquals(table.get().getRequiredNamedRelation().getRemoteTableName().getTableName(), "NUMBERS");
assertEquals(table.get().getRequiredNamedRelation().getSchemaTableName(), schemaTableName);
assertEquals(jdbcClient.getColumns(session, table.orElse(null)), ImmutableList.of(
new JdbcColumnHandle("TEXT", JDBC_VARCHAR, VARCHAR),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ public class TestJdbcTableHandle
@Test
public void testJsonRoundTrip()
{
assertJsonRoundTrip(TABLE_CODEC, new JdbcTableHandle(new SchemaTableName("schema", "table"), "jdbcCatalog", "jdbcSchema", "jdbcTable"));
assertJsonRoundTrip(TABLE_CODEC, new JdbcTableHandle(new SchemaTableName("schema", "table"), new RemoteTableName(Optional.of("jdbcCatalog"), Optional.of("jdbcSchema"), "jdbcTable"), Optional.empty()));
}

@Test
public void testEquivalence()
{
EquivalenceTester.equivalenceTester()
.addEquivalentGroup(
new JdbcTableHandle(new SchemaTableName("schema", "table"), "jdbcCatalog", "jdbcSchema", "jdbcTable"),
new JdbcTableHandle(new SchemaTableName("schema", "table"), "jdbcCatalogX", "jdbcSchema", "jdbcTable"),
new JdbcTableHandle(new SchemaTableName("schema", "table"), "jdbcCatalog", "jdbcSchemaX", "jdbcTable"),
new JdbcTableHandle(new SchemaTableName("schema", "table"), "jdbcCatalog", "jdbcSchema", "jdbcTableX"))
new JdbcTableHandle(new SchemaTableName("schema", "table"), new RemoteTableName(Optional.of("jdbcCatalog"), Optional.of("jdbcSchema"), "jdbcTable"), Optional.empty()),
new JdbcTableHandle(new SchemaTableName("schema", "table"), new RemoteTableName(Optional.of("jdbcCatalogX"), Optional.of("jdbcSchema"), "jdbcTable"), Optional.empty()),
new JdbcTableHandle(new SchemaTableName("schema", "table"), new RemoteTableName(Optional.of("jdbcCatalog"), Optional.of("jdbcSchemaX"), "jdbcTable"), Optional.empty()),
new JdbcTableHandle(new SchemaTableName("schema", "table"), new RemoteTableName(Optional.of("jdbcCatalog"), Optional.of("jdbcSchema"), "jdbcTableX"), Optional.empty()))
.addEquivalentGroup(
new JdbcTableHandle(new SchemaTableName("schemaX", "table"), "jdbcCatalog", "jdbcSchema", "jdbcTable"),
new JdbcTableHandle(new SchemaTableName("schemaX", "table"), "jdbcCatalogX", "jdbcSchema", "jdbcTable"),
new JdbcTableHandle(new SchemaTableName("schemaX", "table"), "jdbcCatalog", "jdbcSchemaX", "jdbcTable"),
new JdbcTableHandle(new SchemaTableName("schemaX", "table"), "jdbcCatalog", "jdbcSchema", "jdbcTableX"))
new JdbcTableHandle(new SchemaTableName("schemaX", "table"), new RemoteTableName(Optional.of("jdbcCatalog"), Optional.of("jdbcSchema"), "jdbcTable"), Optional.empty()),
new JdbcTableHandle(new SchemaTableName("schemaX", "table"), new RemoteTableName(Optional.of("jdbcCatalogX"), Optional.of("jdbcSchema"), "jdbcTable"), Optional.empty()),
new JdbcTableHandle(new SchemaTableName("schemaX", "table"), new RemoteTableName(Optional.of("jdbcCatalog"), Optional.of("jdbcSchemaX"), "jdbcTable"), Optional.empty()),
new JdbcTableHandle(new SchemaTableName("schemaX", "table"), new RemoteTableName(Optional.of("jdbcCatalog"), Optional.of("jdbcSchema"), "jdbcTableX"), Optional.empty()))
.addEquivalentGroup(createNamedHandle())
.addEquivalentGroup(createQueryBasedHandle())
.check();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public void addColumn(ConnectorSession session, JdbcTableHandle handle, ColumnMe
protected String renameColumnSql(JdbcTableHandle handle, JdbcColumnHandle jdbcColumn, String newRemoteColumnName)
{
return format("ALTER TABLE %s RENAME COLUMN %s TO %s ",
quoted(handle.getRemoteTableName()),
quoted(handle.asPlainTable().getRemoteTableName()),
quoted(jdbcColumn.getColumnName()),
quoted(newRemoteColumnName));
}
Expand Down Expand Up @@ -463,7 +463,7 @@ protected Optional<List<String>> getTableTypes()
@Override
public void dropTable(ConnectorSession session, JdbcTableHandle handle)
{
String sql = "DROP TABLE " + quoted(handle.getRemoteTableName());
String sql = "DROP TABLE " + quoted(handle.asPlainTable().getRemoteTableName());
execute(session, sql);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,8 @@ public Optional<JdbcTableHandle> getTableHandle(ConnectorSession session, Schema
if (Objects.equals(schemaName, jdbcSchemaName) && Objects.equals(tableName, jdbcTableName)) {
tableHandles.add(new JdbcTableHandle(
schemaTableName,
DRUID_CATALOG,
schemaName,
tableName));
new RemoteTableName(Optional.of(DRUID_CATALOG), Optional.ofNullable(schemaName), tableName),
Optional.empty()));
}
}
if (tableHandles.isEmpty()) {
Expand Down Expand Up @@ -377,17 +376,19 @@ protected PreparedQuery prepareQuery(ConnectorSession session, Connection connec
private JdbcTableHandle prepareTableHandleForQuery(JdbcTableHandle table)
{
if (table.isNamedRelation()) {
String schemaName = table.getSchemaName();
JdbcNamedRelationHandle relation = table.getRequiredNamedRelation();
RemoteTableName remoteTableName = relation.getRemoteTableName();
String schemaName = remoteTableName.getSchemaName().orElse(null);
checkArgument("druid".equals(schemaName), "Only \"druid\" schema is supported");

table = new JdbcTableHandle(
new JdbcNamedRelationHandle(
table.getRequiredNamedRelation().getSchemaTableName(),
relation.getSchemaTableName(),
// Druid doesn't like table names to be qualified with catalog names in the SQL query, hence we null out the catalog.
new RemoteTableName(
Optional.empty(),
table.getRequiredNamedRelation().getRemoteTableName().getSchemaName(),
table.getRequiredNamedRelation().getRemoteTableName().getTableName()),
remoteTableName.getSchemaName(),
remoteTableName.getTableName()),
Optional.empty()),
table.getConstraint(),
table.getConstraintExpressions(),
Expand Down Expand Up @@ -415,10 +416,11 @@ private JdbcTableHandle prepareTableHandleForQuery(JdbcTableHandle table)
protected ResultSet getColumns(JdbcTableHandle tableHandle, DatabaseMetaData metadata)
throws SQLException
{
RemoteTableName remoteTableName = tableHandle.getRequiredNamedRelation().getRemoteTableName();
return metadata.getColumns(
tableHandle.getCatalogName(),
tableHandle.getSchemaName(),
tableHandle.getTableName(),
remoteTableName.getCatalogName().orElse(null),
remoteTableName.getSchemaName().orElse(null),
remoteTableName.getTableName(),
null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,12 @@ public void renameColumn(ConnectorSession session, JdbcTableHandle handle, JdbcC
{
try (Connection connection = connectionFactory.openConnection(session)) {
String newRemoteColumnName = getIdentifierMapping().toRemoteColumnName(connection, newColumnName);
RemoteTableName remoteTableName = handle.asPlainTable().getRemoteTableName();
// MariaDB versions earlier than 10.5.2 do not support the RENAME COLUMN syntax
// ALTER TABLE ... CHANGE statement exists in th old versions, but it requires providing all attributes of the column
String sql = format(
"ALTER TABLE %s RENAME COLUMN %s TO %s",
quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTableName()),
quoted(remoteTableName.getCatalogName().orElse(null), remoteTableName.getSchemaName().orElse(null), remoteTableName.getTableName()),
quoted(jdbcColumn.getColumnName()),
quoted(newRemoteColumnName));
execute(connection, sql);
Expand Down Expand Up @@ -495,8 +496,9 @@ public void renameTable(ConnectorSession session, JdbcTableHandle handle, Schema
{
// MariaDB doesn't support specifying the catalog name in a rename. By setting the
// catalogName parameter to null, it will be omitted in the ALTER TABLE statement.
verify(handle.getSchemaName() == null);
renameTable(session, null, handle.getCatalogName(), handle.getTableName(), newTableName);
RemoteTableName remoteTableName = handle.asPlainTable().getRemoteTableName();
verify(remoteTableName.getSchemaName().isEmpty());
renameTable(session, null, remoteTableName.getCatalogName().orElse(null), remoteTableName.getTableName(), newTableName);
}

@Override
Expand Down
Loading