Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxiaojian committed May 18, 2024
2 parents 9052136 + 750797f commit 3593d91
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import static org.apache.paimon.catalog.Identifier.UNKNOWN_DATABASE;
import static org.apache.paimon.utils.BranchManager.DEFAULT_MAIN_BRANCH;
import static org.apache.paimon.utils.BranchManager.getBranchPath;
import static org.apache.paimon.utils.BranchManager.isMainBranch;
import static org.apache.paimon.utils.FileUtils.listVersionedFiles;
import static org.apache.paimon.utils.Preconditions.checkState;

Expand Down Expand Up @@ -499,14 +500,14 @@ public static TableSchema fromPath(FileIO fileIO, Path path) {
}

public Path schemaDirectory() {
return branch.equals(DEFAULT_MAIN_BRANCH)
return isMainBranch(branch)
? new Path(tableRoot + "/schema")
: new Path(getBranchPath(tableRoot, branch) + "/schema");
}

@VisibleForTesting
public Path toSchemaPath(long schemaId) {
return branch.equals(DEFAULT_MAIN_BRANCH)
return isMainBranch(branch)
? new Path(tableRoot + "/schema/" + SCHEMA_PREFIX + schemaId)
: new Path(
getBranchPath(tableRoot, branch) + "/schema/" + SCHEMA_PREFIX + schemaId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public Path branchDirectory() {
return new Path(tablePath + "/branch");
}

public static boolean isMainBranch(String branch) {
return branch.equals(DEFAULT_MAIN_BRANCH);
}

/** Return the path string of a branch. */
public static String getBranchPath(Path tablePath, String branchName) {
return tablePath.toString() + "/branch/" + BRANCH_PREFIX + branchName;
Expand All @@ -87,7 +91,7 @@ public Path branchPath(String branchName) {
/** Create empty branch. */
public void createBranch(String branchName) {
checkArgument(
!branchName.equals(DEFAULT_MAIN_BRANCH),
!isMainBranch(branchName),
String.format(
"Branch name '%s' is the default branch and cannot be used.",
DEFAULT_MAIN_BRANCH));
Expand All @@ -114,7 +118,7 @@ branchName, getBranchPath(tablePath, branchName)),

public void createBranch(String branchName, long snapshotId) {
checkArgument(
!branchName.equals(DEFAULT_MAIN_BRANCH),
!isMainBranch(branchName),
String.format(
"Branch name '%s' is the default branch and cannot be used.",
DEFAULT_MAIN_BRANCH));
Expand Down Expand Up @@ -146,7 +150,7 @@ branchName, getBranchPath(tablePath, branchName)),

public void createBranch(String branchName, String tagName) {
checkArgument(
!branchName.equals(DEFAULT_MAIN_BRANCH),
!isMainBranch(branchName),
String.format(
"Branch name '%s' is the default branch and cannot be used.",
DEFAULT_MAIN_BRANCH));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

import static org.apache.paimon.utils.BranchManager.DEFAULT_MAIN_BRANCH;
import static org.apache.paimon.utils.BranchManager.getBranchPath;
import static org.apache.paimon.utils.BranchManager.isMainBranch;
import static org.apache.paimon.utils.FileUtils.listVersionedFiles;

/** Manager for {@link Snapshot}, providing utility methods related to paths and snapshot hints. */
Expand Down Expand Up @@ -89,13 +90,13 @@ public Path tablePath() {
}

public Path changelogDirectory() {
return branch.equals(DEFAULT_MAIN_BRANCH)
return isMainBranch(branch)
? new Path(tablePath + "/changelog")
: new Path(getBranchPath(tablePath, branch) + "/changelog");
}

public Path longLivedChangelogPath(long snapshotId) {
return branch.equals(DEFAULT_MAIN_BRANCH)
return isMainBranch(branch)
? new Path(tablePath + "/changelog/" + CHANGELOG_PREFIX + snapshotId)
: new Path(
getBranchPath(tablePath, branch)
Expand All @@ -105,7 +106,7 @@ public Path longLivedChangelogPath(long snapshotId) {
}

public Path snapshotPath(long snapshotId) {
return branch.equals(DEFAULT_MAIN_BRANCH)
return isMainBranch(branch)
? new Path(tablePath + "/snapshot/" + SNAPSHOT_PREFIX + snapshotId)
: new Path(
getBranchPath(tablePath, branch)
Expand All @@ -115,7 +116,7 @@ public Path snapshotPath(long snapshotId) {
}

public Path snapshotDirectory() {
return branch.equals(DEFAULT_MAIN_BRANCH)
return isMainBranch(branch)
? new Path(tablePath + "/snapshot")
: new Path(getBranchPath(tablePath, branch) + "/snapshot");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

import static org.apache.paimon.utils.BranchManager.DEFAULT_MAIN_BRANCH;
import static org.apache.paimon.utils.BranchManager.getBranchPath;
import static org.apache.paimon.utils.BranchManager.isMainBranch;
import static org.apache.paimon.utils.FileUtils.listVersionedFileStatus;
import static org.apache.paimon.utils.Preconditions.checkArgument;

Expand Down Expand Up @@ -78,14 +79,14 @@ public TagManager copyWithBranch(String branchName) {

/** Return the root Directory of tags. */
public Path tagDirectory() {
return branch.equals(DEFAULT_MAIN_BRANCH)
return isMainBranch(branch)
? new Path(tablePath + "/tag")
: new Path(getBranchPath(tablePath, branch) + "/tag");
}

/** Return the path of a tag in branch. */
public Path tagPath(String tagName) {
return branch.equals(DEFAULT_MAIN_BRANCH)
return isMainBranch(branch)
? new Path(tablePath + "/tag/" + TAG_PREFIX + tagName)
: new Path(getBranchPath(tablePath, branch) + "/tag/" + TAG_PREFIX + tagName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void testReadWriteBranch() throws Exception {
paimonTable("T").createTag("tag1", 1);
// create branch
paimonTable("T").createBranch("branch1", "tag1");

// alter table branch
sql("ALTER TABLE T SET ('branch'='branch1')");
sql("ALTER TABLE T ADD (c1 INT, c2 STRING)");
// insert data to branch
Expand Down

0 comments on commit 3593d91

Please sign in to comment.