Skip to content

Commit

Permalink
[AMORO-3218] Fix logic for consturct the result of optimizer tables a…
Browse files Browse the repository at this point in the history
…pi (#3231)
  • Loading branch information
klion26 authored Oct 10, 2024
1 parent 6ed8162 commit 699afcf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ public void getOptimizerTables(Context ctx) {
.collect(Collectors.toList());

PageResult<TableOptimizingInfo> amsPageResult =
PageResult.of(tableRuntimes, offset, pageSize, OptimizingUtil::buildTableOptimizeInfo);
PageResult.of(
tableRuntimes.stream()
.map(OptimizingUtil::buildTableOptimizeInfo)
.collect(Collectors.toList()),
tableService.listRuntimes(dbFilterStr, tableFilterStr).size());
ctx.json(OkResponse.of(amsPageResult));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
import javax.annotation.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -471,6 +473,33 @@ public TableRuntime getRuntime(Long tableId) {
return tableRuntimeMap.get(tableId);
}

public Map<Long, TableRuntime> listRuntimes(
@Nullable String dbFilter, @Nullable String tableFilter) {
checkStarted();
// no filter, will return all the table runtime.
if (dbFilter == null && tableFilter == null) {
return Collections.unmodifiableMap(tableRuntimeMap);
}

Map<Long, TableRuntime> filteredRuntimes = new HashMap<>();
for (Map.Entry<Long, TableRuntime> entry : tableRuntimeMap.entrySet()) {
ServerTableIdentifier identifier = entry.getValue().getTableIdentifier();
// skip the runtime which fails the db filter.
if (dbFilter != null && !identifier.getDatabase().contains(dbFilter)) {
continue;
}

// skip the runtime which fails the table filter.
if (tableFilter != null && !identifier.getTableName().contains(tableFilter)) {
continue;
}

filteredRuntimes.put(entry.getKey(), entry.getValue());
}

return filteredRuntimes;
}

@Override
public boolean contains(Long tableId) {
checkStarted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import org.apache.amoro.AmoroTable;
import org.apache.amoro.ServerTableIdentifier;

import javax.annotation.Nullable;

import java.util.Map;

public interface TableManager extends TableRuntimeHandler {

/**
Expand All @@ -33,6 +37,9 @@ public interface TableManager extends TableRuntimeHandler {

TableRuntime getRuntime(Long tableId);

/** Return the table runtimes associated to the given filter. */
Map<Long, TableRuntime> listRuntimes(@Nullable String dbFilter, @Nullable String tableFilter);

default boolean contains(Long tableId) {
return getRuntime(tableId) != null;
}
Expand Down

0 comments on commit 699afcf

Please sign in to comment.