-
Notifications
You must be signed in to change notification settings - Fork 3k
Hive, JDBC: Add null check before matching the error message #10082
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
| } catch (RuntimeException e) { | ||
| // any MetaException would be wrapped into RuntimeException during reflection, so let's | ||
| // double-check type here | ||
| if (e.getCause() instanceof MetaException) { |
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.
@nk1506 why is this being removed?
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.
Fixed it.
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.
Let me lookout/add some tests which can catch these errors.
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.
@nk1506 this isn't fixed. The logic in the try-catch blocks changed. The only thing that should be changing is adding a null check before calling t.getMessage()
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 other try-catch block looks redundant . We were wrapping into MetaException and throwing and again wrapping into RuntimeMetaException .
Should I revert and add only null check ?
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.
yes, please revert. The scope within the PR should reflect what's being proposed in the commit msg
| throw new RuntimeMetaException(e, "Failed to connect to Hive Metastore"); | ||
| } catch (Throwable t) { | ||
| if (t.getMessage().contains("Another instance of Derby may have already booted")) { | ||
| if (t.getMessage() != null |
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.
Having trouble to add tests for this. Since GET_CLIENT is static.
@nastra Any pointers will help.
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.
try to look at the existing tests in TestHiveClientPool and see how things could be mocked so that we get the right exception
| try (MockedStatic<JdbcUtil> mockedStatic = Mockito.mockStatic(JdbcUtil.class)) { | ||
| mockedStatic | ||
| .when(() -> JdbcUtil.loadTable(any(), any(), any(), any())) | ||
| .thenThrow(new SQLException("constraint failed")); |
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.
Null message we are checking at other testCommitExceptionWithoutMessage.
| } | ||
|
|
||
| @Test | ||
| public void testCommitExceptionWithoutMessage() { |
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.
can be simplified to
@Test
public void testCommitExceptionWithoutMessage() {
TableIdentifier tableIdent = TableIdentifier.of("db", "tbl");
BaseTable table = (BaseTable) catalog.buildTable(tableIdent, SCHEMA).create();
TableOperations ops = table.operations();
TableMetadata metadataV1 = ops.current();
table.updateSchema().addColumn("n", Types.IntegerType.get()).commit();
ops.refresh();
try (MockedStatic<JdbcUtil> mockedStatic = Mockito.mockStatic(JdbcUtil.class)) {
mockedStatic
.when(() -> JdbcUtil.loadTable(any(), any(), any(), any()))
.thenThrow(new SQLException());
assertThatThrownBy(() -> ops.commit(ops.current(), metadataV1))
.isInstanceOf(UncheckedSQLException.class)
.hasMessageStartingWith("Unknown failure");
}
}
please also update the other tests accordingly. The spying on ops isn't necessary here, because you're throwing the exception when the table/view is being loaded (which is different from #10069)
| public void testCommitExceptionWithoutMessage() { | ||
| TableIdentifier tableIdent = TableIdentifier.of("db", "ns1", "ns2", "tbl"); | ||
| BaseTable table = (BaseTable) catalog.buildTable(tableIdent, SCHEMA).create(); | ||
| JdbcTableOperations ops = (JdbcTableOperations) table.operations(); |
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 need for the casting here. See the simplified test version in my previous comment
| @Test | ||
| public void testExceptionMessages() { | ||
| // Test Wrapped MetaException with a message | ||
| try (MockedStatic<MetaStoreUtils> mockedStatic = Mockito.mockStatic(MetaStoreUtils.class)) { |
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.
Couldn't find a way to mock calling method
return GET_CLIENT.invoke(
hiveConf, (HiveMetaHookLoader) tbl -> null, HiveMetaStoreClient.class.getName());
and throw Exception. Had to trace and mock the class which is throwing error.
|
|
||
| @Test | ||
| public void testExceptionMessages() { | ||
| // Test Wrapped MetaException with a message |
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 don't think those comments are helpful. I would just remove all of those
No description provided.