-
Notifications
You must be signed in to change notification settings - Fork 593
feat: optimising adjacency edge queries #2242
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
3559ace
refact: move dirs into hugegraph-server
VGalaxies 9068cef
refact: create dirs for hugegraph-pd and hugegraph-store
VGalaxies fd161f2
refact: init root pom for all modules
VGalaxies 49a1acf
fix: fix parent of submodules in hugegraph-server
VGalaxies fca91b2
fix: path
msgui 8465927
fix: conf path
msgui 3b791ee
fix: 1.10 -> 1.11
msgui ae90ba6
Revert "fix: 1.10 -> 1.11"
msgui ce5ddbf
fix: version 1.0.0 -> 1.5.0
msgui 8a7ed6a
fix:
msgui 242786b
check
msgui 2e401de
fix: SERVER_DIR
msgui 67de746
fix
msgui edb77ef
fix
msgui 764dd89
fix: SERVER_DIR
msgui 9a2f2e6
Merge pull request #5 from msgui/fix_CI
msgui 4f68641
test
msgui d582a51
Merge pull request #14 from msgui/new-fix-depedency-review
msgui 80cf036
Merge branch 'master' of https://github.com/msgui/incubator-hugegraph
msgui 2b241dd
Merge branch 'master' of https://github.com/msgui/incubator-hugegraph
msgui 5b5560f
Merge branch 'master' of https://github.com/msgui/incubator-hugegraph
msgui 5db1cfb
feat: optimising adjacency edge queries
msgui 32f44c0
fix: "source" -> "target"
msgui 33108fe
fix: resolve reviews
msgui 7a2a61a
fix: lack of support for sort keys
msgui 89b34b3
chore
msgui 43d024a
Merge branch 'master' into edge_queries_optimize
msgui ea6cd18
update pom.xml
msgui 531f389
Update EdgeExistenceTraverser.java
imbajin e08b25e
chore: add summary for edge-existence api
msgui c0e2ea6
tiny improve
imbajin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...ver/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/EdgeExistenceAPI.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * 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.traversers; | ||
|
|
||
| import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_LIMIT; | ||
|
|
||
| import java.util.Iterator; | ||
|
|
||
| import org.apache.hugegraph.HugeGraph; | ||
| import org.apache.hugegraph.backend.id.Id; | ||
| import org.apache.hugegraph.core.GraphManager; | ||
| import org.apache.hugegraph.structure.HugeVertex; | ||
| import org.apache.hugegraph.traversal.algorithm.EdgeExistenceTraverser; | ||
| import org.apache.hugegraph.util.E; | ||
| import org.apache.hugegraph.util.Log; | ||
| import org.apache.tinkerpop.gremlin.structure.Edge; | ||
| import org.slf4j.Logger; | ||
|
|
||
| import com.codahale.metrics.annotation.Timed; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.inject.Singleton; | ||
| import jakarta.ws.rs.DefaultValue; | ||
| import jakarta.ws.rs.GET; | ||
| import jakarta.ws.rs.Path; | ||
| import jakarta.ws.rs.PathParam; | ||
| import jakarta.ws.rs.Produces; | ||
| import jakarta.ws.rs.QueryParam; | ||
| import jakarta.ws.rs.core.Context; | ||
|
|
||
| @Path("graphs/{graph}/traversers/edgeexist") | ||
| @Singleton | ||
| @Tag(name = "EdgeExistenceAPI") | ||
| public class EdgeExistenceAPI extends TraverserAPI { | ||
|
|
||
| private static final Logger LOG = Log.logger(EdgeExistenceAPI.class); | ||
| private static final String DEFAULT_EMPTY = ""; | ||
|
|
||
| @GET | ||
| @Timed | ||
| @Produces(APPLICATION_JSON_WITH_CHARSET) | ||
| @Operation(summary = "get edges from 'source' to 'target' vertex") | ||
| public String get(@Context GraphManager manager, | ||
| @PathParam("graph") String graph, | ||
| @QueryParam("source") String source, | ||
| @QueryParam("target") String target, | ||
| @QueryParam("label") String edgeLabel, | ||
| @QueryParam("sort_values") | ||
| @DefaultValue(DEFAULT_EMPTY) String sortValues, | ||
| @QueryParam("limit") | ||
| @DefaultValue(DEFAULT_LIMIT) long limit) { | ||
| LOG.debug("Graph [{}] get edgeExistence with " + | ||
| "source '{}', target '{}', edgeLabel '{}', sortValue '{}', limit '{}'", | ||
| graph, source, target, edgeLabel, sortValues, limit); | ||
|
|
||
| E.checkArgumentNotNull(source, "The source can't be null"); | ||
| E.checkArgumentNotNull(target, "The target can't be null"); | ||
|
|
||
| Id sourceId = HugeVertex.getIdValue(source); | ||
| Id targetId = HugeVertex.getIdValue(target); | ||
| HugeGraph hugegraph = graph(manager, graph); | ||
| EdgeExistenceTraverser traverser = new EdgeExistenceTraverser(hugegraph); | ||
| Iterator<Edge> edges = traverser.queryEdgeExistence(sourceId, targetId, edgeLabel, | ||
| sortValues, limit); | ||
|
|
||
| return manager.serializer(hugegraph).writeEdges(edges, false); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...h-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * 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.traversal.algorithm; | ||
|
|
||
| import java.util.Iterator; | ||
|
|
||
| import org.apache.hugegraph.HugeGraph; | ||
| import org.apache.hugegraph.backend.id.Id; | ||
| import org.apache.hugegraph.backend.query.ConditionQuery; | ||
| import org.apache.hugegraph.iterator.FilterIterator; | ||
| import org.apache.hugegraph.schema.EdgeLabel; | ||
| import org.apache.hugegraph.type.HugeType; | ||
| import org.apache.hugegraph.type.define.Directions; | ||
| import org.apache.hugegraph.type.define.HugeKeys; | ||
| import org.apache.tinkerpop.gremlin.structure.Edge; | ||
|
|
||
| public class EdgeExistenceTraverser extends HugeTraverser { | ||
|
|
||
| public EdgeExistenceTraverser(HugeGraph graph) { | ||
| super(graph); | ||
| } | ||
|
|
||
| public Iterator<Edge> queryEdgeExistence(Id sourceId, Id targetId, String label, | ||
| String sortValues, long limit) { | ||
| // If no label provided, fallback to a slow query by filtering | ||
| if (label == null || label.isEmpty()) { | ||
| return queryByNeighbors(sourceId, targetId, limit); | ||
| } | ||
|
|
||
| Id edgeLabelId = getEdgeLabelId(label); | ||
| EdgeLabel edgeLabel = graph().edgeLabel(edgeLabelId); | ||
| ConditionQuery conditionQuery = new ConditionQuery(HugeType.EDGE); | ||
| conditionQuery.eq(HugeKeys.OWNER_VERTEX, sourceId); | ||
| conditionQuery.eq(HugeKeys.OTHER_VERTEX, targetId); | ||
| conditionQuery.eq(HugeKeys.LABEL, edgeLabelId); | ||
| conditionQuery.eq(HugeKeys.DIRECTION, Directions.OUT); | ||
| conditionQuery.limit(limit); | ||
|
|
||
| if (edgeLabel.existSortKeys()) { | ||
| conditionQuery.eq(HugeKeys.SORT_VALUES, sortValues); | ||
| } else { | ||
| conditionQuery.eq(HugeKeys.SORT_VALUES, ""); | ||
| } | ||
| return graph().edges(conditionQuery); | ||
| } | ||
|
|
||
| private Iterator<Edge> queryByNeighbors(Id sourceId, Id targetId, long limit) { | ||
| return new FilterIterator<>(edgesOfVertex(sourceId, Directions.OUT, (Id) null, limit), | ||
| edge -> targetId.equals(edge.inVertex().id())); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.