From ef149ccb2ecea4753da973e303f935f53ea6bbc4 Mon Sep 17 00:00:00 2001 From: M <1216063060@qq.com> Date: Mon, 13 Nov 2023 16:02:24 +0800 Subject: [PATCH 1/3] feat: support edgeexistence api --- .../api/traverser/EdgeExistenceAPI.java | 57 ++++++++++++++++ .../hugegraph/driver/TraverserManager.java | 9 +++ .../apache/hugegraph/api/ApiTestSuite.java | 2 + .../org/apache/hugegraph/api/BaseApiTest.java | 1 + .../api/traverser/EdgeExistenceAPITest.java | 68 +++++++++++++++++++ .../api/traverser/TraverserApiTest.java | 3 + 6 files changed, 140 insertions(+) create mode 100644 hugegraph-client/src/main/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPI.java create mode 100644 hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPITest.java diff --git a/hugegraph-client/src/main/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPI.java b/hugegraph-client/src/main/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPI.java new file mode 100644 index 000000000..80094a9a6 --- /dev/null +++ b/hugegraph-client/src/main/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPI.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package org.apache.hugegraph.api.traverser; + + +import org.apache.hugegraph.api.graph.GraphAPI; +import org.apache.hugegraph.client.RestClient; +import org.apache.hugegraph.rest.RestResult; +import org.apache.hugegraph.structure.graph.Edge; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class EdgeExistenceAPI extends TraversersAPI { + + public EdgeExistenceAPI(RestClient client, String graph) { + super(client, graph); + } + + @Override + protected String type() { + return "edgeexistence"; + } + + public List get(Object sourceId, Object targetId, String edgeLabel, + String sortValues, long limit) { + String source = GraphAPI.formatVertexId(sourceId, false); + String target = GraphAPI.formatVertexId(targetId, false); + + checkLimit((int) limit); + + Map params = new LinkedHashMap<>(); + params.put("source", source); + params.put("target", target); + params.put("label", edgeLabel); + params.put("sortValues", sortValues); + params.put("limit", limit); + RestResult result = this.client.get(this.path(), params); + return result.readList(this.type(), Edge.class); + } +} diff --git a/hugegraph-client/src/main/java/org/apache/hugegraph/driver/TraverserManager.java b/hugegraph-client/src/main/java/org/apache/hugegraph/driver/TraverserManager.java index 735046a7f..c2c2d951b 100644 --- a/hugegraph-client/src/main/java/org/apache/hugegraph/driver/TraverserManager.java +++ b/hugegraph-client/src/main/java/org/apache/hugegraph/driver/TraverserManager.java @@ -45,6 +45,7 @@ import org.apache.hugegraph.api.traverser.TemplatePathsAPI; import org.apache.hugegraph.api.traverser.VerticesAPI; import org.apache.hugegraph.api.traverser.WeightedShortestPathAPI; +import org.apache.hugegraph.api.traverser.EdgeExistenceAPI; import org.apache.hugegraph.client.RestClient; import org.apache.hugegraph.structure.graph.Edge; import org.apache.hugegraph.structure.graph.Edges; @@ -98,6 +99,7 @@ public class TraverserManager { private PersonalRankAPI personalRankAPI; private VerticesAPI verticesAPI; private EdgesAPI edgesAPI; + private EdgeExistenceAPI edgeExistenceAPI; public TraverserManager(RestClient client, GraphManager graphManager) { this.graphManager = graphManager; @@ -124,6 +126,7 @@ public TraverserManager(RestClient client, GraphManager graphManager) { this.personalRankAPI = new PersonalRankAPI(client, graph); this.verticesAPI = new VerticesAPI(client, graph); this.edgesAPI = new EdgesAPI(client, graph); + this.edgeExistenceAPI = new EdgeExistenceAPI(client, graph); } public double jaccardSimilarity(Object vertexId, Object otherId) { @@ -538,4 +541,10 @@ public Iterator iteratorEdges(Shard shard, int sizePerPage) { return this.edges(shard, page, sizePerPage); }); } + + public List edgeExistence(Object sourceId, Object targetId, String edgeLabel, + String sortValues, long limit){ + return this.edgeExistenceAPI.get(sourceId, targetId, edgeLabel, + sortValues, limit); + } } diff --git a/hugegraph-client/src/test/java/org/apache/hugegraph/api/ApiTestSuite.java b/hugegraph-client/src/test/java/org/apache/hugegraph/api/ApiTestSuite.java index 6fdb3c537..c9edba73f 100644 --- a/hugegraph-client/src/test/java/org/apache/hugegraph/api/ApiTestSuite.java +++ b/hugegraph-client/src/test/java/org/apache/hugegraph/api/ApiTestSuite.java @@ -44,6 +44,7 @@ import org.apache.hugegraph.api.traverser.SingleSourceShortestPathApiTest; import org.apache.hugegraph.api.traverser.TemplatePathsApiTest; import org.apache.hugegraph.api.traverser.WeightedShortestPathApiTest; +import org.apache.hugegraph.api.traverser.EdgeExistenceAPITest; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -84,6 +85,7 @@ FusiformSimilarityApiTest.class, NeighborRankApiTest.class, PersonalRankApiTest.class, + EdgeExistenceAPITest.class, TargetApiTest.class, GroupApiTest.class, diff --git a/hugegraph-client/src/test/java/org/apache/hugegraph/api/BaseApiTest.java b/hugegraph-client/src/test/java/org/apache/hugegraph/api/BaseApiTest.java index 37e88622e..aca50e25a 100644 --- a/hugegraph-client/src/test/java/org/apache/hugegraph/api/BaseApiTest.java +++ b/hugegraph-client/src/test/java/org/apache/hugegraph/api/BaseApiTest.java @@ -31,6 +31,7 @@ import org.apache.hugegraph.api.schema.SchemaAPI; import org.apache.hugegraph.api.schema.VertexLabelAPI; import org.apache.hugegraph.api.task.TaskAPI; +import org.apache.hugegraph.api.traverser.EdgeExistenceAPI; import org.apache.hugegraph.api.variables.VariablesAPI; import org.apache.hugegraph.api.version.VersionAPI; import org.apache.hugegraph.client.RestClient; diff --git a/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPITest.java b/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPITest.java new file mode 100644 index 000000000..d88ac6c66 --- /dev/null +++ b/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPITest.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package org.apache.hugegraph.api.traverser; + + +import org.apache.hugegraph.api.BaseApiTest; +import org.apache.hugegraph.structure.graph.Edge; +import org.apache.hugegraph.testutil.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +public class EdgeExistenceAPITest extends TraverserApiTest{ + + @BeforeClass + public static void prepareSchemaAndGraph() { + BaseApiTest.initPropertyKey(); + BaseApiTest.initVertexLabel(); + BaseApiTest.initEdgeLabel(); + BaseApiTest.initIndexLabel(); + BaseApiTest.initVertex(); + BaseApiTest.initEdge(); + } + + @Test + public void testEdgeExistenceGet() { + Object markoId = getVertexId("person", "name", "marko"); + Object vadasId = getVertexId("person", "name", "vadas"); + + List edges = edgeExistenceAPI.get(markoId, vadasId, + "knows", "", 100); + + Assert.assertEquals(1, edges.size()); + String id = edges.get(0).id(); + + Assert.assertTrue(id.contains("marko")); + Assert.assertTrue(id.contains("vadas")); + + Object lopId = getVertexId("software", "name", "lop"); + + edges = edgeExistenceAPI.get(lopId, vadasId, + "knows", "", 100); + Assert.assertEquals(0, edges.size()); + + Object joshId = getVertexId("person", "name", "josh"); + Object rippleId = getVertexId("person", "name", "ripple"); + + edges = edgeExistenceAPI.get(joshId, rippleId, + "created", "", 100); + Assert.assertEquals(1, edges.size()); + } +} diff --git a/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/TraverserApiTest.java b/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/TraverserApiTest.java index 2a02dd10d..f6ab77156 100644 --- a/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/TraverserApiTest.java +++ b/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/TraverserApiTest.java @@ -49,6 +49,7 @@ public class TraverserApiTest extends BaseApiTest { protected static VerticesAPI verticesAPI; protected static EdgesAPI edgesAPI; + protected static EdgeExistenceAPI edgeExistenceAPI; @BeforeClass public static void init() { @@ -82,5 +83,7 @@ public static void init() { verticesAPI = new VerticesAPI(client, GRAPH); edgesAPI = new EdgesAPI(client, GRAPH); + + edgeExistenceAPI = new EdgeExistenceAPI(client, GRAPH); } } From ca07c7f11fa410a676642bd931a07a8e34abba96 Mon Sep 17 00:00:00 2001 From: M <1216063060@qq.com> Date: Mon, 13 Nov 2023 16:02:24 +0800 Subject: [PATCH 2/3] feat: support edgeexistence api --- .../api/traverser/EdgeExistenceAPI.java | 57 ++++++++++++++++ .../hugegraph/driver/TraverserManager.java | 9 +++ .../apache/hugegraph/api/ApiTestSuite.java | 2 + .../org/apache/hugegraph/api/BaseApiTest.java | 1 + .../api/traverser/EdgeExistenceAPITest.java | 68 +++++++++++++++++++ .../api/traverser/TraverserApiTest.java | 3 + 6 files changed, 140 insertions(+) create mode 100644 hugegraph-client/src/main/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPI.java create mode 100644 hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPITest.java diff --git a/hugegraph-client/src/main/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPI.java b/hugegraph-client/src/main/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPI.java new file mode 100644 index 000000000..80094a9a6 --- /dev/null +++ b/hugegraph-client/src/main/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPI.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package org.apache.hugegraph.api.traverser; + + +import org.apache.hugegraph.api.graph.GraphAPI; +import org.apache.hugegraph.client.RestClient; +import org.apache.hugegraph.rest.RestResult; +import org.apache.hugegraph.structure.graph.Edge; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class EdgeExistenceAPI extends TraversersAPI { + + public EdgeExistenceAPI(RestClient client, String graph) { + super(client, graph); + } + + @Override + protected String type() { + return "edgeexistence"; + } + + public List get(Object sourceId, Object targetId, String edgeLabel, + String sortValues, long limit) { + String source = GraphAPI.formatVertexId(sourceId, false); + String target = GraphAPI.formatVertexId(targetId, false); + + checkLimit((int) limit); + + Map params = new LinkedHashMap<>(); + params.put("source", source); + params.put("target", target); + params.put("label", edgeLabel); + params.put("sortValues", sortValues); + params.put("limit", limit); + RestResult result = this.client.get(this.path(), params); + return result.readList(this.type(), Edge.class); + } +} diff --git a/hugegraph-client/src/main/java/org/apache/hugegraph/driver/TraverserManager.java b/hugegraph-client/src/main/java/org/apache/hugegraph/driver/TraverserManager.java index 735046a7f..c2c2d951b 100644 --- a/hugegraph-client/src/main/java/org/apache/hugegraph/driver/TraverserManager.java +++ b/hugegraph-client/src/main/java/org/apache/hugegraph/driver/TraverserManager.java @@ -45,6 +45,7 @@ import org.apache.hugegraph.api.traverser.TemplatePathsAPI; import org.apache.hugegraph.api.traverser.VerticesAPI; import org.apache.hugegraph.api.traverser.WeightedShortestPathAPI; +import org.apache.hugegraph.api.traverser.EdgeExistenceAPI; import org.apache.hugegraph.client.RestClient; import org.apache.hugegraph.structure.graph.Edge; import org.apache.hugegraph.structure.graph.Edges; @@ -98,6 +99,7 @@ public class TraverserManager { private PersonalRankAPI personalRankAPI; private VerticesAPI verticesAPI; private EdgesAPI edgesAPI; + private EdgeExistenceAPI edgeExistenceAPI; public TraverserManager(RestClient client, GraphManager graphManager) { this.graphManager = graphManager; @@ -124,6 +126,7 @@ public TraverserManager(RestClient client, GraphManager graphManager) { this.personalRankAPI = new PersonalRankAPI(client, graph); this.verticesAPI = new VerticesAPI(client, graph); this.edgesAPI = new EdgesAPI(client, graph); + this.edgeExistenceAPI = new EdgeExistenceAPI(client, graph); } public double jaccardSimilarity(Object vertexId, Object otherId) { @@ -538,4 +541,10 @@ public Iterator iteratorEdges(Shard shard, int sizePerPage) { return this.edges(shard, page, sizePerPage); }); } + + public List edgeExistence(Object sourceId, Object targetId, String edgeLabel, + String sortValues, long limit){ + return this.edgeExistenceAPI.get(sourceId, targetId, edgeLabel, + sortValues, limit); + } } diff --git a/hugegraph-client/src/test/java/org/apache/hugegraph/api/ApiTestSuite.java b/hugegraph-client/src/test/java/org/apache/hugegraph/api/ApiTestSuite.java index 6fdb3c537..c9edba73f 100644 --- a/hugegraph-client/src/test/java/org/apache/hugegraph/api/ApiTestSuite.java +++ b/hugegraph-client/src/test/java/org/apache/hugegraph/api/ApiTestSuite.java @@ -44,6 +44,7 @@ import org.apache.hugegraph.api.traverser.SingleSourceShortestPathApiTest; import org.apache.hugegraph.api.traverser.TemplatePathsApiTest; import org.apache.hugegraph.api.traverser.WeightedShortestPathApiTest; +import org.apache.hugegraph.api.traverser.EdgeExistenceAPITest; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -84,6 +85,7 @@ FusiformSimilarityApiTest.class, NeighborRankApiTest.class, PersonalRankApiTest.class, + EdgeExistenceAPITest.class, TargetApiTest.class, GroupApiTest.class, diff --git a/hugegraph-client/src/test/java/org/apache/hugegraph/api/BaseApiTest.java b/hugegraph-client/src/test/java/org/apache/hugegraph/api/BaseApiTest.java index 37e88622e..aca50e25a 100644 --- a/hugegraph-client/src/test/java/org/apache/hugegraph/api/BaseApiTest.java +++ b/hugegraph-client/src/test/java/org/apache/hugegraph/api/BaseApiTest.java @@ -31,6 +31,7 @@ import org.apache.hugegraph.api.schema.SchemaAPI; import org.apache.hugegraph.api.schema.VertexLabelAPI; import org.apache.hugegraph.api.task.TaskAPI; +import org.apache.hugegraph.api.traverser.EdgeExistenceAPI; import org.apache.hugegraph.api.variables.VariablesAPI; import org.apache.hugegraph.api.version.VersionAPI; import org.apache.hugegraph.client.RestClient; diff --git a/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPITest.java b/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPITest.java new file mode 100644 index 000000000..d88ac6c66 --- /dev/null +++ b/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/EdgeExistenceAPITest.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package org.apache.hugegraph.api.traverser; + + +import org.apache.hugegraph.api.BaseApiTest; +import org.apache.hugegraph.structure.graph.Edge; +import org.apache.hugegraph.testutil.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +public class EdgeExistenceAPITest extends TraverserApiTest{ + + @BeforeClass + public static void prepareSchemaAndGraph() { + BaseApiTest.initPropertyKey(); + BaseApiTest.initVertexLabel(); + BaseApiTest.initEdgeLabel(); + BaseApiTest.initIndexLabel(); + BaseApiTest.initVertex(); + BaseApiTest.initEdge(); + } + + @Test + public void testEdgeExistenceGet() { + Object markoId = getVertexId("person", "name", "marko"); + Object vadasId = getVertexId("person", "name", "vadas"); + + List edges = edgeExistenceAPI.get(markoId, vadasId, + "knows", "", 100); + + Assert.assertEquals(1, edges.size()); + String id = edges.get(0).id(); + + Assert.assertTrue(id.contains("marko")); + Assert.assertTrue(id.contains("vadas")); + + Object lopId = getVertexId("software", "name", "lop"); + + edges = edgeExistenceAPI.get(lopId, vadasId, + "knows", "", 100); + Assert.assertEquals(0, edges.size()); + + Object joshId = getVertexId("person", "name", "josh"); + Object rippleId = getVertexId("person", "name", "ripple"); + + edges = edgeExistenceAPI.get(joshId, rippleId, + "created", "", 100); + Assert.assertEquals(1, edges.size()); + } +} diff --git a/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/TraverserApiTest.java b/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/TraverserApiTest.java index 2a02dd10d..f6ab77156 100644 --- a/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/TraverserApiTest.java +++ b/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/TraverserApiTest.java @@ -49,6 +49,7 @@ public class TraverserApiTest extends BaseApiTest { protected static VerticesAPI verticesAPI; protected static EdgesAPI edgesAPI; + protected static EdgeExistenceAPI edgeExistenceAPI; @BeforeClass public static void init() { @@ -82,5 +83,7 @@ public static void init() { verticesAPI = new VerticesAPI(client, GRAPH); edgesAPI = new EdgesAPI(client, GRAPH); + + edgeExistenceAPI = new EdgeExistenceAPI(client, GRAPH); } } From 6d4eac994046ddfafdf297c39810754156461e80 Mon Sep 17 00:00:00 2001 From: M <1216063060@qq.com> Date: Thu, 30 Nov 2023 10:42:52 +0800 Subject: [PATCH 3/3] Update install-hugegraph-from-source.sh --- .../assembly/travis/install-hugegraph-from-source.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/hugegraph-client/assembly/travis/install-hugegraph-from-source.sh b/hugegraph-client/assembly/travis/install-hugegraph-from-source.sh index fe9024077..9359a27a1 100755 --- a/hugegraph-client/assembly/travis/install-hugegraph-from-source.sh +++ b/hugegraph-client/assembly/travis/install-hugegraph-from-source.sh @@ -28,6 +28,7 @@ GIT_DIR=hugegraph # download code and compile git clone --depth 100 ${HUGEGRAPH_GIT_URL} $GIT_DIR cd "${GIT_DIR}" +git log git checkout "${COMMIT_ID}" mvn package -DskipTests -Dmaven.javadoc.skip=true -ntp