Skip to content

Commit

Permalink
fix renameTable fail
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry-024 committed Jan 8, 2025
1 parent d6039fb commit 685224e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ public void createTable(Identifier identifier, Schema schema, boolean ignoreIfEx
@Override
public void renameTable(Identifier fromTable, Identifier toTable, boolean ignoreIfNotExists)
throws TableNotExistException, TableAlreadyExistException {
checkNotBranch(fromTable, "renameTable");
checkNotBranch(toTable, "renameTable");
checkNotSystemTable(fromTable, "renameTable");
checkNotSystemTable(toTable, "renameTable");
try {
RenameTableRequest request = new RenameTableRequest(toTable);
client.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.paimon.rest.requests.AlterTableRequest;
import org.apache.paimon.rest.requests.CreateDatabaseRequest;
import org.apache.paimon.rest.requests.CreateTableRequest;
import org.apache.paimon.rest.requests.RenameTableRequest;
import org.apache.paimon.rest.responses.CreateDatabaseResponse;
import org.apache.paimon.rest.responses.ErrorResponse;
import org.apache.paimon.rest.responses.GetDatabaseResponse;
Expand Down Expand Up @@ -114,7 +115,27 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
String databaseName = resources[0];
boolean isTables = resources.length == 2 && "tables".equals(resources[1]);
boolean isTable = resources.length == 3 && "tables".equals(resources[1]);
if (isTable) {
if (resources.length == 4 && "rename".equals(resources[3])) {
RenameTableRequest requestBody =
mapper.readValue(
request.getBody().readUtf8(), RenameTableRequest.class);
catalog.renameTable(
Identifier.create(databaseName, resources[2]),
requestBody.getNewIdentifier(),
false);
FileStoreTable table =
(FileStoreTable)
catalog.getTable(requestBody.getNewIdentifier());
response =
new GetTableResponse(
AbstractCatalog.newTableLocation(
catalog.warehouse(),
requestBody.getNewIdentifier())
.toString(),
table.schema().id(),
table.schema().toSchema());
return mockResponse(response, 200);
} else if (isTable) {
String tableName = resources[2];
return tableApiHandler(catalog, request, databaseName, tableName);
} else if (isTables) {
Expand Down

0 comments on commit 685224e

Please sign in to comment.