Skip to content

Conversation

@kbendick
Copy link
Contributor

Adds RenameTableRequest as a request for the RESTCatalog and adds the call for renameTable to the RESTCatalog.

@github-actions github-actions bot added the core label Mar 31, 2022
@kbendick kbendick force-pushed the rename-table-request branch from 8ba9b83 to f701064 Compare March 31, 2022 18:51
Copy link
Contributor

@rdblue rdblue left a comment

Choose a reason for hiding this comment

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

Mostly looks good. I think we should allow empty namespaces and add the additional tests. Thanks, @kbendick!

@kbendick kbendick force-pushed the rename-table-request branch from f701064 to 5db9e19 Compare May 3, 2022 02:22
err -> {
if (err instanceof SQLIntegrityConstraintViolationException) {
if (err instanceof SQLIntegrityConstraintViolationException ||
err.getMessage() != null && err.getMessage().contains("UNIQUE constraint failed")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this test is going to hold up for most JDBC databases.

There's a SQLCode on the error, but it was SQLIte specific in the test runs.

Copy link
Contributor

Choose a reason for hiding this comment

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

We looked into this and there isn't a good way to do it. In JdbcTableOperations, we do the same thing but check for just "constraint failed". I pasted some links for background in my other comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use the referenced code (with the same comment).

Preconditions.checkArgument(source != null, "Invalid source table: null");
Preconditions.checkArgument(destination != null, "Invalid destination table: null");
Preconditions.checkArgument(!source.equals(destination),
"Invalid rename table request: source must not be the same as destination");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be invalid or a no-op?

Copy link
Contributor Author

@kbendick kbendick May 4, 2022

Choose a reason for hiding this comment

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

I suppose it can be a no-op given we've been somewhat permissive in terms of what is allowed to come through the requests (so that implementors can have discretion as to how they respond to these situations).

I looked at the Glue catalog, and it doesn't specifically check for this case at all. Though I imagine their server fails at the end.

In terms of making it a no-op, should we just let the client send the request and allow the server to deal with it? Maybe log a warning? Seems somewhat difficult to adjust the control flow from the validate function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allowing it to go through and the server can deal with it.

This is in line with some of the other catalogs.

}

public static void renameTable(Catalog catalog, RenameTableRequest request) {
request.validate();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think other methods in CatalogHandlers run validate. I think that should be done before passing it in here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good point they don't. Since we're building them via the builder, it's not really necessary. Plus validate is called in the constructor anyway.

catalog.createNamespace(NS);
}

Assert.assertFalse("Source table should not exist before create", catalog.tableExists(TABLE));
Copy link
Contributor

Choose a reason for hiding this comment

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

create -> rename.


catalog.dropTable(TABLE);
catalog.dropTable(RENAMED_TABLE);
assertEmpty("Should not contain table after drop", catalog, NS);
Copy link
Contributor

Choose a reason for hiding this comment

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

These get cleaned up with the catalog, so no need to drop and assert.

Copy link
Contributor

@rdblue rdblue left a comment

Choose a reason for hiding this comment

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

@kbendick, this looks ready to go to me, except for the unfinished changes from the JDBC catalog issue. If you remove the comments in tests and update the contains check, I'll merge this.

@kbendick
Copy link
Contributor Author

kbendick commented May 3, 2022

@kbendick, this looks ready to go to me, except for the unfinished changes from the JDBC catalog issue. If you remove the comments in tests and update the contains check, I'll merge this.

Cool. I figured that the JDBC catalog issue was something there wasn't a clean way to resolve.

I will make the changes so we can merge this.

@kbendick kbendick force-pushed the rename-table-request branch from 3e21a33 to bfe4884 Compare May 3, 2022 17:23
String sourceTableUUID = ((HasTableOperations) catalog.loadTable(TABLE)).operations().current().uuid();
String destinationTableUUID = ((HasTableOperations) catalog.loadTable(RENAMED_TABLE)).operations().current().uuid();
Assert.assertNotEquals("Source and destination table should remain distinct after failed rename",
sourceTableUUID, destinationTableUUID);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good.

Copy link
Contributor

@rdblue rdblue left a comment

Choose a reason for hiding this comment

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

Looks great. I think there was a WIP comment accidentally left in, but overall looks good to merge.

@kbendick
Copy link
Contributor Author

kbendick commented May 4, 2022

Looks great. I think there was a WIP comment accidentally left in, but overall looks good to merge.

Just noticed it. Removed!

@kbendick kbendick force-pushed the rename-table-request branch from 13a0049 to aa7a5cc Compare May 6, 2022 17:20
@kbendick
Copy link
Contributor Author

kbendick commented May 6, 2022

This should be good to go when you get a chance. Rebased and removed unnecessary commits.

@rdblue rdblue merged commit 62b01fa into apache:master May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants