Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): support output filter #303

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,8 @@ private boolean isAllTargetsReached(Vertex vertex) {
}
return false;
}

public IdSet getTargetIdSet() {
return targetIdSet;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep this. prefix for members access

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import java.util.HashMap;
import java.util.Map;

import org.apache.hugegraph.computer.core.config.Config;
import org.apache.hugegraph.computer.core.graph.vertex.Vertex;
import org.apache.hugegraph.computer.core.output.hg.HugeGraphOutput;
import org.apache.hugegraph.computer.core.worker.Computation;
import org.apache.hugegraph.util.JsonUtil;

public class SingleSourceShortestPathOutput extends HugeGraphOutput<String> {
Expand All @@ -45,4 +47,10 @@ protected String value(Vertex vertex) {
map.put("total_weight", value.totalWeight());
return JsonUtil.toJson(map);
}

@Override
public boolean filter(Config config, Computation computation, Vertex vertex) {
SingleSourceShortestPath sssp = (SingleSourceShortestPath) computation;
return sssp.getTargetIdSet() == null || sssp.getTargetIdSet().contains(vertex.id());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.hugegraph.computer.core.config.Config;
import org.apache.hugegraph.computer.core.graph.vertex.Vertex;
import org.apache.hugegraph.computer.core.worker.Computation;

/**
* Computer output is used to output computer results. There is an output object
Expand All @@ -37,6 +38,14 @@ public interface ComputerOutput {
*/
void write(Vertex vertex);

/**
* Write filter.
* True to commit the computation result, otherwise not to commit.
*/
default boolean filter(Config config, Computation computation, Vertex vertex) {
return true;
}

/**
* Merge output files of multiple partitions if applicable.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ protected PartitionStat output() {
Edges edges = this.edgesInput.edges(this.vertexInput.idPointer());
vertex.edges(edges);

output.write(vertex);
if (output.filter(this.context.config(), this.computation, vertex)) {
output.write(vertex);
}
}

try {
Expand Down
Loading