From d0a9a1fa1fff45ac1c4c4cbee98f86cc507b13f7 Mon Sep 17 00:00:00 2001 From: liningrui Date: Wed, 2 Jun 2021 19:03:38 +0800 Subject: [PATCH 1/3] Improve check for getting vertex when create edge Change-Id: I86b7ac068154c52faf0d0d7f035cbf08178bf0d8 --- .../main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java index 55e8f14382..37d36e6ad9 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java @@ -275,7 +275,8 @@ public String list(@Context GraphManager manager, @QueryParam("limit") @DefaultValue("100") long limit) { LOG.debug("Graph [{}] query edges by vertex: {}, direction: {}, " + "label: {}, properties: {}, offset: {}, page: {}, limit: {}", - vertexId, direction, label, properties, offset, page, limit); + graph, vertexId, direction, + label, properties, offset, page, limit); Map props = parseProperties(properties); if (page != null) { @@ -402,6 +403,12 @@ private static Vertex getVertex(HugeGraph graph, throw new IllegalArgumentException(String.format( "Invalid vertex id '%s'", id)); } + if (vertex.label().equals(label)) { + throw new IllegalArgumentException(String.format( + "The label of vertex '%s' is unmatched, users expect " + + "label '%s', actual label stored is '%s'", + id, label, vertex.label())); + } // Clone a new vertex to support multi-thread access return vertex.copy(); } From e12a45c873257ef546819f7939889640abdbc168 Mon Sep 17 00:00:00 2001 From: liningrui Date: Tue, 8 Jun 2021 14:47:14 +0800 Subject: [PATCH 2/3] add ! Change-Id: I52acfae504460d2c2a7927aa129cb658822836e0 --- .../src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java index 37d36e6ad9..50b7a2a373 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java @@ -403,7 +403,7 @@ private static Vertex getVertex(HugeGraph graph, throw new IllegalArgumentException(String.format( "Invalid vertex id '%s'", id)); } - if (vertex.label().equals(label)) { + if (!vertex.label().equals(label)) { throw new IllegalArgumentException(String.format( "The label of vertex '%s' is unmatched, users expect " + "label '%s', actual label stored is '%s'", From c01e998b31d92c3dd4808ef069eacd94cce2032c Mon Sep 17 00:00:00 2001 From: liningrui Date: Tue, 8 Jun 2021 19:55:23 +0800 Subject: [PATCH 3/3] improve Change-Id: I3addbb2ffd44b53c4edd0241327ba6d4f4895126 --- .../src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java index 50b7a2a373..c146e9e449 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java @@ -104,8 +104,8 @@ public String create(@Context GraphManager manager, "Invalid target vertex label '%s'"); } - Vertex srcVertex = getVertex(g, jsonEdge.source, null); - Vertex tgtVertex = getVertex(g, jsonEdge.target, null); + Vertex srcVertex = getVertex(g, jsonEdge.source, jsonEdge.sourceLabel); + Vertex tgtVertex = getVertex(g, jsonEdge.target, jsonEdge.targetLabel); Edge edge = commit(g, () -> { return srcVertex.addEdge(jsonEdge.label, tgtVertex,