|
44 | 44 | import org.junit.jupiter.api.io.TempDir;
|
45 | 45 |
|
46 | 46 | import java.lang.reflect.Field;
|
| 47 | +import java.nio.file.Path; |
| 48 | +import java.nio.file.Paths; |
47 | 49 | import java.util.ArrayList;
|
48 | 50 | import java.util.Arrays;
|
49 | 51 | import java.util.Collections;
|
|
59 | 61 | import static org.apache.paimon.hive.HiveCatalog.TABLE_TYPE_PROP;
|
60 | 62 | import static org.assertj.core.api.Assertions.assertThat;
|
61 | 63 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
| 64 | +import static org.junit.Assert.assertThrows; |
62 | 65 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
63 | 66 | import static org.junit.jupiter.api.Assertions.fail;
|
64 | 67 |
|
@@ -407,6 +410,37 @@ public void testListTables() throws Exception {
|
407 | 410 | catalog.dropDatabase(databaseName, true, true);
|
408 | 411 | }
|
409 | 412 |
|
| 413 | + @Test |
| 414 | + public void testDropTable() throws Exception { |
| 415 | + String databaseName = "drop_table_test_db"; |
| 416 | + String tableName = "drop_table_test_table"; |
| 417 | + catalog.dropDatabase(databaseName, true, true); |
| 418 | + catalog.createDatabase(databaseName, true); |
| 419 | + Identifier identifier = Identifier.create(databaseName, tableName); |
| 420 | + |
| 421 | + // test ignore if exists |
| 422 | + catalog.createTable( |
| 423 | + identifier, Schema.newBuilder().column("col", DataTypes.INT()).build(), true); |
| 424 | + Path path = Paths.get(catalog.warehouse(), databaseName.concat(".db"), tableName); |
| 425 | + catalog.fileIO().delete(new org.apache.paimon.fs.Path(path.toString()), true); |
| 426 | + List<String> tables = catalog.listTables(databaseName); |
| 427 | + assertEquals(1, tables.size()); |
| 428 | + catalog.dropTable(identifier, true); |
| 429 | + List<String> newTables = catalog.listTables(databaseName); |
| 430 | + assertEquals(0, newTables.size()); |
| 431 | + |
| 432 | + // test not ignore if exists |
| 433 | + catalog.createTable( |
| 434 | + identifier, Schema.newBuilder().column("col", DataTypes.INT()).build(), true); |
| 435 | + catalog.fileIO().delete(new org.apache.paimon.fs.Path(path.toString()), true); |
| 436 | + tables = catalog.listTables(databaseName); |
| 437 | + assertEquals(1, tables.size()); |
| 438 | + assertThrows( |
| 439 | + Catalog.TableNotExistException.class, () -> catalog.dropTable(identifier, false)); |
| 440 | + |
| 441 | + catalog.dropDatabase(databaseName, true, true); |
| 442 | + } |
| 443 | + |
410 | 444 | @Override
|
411 | 445 | protected boolean supportsView() {
|
412 | 446 | return true;
|
|
0 commit comments