|
38 | 38 | import org.apache.doris.nereids.trees.plans.commands.info.BranchOptions; |
39 | 39 | import org.apache.doris.nereids.trees.plans.commands.info.CreateOrReplaceBranchInfo; |
40 | 40 | import org.apache.doris.nereids.trees.plans.commands.info.CreateOrReplaceTagInfo; |
| 41 | +import org.apache.doris.nereids.trees.plans.commands.info.DropBranchInfo; |
| 42 | +import org.apache.doris.nereids.trees.plans.commands.info.DropTagInfo; |
41 | 43 | import org.apache.doris.nereids.trees.plans.commands.info.TagOptions; |
42 | 44 |
|
43 | 45 | import org.apache.iceberg.ManageSnapshots; |
44 | 46 | import org.apache.iceberg.PartitionSpec; |
45 | 47 | import org.apache.iceberg.Schema; |
46 | 48 | import org.apache.iceberg.Snapshot; |
| 49 | +import org.apache.iceberg.SnapshotRef; |
47 | 50 | import org.apache.iceberg.Table; |
48 | 51 | import org.apache.iceberg.catalog.Catalog; |
49 | 52 | import org.apache.iceberg.catalog.Namespace; |
@@ -401,7 +404,7 @@ public void createOrReplaceBranchImpl(String dbName, String tblName, CreateOrRep |
401 | 404 | } |
402 | 405 |
|
403 | 406 | @Override |
404 | | - public void afterCreateOrReplaceBranchOrTag(String dbName, String tblName) { |
| 407 | + public void afterOperateOnBranchOrTag(String dbName, String tblName) { |
405 | 408 | ExternalDatabase<?> db = dorisCatalog.getDbNullable(dbName); |
406 | 409 | if (db != null) { |
407 | 410 | ExternalTable tbl = db.getTableNullable(tblName); |
@@ -455,6 +458,44 @@ public void createOrReplaceTagImpl(String dbName, String tblName, CreateOrReplac |
455 | 458 | } |
456 | 459 | } |
457 | 460 |
|
| 461 | + @Override |
| 462 | + public void dropTagImpl(String dbName, String tblName, DropTagInfo tagInfo) throws UserException { |
| 463 | + String tagName = tagInfo.getTagName(); |
| 464 | + boolean ifExists = tagInfo.getIfExists(); |
| 465 | + Table icebergTable = IcebergUtils.getIcebergTable(dorisCatalog, dbName, tblName); |
| 466 | + SnapshotRef snapshotRef = icebergTable.refs().get(tagName); |
| 467 | + |
| 468 | + if (snapshotRef != null || !ifExists) { |
| 469 | + ManageSnapshots manageSnapshots = icebergTable.manageSnapshots(); |
| 470 | + try { |
| 471 | + preExecutionAuthenticator.execute(() -> manageSnapshots.removeTag(tagName).commit()); |
| 472 | + } catch (Exception e) { |
| 473 | + throw new RuntimeException( |
| 474 | + "Failed to drop tag: " + tagName + " in table: " + icebergTable.name() |
| 475 | + + ", error message is: " + e.getMessage(), e); |
| 476 | + } |
| 477 | + } |
| 478 | + } |
| 479 | + |
| 480 | + @Override |
| 481 | + public void dropBranchImpl(String dbName, String tblName, DropBranchInfo branchInfo) throws UserException { |
| 482 | + String branchName = branchInfo.getBranchName(); |
| 483 | + boolean ifExists = branchInfo.getIfExists(); |
| 484 | + Table icebergTable = IcebergUtils.getIcebergTable(dorisCatalog, dbName, tblName); |
| 485 | + SnapshotRef snapshotRef = icebergTable.refs().get(branchName); |
| 486 | + |
| 487 | + if (snapshotRef != null || !ifExists) { |
| 488 | + ManageSnapshots manageSnapshots = icebergTable.manageSnapshots(); |
| 489 | + try { |
| 490 | + preExecutionAuthenticator.execute(() -> manageSnapshots.removeBranch(branchName).commit()); |
| 491 | + } catch (Exception e) { |
| 492 | + throw new RuntimeException( |
| 493 | + "Failed to drop branch: " + branchName + " in table: " + icebergTable.name() |
| 494 | + + ", error message is: " + e.getMessage(), e); |
| 495 | + } |
| 496 | + } |
| 497 | + } |
| 498 | + |
458 | 499 | public PreExecutionAuthenticator getPreExecutionAuthenticator() { |
459 | 500 | return preExecutionAuthenticator; |
460 | 501 | } |
|
0 commit comments