-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
tiny improve chore: keep Iterator type chore chore tiny improve tiny changes tiny changes update version
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,64 @@ | ||
/* | ||
* 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 com.google.common.collect.ImmutableList; | ||
import org.apache.hugegraph.HugeGraph; | ||
import org.apache.hugegraph.auth.HugeTarget; | ||
import org.apache.hugegraph.auth.HugeUser; | ||
import org.apache.hugegraph.backend.id.Id; | ||
import org.apache.hugegraph.backend.query.ConditionQuery; | ||
import org.apache.hugegraph.backend.query.IdQuery; | ||
import org.apache.hugegraph.backend.query.Query; | ||
import org.apache.hugegraph.iterator.FilterIterator; | ||
import org.apache.hugegraph.schema.EdgeLabel; | ||
import org.apache.hugegraph.schema.PropertyKey; | ||
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; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
public class EdgeExistenceTraverser extends HugeTraverser { | ||
|
||
public EdgeExistenceTraverser(HugeGraph graph) { | ||
super(graph); | ||
} | ||
Check warning on line 36 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java Codecov / codecov/patchhugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L35-L36
|
||
|
||
public Iterator<Edge> queryEdgeExistence(Id sourceId, Id targetId, String label, | ||
String sortValues, long limit) { | ||
// If no label provided, fallback to slow query by filtering | ||
if (label == null || label.isEmpty()) { | ||
return queryByNeighbor(sourceId, targetId, limit); | ||
return queryByNeighbors(sourceId, targetId, limit); | ||
Check warning on line 42 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java Codecov / codecov/patchhugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L42
|
||
} | ||
Id edgeLabelId = getEdgeLabelId(label); | ||
EdgeLabel edgeLabel = EdgeLabel.undefined(graph(), edgeLabelId); | ||
List<Id> sortKeys = edgeLabel.sortKeys(); | ||
|
||
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.eq(HugeKeys.SORT_VALUES, sortValues); | ||
conditionQuery.limit(limit); | ||
Check warning on line 51 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java Codecov / codecov/patchhugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L44-L51
|
||
if (sortKeys != null) { | ||
List<String> names = graph().mapPkId2Name(sortKeys); | ||
conditionQuery.key(HugeKeys.SORT_KEYS, names); | ||
if (edgeLabel.existSortKeys()) { | ||
conditionQuery.eq(HugeKeys.SORT_VALUES, sortValues); | ||
Check warning on line 53 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java Codecov / codecov/patchhugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L53
|
||
} else { | ||
conditionQuery.eq(HugeKeys.SORT_VALUES, ""); | ||
Check warning on line 55 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java Codecov / codecov/patchhugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L55
|
||
} | ||
return graph().edges(conditionQuery); | ||
Check warning on line 57 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java Codecov / codecov/patchhugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L57
|
||
} | ||
|
||
private Iterator<Edge> queryByNeighbor(Id sourceId, Id targetId, long limit) { | ||
Iterator<Edge> edges = this.edgesOfVertex(sourceId, Directions.OUT, (Id) null, limit); | ||
List<Edge> res = new ArrayList<>(); | ||
String target = targetId.toString(); | ||
while (edges.hasNext()) { | ||
Edge edge = edges.next(); | ||
String outVertexId = edge.inVertex().id().toString(); | ||
if (!target.equals(outVertexId)) continue; | ||
res.add(edge); | ||
} | ||
return res.iterator(); | ||
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())); | ||
Check warning on line 62 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java Codecov / codecov/patchhugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L61-L62
|
||
} | ||
} |