-
Notifications
You must be signed in to change notification settings - Fork 94
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: support edgeexistence api #539
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Edge> 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<String, Object> 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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<Edge> iteratorEdges(Shard shard, int sizePerPage) { | |
return this.edges(shard, page, sizePerPage); | ||
}); | ||
} | ||
|
||
public List<Edge> edgeExistence(Object sourceId, Object targetId, String edgeLabel, | ||
String sortValues, long limit){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expect |
||
return this.edgeExistenceAPI.get(sourceId, targetId, edgeLabel, | ||
sortValues, limit); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems one line is ok |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Edge> 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems one line is ok |
||
Assert.assertEquals(0, edges.size()); | ||
|
||
Object joshId = getVertexId("person", "name", "josh"); | ||
Object rippleId = getVertexId("person", "name", "ripple"); | ||
|
||
edges = edgeExistenceAPI.get(joshId, rippleId, | ||
"created", "", 100); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems one line is ok |
||
Assert.assertEquals(1, edges.size()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add this 2 versions: