Skip to content

Conversation

@rdblue
Copy link
Contributor

@rdblue rdblue commented Mar 13, 2022

This extends the recently added CatalogTests class 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, and toString in CharSequenceSet to make testing easier.

This is in support of #4241.

@github-actions github-actions bot added the API label Mar 13, 2022
@rdblue rdblue force-pushed the add-char-sequence-set-equals branch from 9ed9979 to 3c43fe7 Compare March 13, 2022 23:00

@Override
public String toString() {
return Streams.stream(iterator()).collect(Collectors.joining("CharSequenceSet({", ", ", "})"));
Copy link
Contributor Author

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.

@github-actions github-actions bot added the core label Mar 13, 2022
@rdblue rdblue changed the title API: Implement equals and hashCode in CharSequenceSet Core: Add transaction catalog tests Mar 13, 2022
@rdblue rdblue requested a review from danielcweeks March 13, 2022 23:06
@github-actions github-actions bot added the hive label Mar 13, 2022
Copy link
Contributor

@nastra nastra left a 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));
Copy link
Contributor

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?

Copy link
Contributor

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() {
Copy link
Contributor

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());
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@szehon-ho szehon-ho Mar 14, 2022

Choose a reason for hiding this comment

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

yea makes sense now, thanks. I guess it may be the same concern as @kbendick :) Maybe we should add this to @base argument javadoc in the TableOperations to clarify it, but itd be unrelated.

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 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());
Copy link
Contributor

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.

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 added a comment to make this clear.


TableIdentifier ident = TableIdentifier.of("ns", "table");

Assert.assertFalse("Table should not exist", catalog.tableExists(ident));
Copy link
Contributor

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());
}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@rdblue
Copy link
Contributor Author

rdblue commented Mar 15, 2022

Thanks for reviewing, @nastra, @szehon-ho, @kbendick, and @danielcweeks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants