Skip to content

Commit

Permalink
[Improve][Jdbc] Jdbc truncate table should check table not database (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Hisoka-X authored Sep 19, 2024
1 parent 6765312 commit 0c0eb7e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,11 @@ protected void closeDatabaseConnection(String databaseName) {
public void truncateTable(TablePath tablePath, boolean ignoreIfNotExists)
throws TableNotExistException, CatalogException {
checkNotNull(tablePath, "Table path cannot be null");
if (!databaseExists(tablePath.getDatabaseName())) {
if (!tableExists(tablePath)) {
if (ignoreIfNotExists) {
return;
}
throw new DatabaseNotExistException(catalogName, tablePath.getDatabaseName());
throw new TableNotExistException(catalogName, tablePath);
}
truncateTableInternal(tablePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.seatunnel.api.table.catalog.PrimaryKey;
import org.apache.seatunnel.api.table.catalog.TablePath;
import org.apache.seatunnel.api.table.catalog.TableSchema;
import org.apache.seatunnel.api.table.catalog.exception.TableNotExistException;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
import org.apache.seatunnel.common.utils.ExceptionUtils;
Expand Down Expand Up @@ -462,6 +463,19 @@ public void testCatalog() {
catalog.dropDatabase(targetTablePath, false);
Assertions.assertFalse(catalog.databaseExists(targetTablePath.getDatabaseName()));
}

TableNotExistException exception =
Assertions.assertThrows(
TableNotExistException.class,
() ->
catalog.truncateTable(
TablePath.of("not_exist", "not_exist", "not_exist"),
false));
Assertions.assertEquals(
String.format(
"ErrorCode:[API-05], ErrorDescription:[Table not existed] - Table not_exist.not_exist.not_exist does not exist in Catalog %s.",
catalog.name()),
exception.getMessage());
}

@Test
Expand Down

0 comments on commit 0c0eb7e

Please sign in to comment.