Skip to content

Commit

Permalink
[#555] improvement(hive): Improve error message about altering an unk…
Browse files Browse the repository at this point in the history
…nown table (#556)

### What changes were proposed in this pull request?

Change the exception class from `RuntimeException` to
`NoSuchTableException` when altering an unknown table.

### Why are the changes needed?

Improving error messages to be more accurate and readable.

Fix: #555 

### Does this PR introduce _any_ user-facing change?

NO

### How was this patch tested?

Add test int IT.
  • Loading branch information
yuqi1129 authored Oct 19, 2023
1 parent bdb2ab0 commit fe2ec48
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,6 @@ public Table alterTable(NameIdentifier tableIdent, TableChange... changes)
LOG.info("Altered Hive table {} in Hive Metastore", tableIdent.name());
return HiveTable.fromHiveTable(alteredHiveTable);

} catch (NoSuchObjectException e) {
throw new NoSuchTableException(
String.format("Hive table does not exist: %s in Hive Metastore", tableIdent.name()), e);
} catch (TException | InterruptedException e) {
if (e.getMessage().contains("types incompatible with the existing columns")) {
throw new IllegalArgumentException(
Expand All @@ -677,7 +674,7 @@ public Table alterTable(NameIdentifier tableIdent, TableChange... changes)
}
throw new RuntimeException(
"Failed to alter Hive table " + tableIdent.name() + " in Hive metastore", e);
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException | NoSuchTableException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@ private <R, E1 extends Throwable, E2 extends Throwable> R doWithCatalog(
} else if (ex2.isInstance(throwable)) {
throw ex2.cast(throwable);
}
if (RuntimeException.class.isAssignableFrom(throwable.getClass())) {
throw (RuntimeException) throwable;
}

throw new RuntimeException(throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.datastrato.gravitino.catalog.hive.HiveTablePropertiesMetadata;
import com.datastrato.gravitino.client.GravitinoMetaLake;
import com.datastrato.gravitino.dto.rel.ColumnDTO;
import com.datastrato.gravitino.exceptions.NoSuchTableException;
import com.datastrato.gravitino.integration.test.util.AbstractIT;
import com.datastrato.gravitino.integration.test.util.GravitinoITUtils;
import com.datastrato.gravitino.rel.Distribution;
Expand Down Expand Up @@ -580,6 +581,16 @@ private void assertTableEquals(
Assertions.assertEquals(partitionKeys, hivePartitionKeys);
}

@Test
void testAlterUnknownTable() {
NameIdentifier identifier = NameIdentifier.of(metalakeName, catalogName, schemaName, "unknown");
Assertions.assertThrows(
NoSuchTableException.class,
() -> {
catalog.asTableCatalog().alterTable(identifier, TableChange.updateComment("new_comment"));
});
}

@Test
public void testAlterHiveTable() throws TException, InterruptedException {
ColumnDTO[] columns = createColumns();
Expand Down

0 comments on commit fe2ec48

Please sign in to comment.