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

Merged
merged 20 commits into from
Aug 10, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(core): IdList Merge Combiner
diaohancai committed Dec 26, 2023
commit cdaba230d2da41a31a21b0e68765d2b2eb4e8f31
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@
*/
private Double defaultWeight;

//****************** global data ******************//
/**
* reach target
*/
@@ -97,22 +98,22 @@
public void init(Config config) {
this.sourceId = config.getString(OPTION_SOURCE_ID, "");
if (StringUtils.isBlank(this.sourceId)) {
throw new ComputerException("The param '%s' must not be blank", OPTION_SOURCE_ID);

Check warning on line 101 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L101

Added line #L101 was not covered by tests
}

this.targetId = config.getString(OPTION_TARGET_ID, "");
if (StringUtils.isBlank(this.targetId)) {
throw new ComputerException("The param '%s' must not be blank", OPTION_TARGET_ID);

Check warning on line 106 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L106

Added line #L106 was not covered by tests
}

if (this.targetId.equals("*")) {
this.targetQuantityType = QuantityType.ALL;

Check warning on line 110 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L110

Added line #L110 was not covered by tests
} else if (this.targetId.split(",").length > 1) {
// remove spaces
this.targetId = Arrays.stream(this.targetId.split(","))
.map(e -> e.trim())
.collect(Collectors.joining(","));
this.targetQuantityType = QuantityType.MULTIPLE;

Check warning on line 116 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L113-L116

Added lines #L113 - L116 were not covered by tests
} else {
this.targetQuantityType = QuantityType.SINGLE;
}
@@ -121,7 +122,7 @@

this.defaultWeight = config.getDouble(OPTION_DEFAULT_WEIGHT, 1);
if (this.defaultWeight <= 0) {
throw new ComputerException("The param '%s' must be greater than 0, " +

Check warning on line 125 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L125

Added line #L125 was not covered by tests
"actual got '%s'",
OPTION_DEFAULT_WEIGHT, this.defaultWeight);
}
@@ -143,17 +144,17 @@
// single target && source vertex == target vertex
if (this.targetQuantityType.equals(QuantityType.SINGLE) &&
this.sourceId.equals(this.targetId)) {
LOG.debug("source vertex {} equals target vertex {}", this.sourceId, this.targetId);
vertex.inactivate();
return;

Check warning on line 149 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L147-L149

Added lines #L147 - L149 were not covered by tests
}

if (vertex.numEdges() <= 0) {
// isolated vertex
LOG.debug("source vertex {} can not reach target vertex {}",

Check warning on line 154 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L154

Added line #L154 was not covered by tests
this.sourceId, this.targetId);
vertex.inactivate();
return;

Check warning on line 157 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L156-L157

Added lines #L156 - L157 were not covered by tests
}

vertex.edges().forEach(edge -> {
@@ -231,16 +232,16 @@
Value property = edge.property(this.weightProperty);
if (property != null) {
if (!property.isNumber()) {
throw new ComputerException("The value of %s must be a numeric value, " +

Check warning on line 235 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L235

Added line #L235 was not covered by tests
"actual got '%s'",
this.weightProperty, property.string());

Check warning on line 237 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L237

Added line #L237 was not covered by tests
}

weight = ((DoubleValue) property).doubleValue();
if (weight <= 0) {
throw new ComputerException("The value of %s must be greater than 0, " +

Check warning on line 242 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L242

Added line #L242 was not covered by tests
"actual got '%s'",
this.weightProperty, property.string());

Check warning on line 244 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L244

Added line #L244 was not covered by tests
}
}
return weight;
@@ -258,7 +259,7 @@
if (this.targetQuantityType.equals(QuantityType.MULTIPLE)) {
for (String targetId : this.targetId.split(",")) {
if (this.idEquals(vertex, targetId)) {
return true;

Check warning on line 262 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L262

Added line #L262 was not covered by tests
}
}
}
@@ -275,17 +276,17 @@
}

if (this.targetQuantityType.equals(QuantityType.MULTIPLE)) {
String[] targetIds = this.targetId.split(",");

Check warning on line 279 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L279

Added line #L279 was not covered by tests
if (targetIds.length == this.reachTarget.size()) {
List<String> reachTargets = this.reachTarget.values()
.stream().map(Id::toString)
.collect(Collectors.toList());

Check warning on line 283 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L281-L283

Added lines #L281 - L283 were not covered by tests
for (String targetId : targetIds) {
if (!reachTargets.contains(targetId)) {
return false;

Check warning on line 286 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L286

Added line #L286 was not covered by tests
}
}
return true;

Check warning on line 289 in computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java

Codecov / codecov/patch

computer-algorithm/src/main/java/org/apache/hugegraph/computer/algorithm/path/shortest/SingleSourceShortestPath.java#L289

Added line #L289 was not covered by tests
}
}

Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@

package org.apache.hugegraph.computer.algorithm.path.shortest;

import org.apache.hugegraph.computer.core.combiner.IdListMergeCombiner;
import org.apache.hugegraph.computer.core.graph.value.ValueType;
import org.apache.hugegraph.computer.core.master.MasterComputation;
import org.apache.hugegraph.computer.core.master.MasterComputationContext;
@@ -31,7 +32,7 @@ public class SingleSourceShortestPathMaster implements MasterComputation {
public void init(MasterContext context) {
context.registerAggregator(SINGLE_SOURCE_SHORTEST_PATH_REACH_TARGET,
ValueType.ID_LIST,
ReachTargetCombiner.class);
IdListMergeCombiner.class);
}

@Override
Original file line number Diff line number Diff line change
@@ -15,13 +15,12 @@
* under the License.
*/

package org.apache.hugegraph.computer.algorithm.path.shortest;
package org.apache.hugegraph.computer.core.combiner;

import org.apache.hugegraph.computer.core.combiner.Combiner;
import org.apache.hugegraph.computer.core.graph.id.Id;
import org.apache.hugegraph.computer.core.graph.value.IdList;

public class ReachTargetCombiner implements Combiner<IdList> {
public class IdListMergeCombiner implements Combiner<IdList> {

@Override
public void combine(IdList v1, IdList v2, IdList result) {
@@ -33,7 +32,7 @@
}
for (Id id : v2.values()) {
if (!result.contains(id)) {
result.add(id);

Check warning on line 35 in computer-api/src/main/java/org/apache/hugegraph/computer/core/combiner/IdListMergeCombiner.java

Codecov / codecov/patch

computer-api/src/main/java/org/apache/hugegraph/computer/core/combiner/IdListMergeCombiner.java#L35

Added line #L35 was not covered by tests
}
}
}
Loading