Skip to content

Commit 1a95f7c

Browse files
committed
fix
1 parent 71a5971 commit 1a95f7c

File tree

6 files changed

+51
-46
lines changed

6 files changed

+51
-46
lines changed

paimon-core/src/main/java/org/apache/paimon/catalog/AbstractCatalog.java

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.apache.paimon.table.object.ObjectTable;
4040
import org.apache.paimon.table.system.SystemTableLoader;
4141
import org.apache.paimon.types.RowType;
42-
import org.apache.paimon.utils.FileSystemBranchManager;
4342

4443
import org.slf4j.Logger;
4544
import org.slf4j.LoggerFactory;
@@ -67,7 +66,7 @@
6766
import static org.apache.paimon.catalog.CatalogUtils.validateAutoCreateClose;
6867
import static org.apache.paimon.options.CatalogOptions.LOCK_ENABLED;
6968
import static org.apache.paimon.options.CatalogOptions.LOCK_TYPE;
70-
import static org.apache.paimon.utils.FileSystemBranchManager.DEFAULT_MAIN_BRANCH;
69+
import static org.apache.paimon.utils.BranchManager.DEFAULT_MAIN_BRANCH;
7170
import static org.apache.paimon.utils.Preconditions.checkArgument;
7271

7372
/** Common implementation of {@link Catalog}. */
@@ -441,53 +440,25 @@ public Table getTable(Identifier identifier) throws TableNotExistException {
441440
lockContext().orElse(null));
442441
}
443442

444-
private FileSystemBranchManager fileSystemBranchManager(Identifier identifier)
445-
throws TableNotExistException {
446-
FileStoreTable table = (FileStoreTable) getTable(identifier);
447-
return new FileSystemBranchManager(
448-
table.fileIO(),
449-
table.location(),
450-
table.snapshotManager(),
451-
table.tagManager(),
452-
table.schemaManager());
453-
}
454-
455443
@Override
456444
public void createBranch(Identifier identifier, String branch, @Nullable String fromTag)
457445
throws TableNotExistException, BranchAlreadyExistException, TagNotExistException {
458-
FileSystemBranchManager branchManager = fileSystemBranchManager(identifier);
459-
if (fromTag == null) {
460-
branchManager.createBranch(branch);
461-
} else {
462-
branchManager.createBranch(branch, fromTag);
463-
}
446+
throw new UnsupportedOperationException();
464447
}
465448

466449
@Override
467450
public void dropBranch(Identifier identifier, String branch) throws BranchNotExistException {
468-
FileSystemBranchManager branchManager;
469-
try {
470-
branchManager = fileSystemBranchManager(identifier);
471-
} catch (TableNotExistException e) {
472-
throw new BranchNotExistException(identifier, branch);
473-
}
474-
branchManager.dropBranch(branch);
451+
throw new UnsupportedOperationException();
475452
}
476453

477454
@Override
478455
public void fastForward(Identifier identifier, String branch) throws BranchNotExistException {
479-
FileSystemBranchManager branchManager;
480-
try {
481-
branchManager = fileSystemBranchManager(identifier);
482-
} catch (TableNotExistException e) {
483-
throw new BranchNotExistException(identifier, branch);
484-
}
485-
branchManager.fastForward(branch);
456+
throw new UnsupportedOperationException();
486457
}
487458

488459
@Override
489460
public List<String> listBranches(Identifier identifier) throws TableNotExistException {
490-
return fileSystemBranchManager(identifier).branches();
461+
throw new UnsupportedOperationException();
491462
}
492463

493464
@Override

paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,11 +688,14 @@ public TagManager tagManager() {
688688

689689
@Override
690690
public BranchManager branchManager() {
691+
FileSystemBranchManager branchManager =
692+
new FileSystemBranchManager(
693+
fileIO, path, snapshotManager(), tagManager(), schemaManager());
691694
if (catalogEnvironment.catalogLoader() != null) {
692-
return new CatalogBranchManager(catalogEnvironment.catalogLoader(), identifier());
695+
return new CatalogBranchManager(
696+
catalogEnvironment.catalogLoader(), identifier(), branchManager);
693697
}
694-
return new FileSystemBranchManager(
695-
fileIO, path, snapshotManager(), tagManager(), schemaManager());
698+
return branchManager;
696699
}
697700

698701
@Override

paimon-core/src/main/java/org/apache/paimon/utils/CatalogBranchManager.java

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ public class CatalogBranchManager implements BranchManager {
3131

3232
private final CatalogLoader catalogLoader;
3333
private final Identifier identifier;
34+
private final FileSystemBranchManager branchManager;
3435

35-
public CatalogBranchManager(CatalogLoader catalogLoader, Identifier identifier) {
36+
public CatalogBranchManager(
37+
CatalogLoader catalogLoader,
38+
Identifier identifier,
39+
FileSystemBranchManager branchManager) {
3640
this.catalogLoader = catalogLoader;
3741
this.identifier = identifier;
42+
this.branchManager = branchManager;
3843
}
3944

4045
private void executePost(ThrowingConsumer<Catalog, Exception> func) {
@@ -48,33 +53,59 @@ private void executePost(ThrowingConsumer<Catalog, Exception> func) {
4853
private <T> T executeGet(FunctionWithException<Catalog, T, Exception> func) {
4954
try (Catalog catalog = catalogLoader.load()) {
5055
return func.apply(catalog);
56+
} catch (RuntimeException e) {
57+
throw e;
5158
} catch (Exception e) {
5259
throw new RuntimeException(e);
5360
}
5461
}
5562

5663
@Override
5764
public void createBranch(String branchName) {
58-
executePost(catalog -> catalog.createBranch(identifier, branchName, null));
65+
try {
66+
executePost(catalog -> catalog.createBranch(identifier, branchName, null));
67+
} catch (UnsupportedOperationException e) {
68+
branchManager.dropBranch(branchName);
69+
}
5970
}
6071

6172
@Override
6273
public void createBranch(String branchName, @Nullable String tagName) {
63-
executePost(catalog -> catalog.createBranch(identifier, branchName, tagName));
74+
try {
75+
executePost(catalog -> catalog.createBranch(identifier, branchName, tagName));
76+
} catch (UnsupportedOperationException e) {
77+
if (tagName == null) {
78+
branchManager.createBranch(branchName);
79+
} else {
80+
branchManager.createBranch(branchName, tagName);
81+
}
82+
}
6483
}
6584

6685
@Override
6786
public void dropBranch(String branchName) {
68-
executePost(catalog -> catalog.dropBranch(identifier, branchName));
87+
try {
88+
executePost(catalog -> catalog.dropBranch(identifier, branchName));
89+
} catch (UnsupportedOperationException e) {
90+
branchManager.dropBranch(branchName);
91+
}
6992
}
7093

7194
@Override
7295
public void fastForward(String branchName) {
73-
executePost(catalog -> catalog.fastForward(identifier, branchName));
96+
try {
97+
executePost(catalog -> catalog.fastForward(identifier, branchName));
98+
} catch (UnsupportedOperationException e) {
99+
branchManager.fastForward(branchName);
100+
}
74101
}
75102

76103
@Override
77104
public List<String> branches() {
78-
return executeGet(catalog -> catalog.listBranches(identifier));
105+
try {
106+
return executeGet(catalog -> catalog.listBranches(identifier));
107+
} catch (UnsupportedOperationException e) {
108+
return branchManager.branches();
109+
}
79110
}
80111
}

paimon-core/src/test/java/org/apache/paimon/SnapshotTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import org.junit.jupiter.api.Test;
2727

28-
import static org.apache.paimon.utils.FileSystemBranchManager.DEFAULT_MAIN_BRANCH;
28+
import static org.apache.paimon.utils.BranchManager.DEFAULT_MAIN_BRANCH;
2929
import static org.assertj.core.api.Assertions.assertThat;
3030

3131
/** Test for snapshots. */

paimon-core/src/test/java/org/apache/paimon/utils/SnapshotManagerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
import static org.apache.paimon.SnapshotTest.newChangelogManager;
4646
import static org.apache.paimon.SnapshotTest.newSnapshotManager;
47-
import static org.apache.paimon.utils.FileSystemBranchManager.DEFAULT_MAIN_BRANCH;
47+
import static org.apache.paimon.utils.BranchManager.DEFAULT_MAIN_BRANCH;
4848
import static org.assertj.core.api.Assertions.assertThat;
4949
import static org.assertj.core.api.Assertions.fail;
5050
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
import static org.apache.paimon.options.CatalogOptions.TABLE_TYPE;
124124
import static org.apache.paimon.options.OptionsUtils.convertToPropertiesPrefixKey;
125125
import static org.apache.paimon.table.FormatTableOptions.FIELD_DELIMITER;
126-
import static org.apache.paimon.utils.FileSystemBranchManager.DEFAULT_MAIN_BRANCH;
126+
import static org.apache.paimon.utils.BranchManager.DEFAULT_MAIN_BRANCH;
127127
import static org.apache.paimon.utils.HadoopUtils.addHadoopConfIfFound;
128128
import static org.apache.paimon.utils.Preconditions.checkArgument;
129129
import static org.apache.paimon.utils.StringUtils.isNullOrWhitespaceOnly;

0 commit comments

Comments
 (0)