This is an automated email from the ASF dual-hosted git repository. jin pushed a commit to branch olap-algo in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git
commit db922eb2dc93545a7203bc61f58e7bdaef43a7de Author: Jermy Li <[email protected]> AuthorDate: Sat Apr 11 10:46:04 2020 +0800 fix inconsistent error messages with clabel (#10) also improve error message cause reason Change-Id: I15ea8dd651e01ff678a32f19efd3584cd20ffc10 --- .../com/baidu/hugegraph/job/algorithm/AbstractAlgorithm.java | 12 ++++++++++-- .../hugegraph/job/algorithm/cent/AbstractCentAlgorithm.java | 2 +- .../baidu/hugegraph/job/algorithm/comm/LouvainTraverser.java | 5 +---- .../com/baidu/hugegraph/job/algorithm/comm/LpaAlgorithm.java | 5 +++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AbstractAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AbstractAlgorithm.java index 8db652d0d..8387a69f9 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AbstractAlgorithm.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AbstractAlgorithm.java @@ -344,7 +344,14 @@ public abstract class AbstractAlgorithm implements Algorithm { }); } - protected static boolean match(Element elem, String key, Object value) { + protected boolean match(Element elem, Object clabel) { + return match(elem, C_LABEL, clabel); + } + + protected boolean match(Element elem, String key, Object value) { + // check property key exists + this.graph().propertyKey(key); + // return true if property value exists & equals to specified value Property<Object> p = elem.property(key); return p.isPresent() && Objects.equal(p.value(), value); } @@ -375,7 +382,8 @@ public abstract class AbstractAlgorithm implements Algorithm { try { return callback.call(); } catch (Exception e) { - throw new HugeException("Failed to execute algorithm", e); + throw new HugeException("Failed to execute algorithm: %s", + e, e.getMessage()); } finally { Query.defaultCapacity(capacity); try { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/AbstractCentAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/AbstractCentAlgorithm.java index fba7a8de7..37492e456 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/AbstractCentAlgorithm.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/AbstractCentAlgorithm.java @@ -66,7 +66,7 @@ public abstract class AbstractCentAlgorithm extends AbstractAlgorithm { t = t.filter(it -> { this.updateProgress(++this.progress); return sourceCLabel == null ? true : - match(it.get(), C_LABEL, sourceCLabel); + match(it.get(), sourceCLabel); }); if (sourceSample > 0L) { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LouvainTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LouvainTraverser.java index ecb500a7d..0177d8f2d 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LouvainTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LouvainTraverser.java @@ -19,8 +19,6 @@ package com.baidu.hugegraph.job.algorithm.comm; -import static com.baidu.hugegraph.job.algorithm.AbstractAlgorithm.C_LABEL; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -237,8 +235,7 @@ public class LouvainTraverser extends AlgoTraverser { } } // skip the vertex with unmatched clabel - if (this.sourceCLabel != null && - !match(v, C_LABEL, this.sourceCLabel)) { + if (this.sourceCLabel != null && !match(v, this.sourceCLabel)) { return true; } return false; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LpaAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LpaAlgorithm.java index 361e9b9a9..abcdb938c 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LpaAlgorithm.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LpaAlgorithm.java @@ -35,6 +35,7 @@ import com.baidu.hugegraph.job.Job; import com.baidu.hugegraph.schema.SchemaManager; import com.baidu.hugegraph.schema.VertexLabel; import com.baidu.hugegraph.type.define.Directions; +import com.baidu.hugegraph.util.E; import com.google.common.collect.ImmutableMap; public class LpaAlgorithm extends AbstractCommAlgorithm { @@ -122,9 +123,9 @@ public class LpaAlgorithm extends AbstractCommAlgorithm { } public Object showCommunity(String clabel) { + E.checkNotNull(clabel, "clabel"); // all vertices with specified c-label - Iterator<Vertex> vertices = this.vertices(LIMIT); - vertices = filter(vertices, C_LABEL, clabel); + Iterator<Vertex> vertices = this.vertices(null, clabel, LIMIT); JsonMap json = new JsonMap(); json.startList();
