Skip to content
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

[#555] improvement(hive): Improve error message about altering an unknown table #556

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,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 @@ -627,7 +624,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 @@ -30,6 +30,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 @@ -495,6 +496,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