Skip to content

Commit

Permalink
Implement merge/replace branch in BranchManager #2153
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxiaojian committed Mar 1, 2024
1 parent 6a2c24d commit ced1e05
Show file tree
Hide file tree
Showing 12 changed files with 706 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,28 @@ public Optional<TableSchema> latest(String branchName) {
}
}

/** List all schema with branch. */
public List<TableSchema> listAllWithBranch(String branchName) {
return listAllIdsWithBranch(branchName).stream()
.map(this::schema)
.collect(Collectors.toList());
}

/** List all schema. */
public List<TableSchema> listAll() {
return listAllIds().stream().map(this::schema).collect(Collectors.toList());
}

/** List all schema IDs with branch. */
public List<Long> listAllIdsWithBranch(String branchName) {
try {
return listVersionedFiles(fileIO, branchSchemaDirectory(branchName), SCHEMA_PREFIX)
.collect(Collectors.toList());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

/** List all schema IDs. */
public List<Long> listAllIds() {
try {
Expand Down Expand Up @@ -482,22 +499,25 @@ public static TableSchema fromPath(FileIO fileIO, Path path) {
}
}

private Path schemaDirectory() {
return new Path(tableRoot + "/schema");
public Path schemaDirectory() {
return branchSchemaDirectory(DEFAULT_MAIN_BRANCH);
}

@VisibleForTesting
public Path toSchemaPath(long id) {
return new Path(tableRoot + "/schema/" + SCHEMA_PREFIX + id);
return branchSchemaPath(DEFAULT_MAIN_BRANCH, id);
}

public Path branchSchemaDirectory(String branchName) {
return new Path(getBranchPath(tableRoot, branchName) + "/schema");
return new Path(getBranchPath(fileIO, tableRoot, branchName) + "/schema");
}

public Path branchSchemaPath(String branchName, long schemaId) {
return new Path(
getBranchPath(tableRoot, branchName) + "/schema/" + SCHEMA_PREFIX + schemaId);
getBranchPath(fileIO, tableRoot, branchName)
+ "/schema/"
+ SCHEMA_PREFIX
+ schemaId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,16 @@ public void deleteBranch(String branchName) {
branchManager().deleteBranch(branchName);
}

@Override
public void replaceBranch(String fromBranch) {
branchManager().replaceBranch(fromBranch);
}

@Override
public void mergeBranch(String fromBranch) {
branchManager().mergeBranch(fromBranch);
}

@Override
public void rollbackTo(String tagName) {
TagManager tagManager = tagManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ default void deleteBranch(String branchName) {
this.getClass().getSimpleName()));
}

@Override
default void replaceBranch(String fromBranch) {
throw new UnsupportedOperationException(
String.format(
"Readonly Table %s does not support replaceBranch.",
this.getClass().getSimpleName()));
}

@Override
default void mergeBranch(String fromBranch) {
throw new UnsupportedOperationException(
String.format(
"Readonly Table %s does not support mergeBranch.",
this.getClass().getSimpleName()));
}

@Override
default ExpireSnapshots newExpireSnapshots() {
throw new UnsupportedOperationException(
Expand Down
6 changes: 6 additions & 0 deletions paimon-core/src/main/java/org/apache/paimon/table/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public interface Table extends Serializable {
@Experimental
void deleteBranch(String branchName);

@Experimental
void replaceBranch(String fromBranch);

@Experimental
void mergeBranch(String fromBranch);

/** Manually expire snapshots, parameters can be controlled independently of table options. */
@Experimental
ExpireSnapshots newExpireSnapshots();
Expand Down
38 changes: 38 additions & 0 deletions paimon-core/src/main/java/org/apache/paimon/tag/TableTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.paimon.tag;

/** {@link TableTag} has tag relevant information for table. */
public class TableTag {
private final String tagName;
private final long createTime;

public TableTag(String tagName, Long createTime) {
this.tagName = tagName;
this.createTime = createTime;
}

public String getTagName() {
return tagName;
}

public long getCreateTime() {
return createTime;
}
}
Loading

0 comments on commit ced1e05

Please sign in to comment.