Skip to content

Commit

Permalink
[AMORO-2842] Support list all paimon branch (apache#3093)
Browse files Browse the repository at this point in the history
* Support list all paimon branch

* update

* Support list all paimon branch

---------

Co-authored-by: huyuanfeng <[email protected]>
Co-authored-by: ConradJam <[email protected]>
  • Loading branch information
3 people authored Nov 1, 2024
1 parent 866b762 commit bbb4062
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -341,7 +343,7 @@ private void collectSnapshots(

@Override
public List<PartitionFileBaseInfo> getSnapshotDetail(
AmoroTable<?> amoroTable, String snapshotId) {
AmoroTable<?> amoroTable, String snapshotId, @Nullable String ref) {
MixedTable mixedTable = getTable(amoroTable);
List<PartitionFileBaseInfo> result = new ArrayList<>();
long commitId = Long.parseLong(snapshotId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public List<AmoroSnapshotsOfTable> getSnapshots(
}

public List<PartitionFileBaseInfo> getSnapshotDetail(
TableIdentifier tableIdentifier, String snapshotId) {
TableIdentifier tableIdentifier, String snapshotId, String ref) {
AmoroTable<?> amoroTable = loadTable(tableIdentifier);
FormatTableDescriptor formatTableDescriptor = formatDescriptorMap.get(amoroTable.format());
return formatTableDescriptor.getSnapshotDetail(amoroTable, snapshotId);
return formatTableDescriptor.getSnapshotDetail(amoroTable, snapshotId, ref);
}

public List<DDLInfo> getTableOperations(TableIdentifier tableIdentifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,13 @@ public void getSnapshotDetail(Context ctx) {
String snapshotId = ctx.pathParam("snapshotId");
Integer page = ctx.queryParamAsClass("page", Integer.class).getOrDefault(1);
Integer pageSize = ctx.queryParamAsClass("pageSize", Integer.class).getOrDefault(20);
String ref = ctx.queryParamAsClass("ref", String.class).getOrDefault(null);

List<PartitionFileBaseInfo> result =
tableDescriptor.getSnapshotDetail(
TableIdentifier.of(catalog, database, tableName).buildTableIdentifier(), snapshotId);
TableIdentifier.of(catalog, database, tableName).buildTableIdentifier(),
snapshotId,
ref);
int offset = (page - 1) * pageSize;
PageResult<PartitionFileBaseInfo> amsPageResult = PageResult.of(result, offset, pageSize);
ctx.json(OkResponse.of(amsPageResult));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ List<AmoroSnapshotsOfTable> getSnapshots(
AmoroTable<?> amoroTable, String ref, OperationType operationType);

/** Get the snapshot detail information of the {@link AmoroTable}. */
List<PartitionFileBaseInfo> getSnapshotDetail(AmoroTable<?> amoroTable, String snapshotId);
List<PartitionFileBaseInfo> getSnapshotDetail(
AmoroTable<?> amoroTable, String snapshotId, String ref);

/** Get the DDL information of the {@link AmoroTable}. */
List<DDLInfo> getTableOperations(AmoroTable<?> amoroTable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;

import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
Expand Down Expand Up @@ -246,7 +248,7 @@ public List<AmoroSnapshotsOfTable> getSnapshots(

@Override
public List<PartitionFileBaseInfo> getSnapshotDetail(
AmoroTable<?> amoroTable, String snapshotId) {
AmoroTable<?> amoroTable, String snapshotId, @Nullable String ref) {
HoodieJavaTable hoodieTable = (HoodieJavaTable) amoroTable.originalTable();
SyncableFileSystemView fileSystemView = hoodieTable.getHoodieView();
Map<String, Stream<FileSlice>> ptFsMap =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.amoro.TableFormat;
import org.apache.amoro.api.CommitMetaProducer;
import org.apache.amoro.process.ProcessStatus;
import org.apache.amoro.shade.guava32.com.google.common.collect.ImmutableList;
import org.apache.amoro.shade.guava32.com.google.common.collect.Lists;
import org.apache.amoro.shade.guava32.com.google.common.collect.Maps;
import org.apache.amoro.shade.guava32.com.google.common.collect.Streams;
Expand Down Expand Up @@ -61,7 +60,9 @@
import org.apache.paimon.manifest.ManifestList;
import org.apache.paimon.table.DataTable;
import org.apache.paimon.table.FileStoreTable;
import org.apache.paimon.utils.BranchManager;
import org.apache.paimon.utils.FileStorePathFactory;
import org.apache.paimon.utils.SnapshotManager;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
Expand Down Expand Up @@ -181,9 +182,10 @@ public List<AmoroSnapshotsOfTable> getSnapshots(
FileStoreTable table = getTable(amoroTable);
List<AmoroSnapshotsOfTable> snapshotsOfTables = new ArrayList<>();
Iterator<Snapshot> snapshots;
if (PAIMON_MAIN_BRANCH_NAME.equals(ref)) {
if (table.branchManager().branchExists(ref) || BranchManager.isMainBranch(ref)) {
SnapshotManager snapshotManager = table.snapshotManager().copyWithBranch(ref);
try {
snapshots = table.snapshotManager().snapshots();
snapshots = snapshotManager.snapshots();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -223,11 +225,17 @@ public List<AmoroSnapshotsOfTable> getSnapshots(

@Override
public List<PartitionFileBaseInfo> getSnapshotDetail(
AmoroTable<?> amoroTable, String snapshotId) {
AmoroTable<?> amoroTable, String snapshotId, String ref) {
FileStoreTable table = getTable(amoroTable);
List<PartitionFileBaseInfo> amsDataFileInfos = new ArrayList<>();
long commitId = Long.parseLong(snapshotId);
Snapshot snapshot = table.snapshotManager().snapshot(commitId);
Snapshot snapshot;
if (BranchManager.isMainBranch(ref) || table.branchManager().branchExists(ref)) {
snapshot = table.snapshotManager().copyWithBranch(ref).snapshot(commitId);
} else {
snapshot = table.tagManager().tag(ref);
}

FileStore<?> store = table.store();
FileStorePathFactory fileStorePathFactory = store.pathFactory();
ManifestList manifestList = store.manifestListFactory().create();
Expand Down Expand Up @@ -531,7 +539,14 @@ public List<TagOrBranchInfo> getTableTags(AmoroTable<?> amoroTable) {

@Override
public List<TagOrBranchInfo> getTableBranches(AmoroTable<?> amoroTable) {
return ImmutableList.of(TagOrBranchInfo.MAIN_BRANCH);
FileStoreTable table = getTable(amoroTable);
List<String> branches = table.branchManager().branches();
List<TagOrBranchInfo> branchInfos =
branches.stream()
.map(name -> new TagOrBranchInfo(name, -1, -1, 0L, 0L, TagOrBranchInfo.BRANCH))
.collect(Collectors.toList());
branchInfos.add(TagOrBranchInfo.MAIN_BRANCH);
return branchInfos;
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions amoro-web/src/services/table.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,15 @@ export function getDetailBySnapshotId(
catalog: string
db: string
table: string
ref: string
snapshotId: string
page: number
pageSize: number
token?: string
},
) {
const { catalog, db, table, snapshotId, page, pageSize, token } = params
return request.get(`api/ams/v1/tables/catalogs/${catalog}/dbs/${db}/tables/${table}/snapshots/${snapshotId}/detail`, { params: { page, pageSize, token } })
const { catalog, db, table, snapshotId, page, pageSize, ref, token } = params
return request.get(`api/v1/tables/catalogs/${catalog}/dbs/${db}/tables/${table}/snapshots/${snapshotId}/detail`, { params: { page, pageSize, ref, token } })
}
// get operations
export function getOperations(
Expand Down
1 change: 1 addition & 0 deletions amoro-web/src/views/tables/components/Snapshots.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ async function getBreadcrumbTable() {
const params = {
...sourceData,
snapshotId: snapshotId.value,
ref: tblRef.value,
page: breadcrumbPagination.current,
pageSize: breadcrumbPagination.pageSize,
}
Expand Down

0 comments on commit bbb4062

Please sign in to comment.