-
Notifications
You must be signed in to change notification settings - Fork 3k
Core: Add transaction catalog tests #4319
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
Conversation
9ed9979 to
3c43fe7
Compare
|
|
||
| @Override | ||
| public String toString() { | ||
| return Streams.stream(iterator()).collect(Collectors.joining("CharSequenceSet({", ", ", "})")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@szehon-ho, I addressed your comment.
nastra
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the new tests themselves LGTM, added just a few suggestions
|
|
||
| TableIdentifier ident = TableIdentifier.of("ns", "table"); | ||
|
|
||
| Assert.assertFalse("Table should not exist", catalog.tableExists(ident)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like the first 3 lines are repeated in a lot of tests. would it make sense to extract this into some method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only thing that could be extracted out would be the create table step. However, some of these tests only create a namespace and not the table. Others create a table in a different namespace, using the added TABLE constant.
We could make a class level constant out of ident, but it might confuse things with TABLE.
Is it possible to use that instead? I'm assuming there's a reason for the change in namespace.
| } | ||
|
|
||
| @Test | ||
| public void testUpdateTableSortOrder() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testUpdateTableSortOrder and testUpdateTableSortOrderServerSideRetry for example only differ in 1-2 lines, so I woder if we can improve the tests a bit and try and reduce code duplication (in a follow up PR)
| if (base != null) { | ||
| throw new CommitFailedException("Cannot commit: stale table metadata"); | ||
| } else { | ||
| throw new AlreadyExistsException("Table already exists: %s", tableName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didnt look deeply, but wondering why if caller passes base=null and current is not null , we can tell the table already exists? It seems it would be a new assumption to all the calling code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When base is null, that signals that the commit is trying to create the table and it should not exist. When current is not null, that signals that the table already exists. So in order to throw AlreadyExistsException from the create transaction, this needs to catch that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment to make this clear.
| if (base != null) { | ||
| throw new CommitFailedException("Cannot commit: stale table metadata"); | ||
| } else { | ||
| throw new AlreadyExistsException("Table already exists: %s", tableName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exception message reads a little funny to me, but I think in context it will make sense.
For clarification, what's happening here is that we entered some sort of create table transaction, and then at the end of the transaction, the table was created by some other process. Is that correct?
A comment might help make that more clear but I can see how the stack trace will make sense in context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment to make this clear.
|
|
||
| TableIdentifier ident = TableIdentifier.of("ns", "table"); | ||
|
|
||
| Assert.assertFalse("Table should not exist", catalog.tableExists(ident)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only thing that could be extracted out would be the create table step. However, some of these tests only create a namespace and not the table. Others create a table in a different namespace, using the added TABLE constant.
We could make a class level constant out of ident, but it might confuse things with TABLE.
Is it possible to use that instead? I'm assuming there's a reason for the change in namespace.
| Assert.assertTrue("Should be unpartitioned", table.spec().isUnpartitioned()); | ||
| Assert.assertTrue("Should be unsorted", table.sortOrder().isUnsorted()); | ||
| Assert.assertNotNull("Should have table properties", table.properties()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to drop the tables that are being created?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the catalog is re-initialized every time and data on disk is in a temporary folder.
|
Thanks for reviewing, @nastra, @szehon-ho, @kbendick, and @danielcweeks! |
This extends the recently added
CatalogTestsclass with more tests that cover transactions. There are also minor updates to other classes to make tests pass by standardizing error messages and exceptions.This implements
equals,hashCode, andtoStringinCharSequenceSetto make testing easier.This is in support of #4241.