Skip to content

Commit

Permalink
Hive, JDBC: Add null check before matching the error message
Browse files Browse the repository at this point in the history
  • Loading branch information
nk1506 committed Apr 3, 2024
1 parent a7f87c7 commit f9f55f8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void doCommit(TableMetadata base, TableMetadata metadata) {
throw new UncheckedSQLException(e, "Database warning");
} catch (SQLException e) {
// SQLite doesn't set SQLState or throw SQLIntegrityConstraintViolationException
if (e.getMessage().contains("constraint failed")) {
if (e.getMessage() != null && e.getMessage().contains("constraint failed")) {
throw new AlreadyExistsException("Table already exists: %s", tableIdentifier);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected void doCommit(ViewMetadata base, ViewMetadata metadata) {
throw new UncheckedSQLException(e, "Database warning");
} catch (SQLException e) {
// SQLite doesn't set SQLState or throw SQLIntegrityConstraintViolationException
if (e.getMessage().contains("constraint failed")) {
if (e.getMessage() != null && e.getMessage().contains("constraint failed")) {
throw new AlreadyExistsException("View already exists: %s", viewIdentifier);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,19 @@ public HiveClientPool(int poolSize, Configuration conf) {
@Override
protected IMetaStoreClient newClient() {
try {
try {
return GET_CLIENT.invoke(
hiveConf, (HiveMetaHookLoader) tbl -> null, HiveMetaStoreClient.class.getName());
} catch (RuntimeException e) {
// any MetaException would be wrapped into RuntimeException during reflection, so let's
// double-check type here
if (e.getCause() instanceof MetaException) {
throw (MetaException) e.getCause();
}
throw e;
}
} catch (MetaException e) {
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")) {
return GET_CLIENT.invoke(
hiveConf, (HiveMetaHookLoader) tbl -> null, HiveMetaStoreClient.class.getName());
} catch (RuntimeException e) {
if (e.getMessage() != null
&& e.getMessage().contains("Another instance of Derby may have already booted")) {
throw new RuntimeMetaException(
t,
e,
"Failed to start an embedded metastore because embedded "
+ "Derby supports only one client at a time. To fix this, use a metastore that supports "
+ "multiple clients.");
}

throw new RuntimeMetaException(t, "Failed to connect to Hive Metastore");
throw new RuntimeMetaException(e, "Failed to connect to Hive Metastore");
}
}

Expand Down

0 comments on commit f9f55f8

Please sign in to comment.