Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add for support creating table with comment for more Jdbc based connectors #16135

Merged
merged 2 commits into from
Apr 5, 2023
Merged
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 @@ -650,8 +650,9 @@ protected JdbcOutputTableHandle createTable(ConnectorSession session, ConnectorT
}

RemoteTableName remoteTableName = new RemoteTableName(Optional.ofNullable(catalog), Optional.ofNullable(remoteSchema), remoteTargetTableName);
String sql = createTableSql(remoteTableName, columnList.build(), tableMetadata);
execute(session, connection, sql);
for (String sql : createTableSqls(remoteTableName, columnList.build(), tableMetadata)) {
execute(session, connection, sql);
}

return new JdbcOutputTableHandle(
catalog,
Expand All @@ -665,6 +666,12 @@ protected JdbcOutputTableHandle createTable(ConnectorSession session, ConnectorT
}
}

protected List<String> createTableSqls(RemoteTableName remoteTableName, List<String> columns, ConnectorTableMetadata tableMetadata)
{
return ImmutableList.of(createTableSql(remoteTableName, columns, tableMetadata));
}

@Deprecated
protected String createTableSql(RemoteTableName remoteTableName, List<String> columns, ConnectorTableMetadata tableMetadata)
{
if (tableMetadata.getComment().isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.String.format;
import static java.lang.String.join;
import static java.math.RoundingMode.UNNECESSARY;
import static java.sql.DatabaseMetaData.columnNoNulls;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -360,10 +361,30 @@ public void createTable(ConnectorSession session, ConnectorTableMetadata tableMe
}

@Override
public Optional<String> getTableComment(ResultSet resultSet)
protected List<String> createTableSqls(RemoteTableName remoteTableName, List<String> columns, ConnectorTableMetadata tableMetadata)
{
// Don't return a comment until the connector supports creating tables with comment
return Optional.empty();
checkArgument(tableMetadata.getProperties().isEmpty(), "Unsupported table properties: %s", tableMetadata.getProperties());
ImmutableList.Builder<String> createTableSqlsBuilder = ImmutableList.builder();
createTableSqlsBuilder.add(format("CREATE TABLE %s (%s)", quoted(remoteTableName), join(", ", columns)));
Optional<String> tableComment = tableMetadata.getComment();
if (tableComment.isPresent()) {
createTableSqlsBuilder.add(buildTableCommentSql(remoteTableName, tableComment));
}
return createTableSqlsBuilder.build();
}

@Override
public void setTableComment(ConnectorSession session, JdbcTableHandle handle, Optional<String> comment)
{
execute(session, buildTableCommentSql(handle.asPlainTable().getRemoteTableName(), comment));
}

private String buildTableCommentSql(RemoteTableName remoteTableName, Optional<String> comment)
{
return format(
"COMMENT ON TABLE %s IS %s",
quoted(remoteTableName),
comment.map(BaseJdbcClient::varcharLiteral).orElse("NULL"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,13 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_JOIN_PUSHDOWN_WITH_FULL_JOIN:
return false;

case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT:
case SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS:
return false;

case SUPPORTS_ADD_COLUMN_WITH_COMMENT:
return false;

case SUPPORTS_COMMENT_ON_TABLE:
return false;

case SUPPORTS_ARRAY:
// Arrays are supported conditionally. Check the defaults.
return new PostgreSqlConfig().getArrayMapping() != PostgreSqlConfig.ArrayMapping.DISABLED;
Expand Down