Skip to content

Commit 0c0eb7e

Browse files
authored
[Improve][Jdbc] Jdbc truncate table should check table not database (#7654)
1 parent 6765312 commit 0c0eb7e

File tree

2 files changed

+16
-2
lines changed
  • seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog
  • seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-common/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc

2 files changed

+16
-2
lines changed

seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,11 @@ protected void closeDatabaseConnection(String databaseName) {
527527
public void truncateTable(TablePath tablePath, boolean ignoreIfNotExists)
528528
throws TableNotExistException, CatalogException {
529529
checkNotNull(tablePath, "Table path cannot be null");
530-
if (!databaseExists(tablePath.getDatabaseName())) {
530+
if (!tableExists(tablePath)) {
531531
if (ignoreIfNotExists) {
532532
return;
533533
}
534-
throw new DatabaseNotExistException(catalogName, tablePath.getDatabaseName());
534+
throw new TableNotExistException(catalogName, tablePath);
535535
}
536536
truncateTableInternal(tablePath);
537537
}

seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-common/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/AbstractJdbcIT.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.seatunnel.api.table.catalog.PrimaryKey;
2727
import org.apache.seatunnel.api.table.catalog.TablePath;
2828
import org.apache.seatunnel.api.table.catalog.TableSchema;
29+
import org.apache.seatunnel.api.table.catalog.exception.TableNotExistException;
2930
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
3031
import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
3132
import org.apache.seatunnel.common.utils.ExceptionUtils;
@@ -462,6 +463,19 @@ public void testCatalog() {
462463
catalog.dropDatabase(targetTablePath, false);
463464
Assertions.assertFalse(catalog.databaseExists(targetTablePath.getDatabaseName()));
464465
}
466+
467+
TableNotExistException exception =
468+
Assertions.assertThrows(
469+
TableNotExistException.class,
470+
() ->
471+
catalog.truncateTable(
472+
TablePath.of("not_exist", "not_exist", "not_exist"),
473+
false));
474+
Assertions.assertEquals(
475+
String.format(
476+
"ErrorCode:[API-05], ErrorDescription:[Table not existed] - Table not_exist.not_exist.not_exist does not exist in Catalog %s.",
477+
catalog.name()),
478+
exception.getMessage());
465479
}
466480

467481
@Test

0 commit comments

Comments
 (0)