|
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; |
@@ -449,7 +452,7 @@ public void createOrReplaceBranchImpl(String dbName, String tblName, CreateOrRep |
449 | 452 | } |
450 | 453 |
|
451 | 454 | @Override |
452 | | - public void afterCreateOrReplaceBranchOrTag(String dbName, String tblName) { |
| 455 | + public void afterOperateOnBranchOrTag(String dbName, String tblName) { |
453 | 456 | ExternalDatabase<?> db = dorisCatalog.getDbNullable(dbName); |
454 | 457 | if (db != null) { |
455 | 458 | ExternalTable tbl = db.getTableNullable(tblName); |
@@ -503,6 +506,44 @@ public void createOrReplaceTagImpl(String dbName, String tblName, CreateOrReplac |
503 | 506 | } |
504 | 507 | } |
505 | 508 |
|
| 509 | + @Override |
| 510 | + public void dropTagImpl(String dbName, String tblName, DropTagInfo tagInfo) throws UserException { |
| 511 | + String tagName = tagInfo.getTagName(); |
| 512 | + boolean ifExists = tagInfo.getIfExists(); |
| 513 | + Table icebergTable = IcebergUtils.getIcebergTable(dorisCatalog, dbName, tblName); |
| 514 | + SnapshotRef snapshotRef = icebergTable.refs().get(tagName); |
| 515 | + |
| 516 | + if (snapshotRef != null || !ifExists) { |
| 517 | + ManageSnapshots manageSnapshots = icebergTable.manageSnapshots(); |
| 518 | + try { |
| 519 | + preExecutionAuthenticator.execute(() -> manageSnapshots.removeTag(tagName).commit()); |
| 520 | + } catch (Exception e) { |
| 521 | + throw new RuntimeException( |
| 522 | + "Failed to drop tag: " + tagName + " in table: " + icebergTable.name() |
| 523 | + + ", error message is: " + e.getMessage(), e); |
| 524 | + } |
| 525 | + } |
| 526 | + } |
| 527 | + |
| 528 | + @Override |
| 529 | + public void dropBranchImpl(String dbName, String tblName, DropBranchInfo branchInfo) throws UserException { |
| 530 | + String branchName = branchInfo.getBranchName(); |
| 531 | + boolean ifExists = branchInfo.getIfExists(); |
| 532 | + Table icebergTable = IcebergUtils.getIcebergTable(dorisCatalog, dbName, tblName); |
| 533 | + SnapshotRef snapshotRef = icebergTable.refs().get(branchName); |
| 534 | + |
| 535 | + if (snapshotRef != null || !ifExists) { |
| 536 | + ManageSnapshots manageSnapshots = icebergTable.manageSnapshots(); |
| 537 | + try { |
| 538 | + preExecutionAuthenticator.execute(() -> manageSnapshots.removeBranch(branchName).commit()); |
| 539 | + } catch (Exception e) { |
| 540 | + throw new RuntimeException( |
| 541 | + "Failed to drop branch: " + branchName + " in table: " + icebergTable.name() |
| 542 | + + ", error message is: " + e.getMessage(), e); |
| 543 | + } |
| 544 | + } |
| 545 | + } |
| 546 | + |
506 | 547 | public PreExecutionAuthenticator getPreExecutionAuthenticator() { |
507 | 548 | return preExecutionAuthenticator; |
508 | 549 | } |
|
0 commit comments