Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
tiny improve

chore: keep Iterator type

chore

chore

tiny improve

tiny changes

tiny changes

update version
  • Loading branch information
msgui committed Nov 28, 2023
1 parent 7a2a61a commit 89b34b3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 41 deletions.
2 changes: 1 addition & 1 deletion hugegraph-server/hugegraph-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
</manifest>
<manifestEntries>
<!-- TODO: update it -->
<Implementation-Version>0.69.0.0</Implementation-Version>
<Implementation-Version>0.70.0.0</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
/*
* 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 com.codahale.metrics.annotation.Timed;
import com.google.common.collect.Lists;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.inject.Singleton;
import jakarta.ws.rs.*;
Expand All @@ -19,9 +35,8 @@
import org.slf4j.Logger;

import java.util.Iterator;
import java.util.List;

@Path("graphs/{graph}/traversers/edgeexistence")
@Path("graphs/{graph}/traversers/edgeexist")
@Singleton
@Tag(name = "EdgeExistenceAPI")
public class EdgeExistenceAPI extends TraverserAPI {

Check warning on line 42 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/EdgeExistenceAPI.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/EdgeExistenceAPI.java#L42

Added line #L42 was not covered by tests
Expand All @@ -36,26 +51,24 @@ public String get(@Context GraphManager manager,
@PathParam("graph") String graph,
@QueryParam("source") String source,
@QueryParam("target") String target,
@QueryParam("edgelabel") String edgeLabel,
@QueryParam("sortValues")
@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 " +

Check warning on line 59 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/EdgeExistenceAPI.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/EdgeExistenceAPI.java#L59

Added line #L59 was not covered by tests
"source '{}', target '{}', edgeLabel '{}', sortValue '{}'and limit '{}'",
graph, source, target, edgeLabel, sortValues, limit);
"source '{}', target '{}', edgeLabel '{}', sortValue '{}', limit '{}'",
graph, source, target, edgeLabel, sortValues, limit);

Check warning on line 61 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/EdgeExistenceAPI.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/EdgeExistenceAPI.java#L61

Added line #L61 was not covered by tests

E.checkArgumentNotNull(source, "The source can't be null");
E.checkArgumentNotNull(target, "The target can't be null");

Check warning on line 64 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/EdgeExistenceAPI.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/EdgeExistenceAPI.java#L63-L64

Added lines #L63 - L64 were not covered by tests

Id sourceId = HugeVertex.getIdValue(source);
Id targetId = HugeVertex.getIdValue(target);
HugeGraph hugeGraph = graph(manager, graph);
EdgeExistenceTraverser traverser = new EdgeExistenceTraverser(hugeGraph);

HugeGraph hugegraph = graph(manager, graph);
EdgeExistenceTraverser traverser = new EdgeExistenceTraverser(hugegraph);
Iterator<Edge> edges = traverser.queryEdgeExistence(sourceId, targetId, edgeLabel, sortValues, limit);

Check warning on line 70 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/EdgeExistenceAPI.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/EdgeExistenceAPI.java#L66-L70

Added lines #L66 - L70 were not covered by tests

List<Edge> all = Lists.newArrayList(edges);
return manager.serializer(hugeGraph).writeList("edges", all);
return manager.serializer(hugegraph).writeEdges(edges, false);

Check warning on line 72 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/EdgeExistenceAPI.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/EdgeExistenceAPI.java#L72

Added line #L72 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ public final class ApiVersion {
* [0.67] Issue-1065: Support dynamically add/remove graph
* [0.68] Issue-1763: Support adamic-adar & resource-allocation API
* [0.69] Issue-1748: Support Cypher query RESTful API
* [0.70] Issue-2242: Add edge-existence RESTful API
*/

/**
* The second parameter of Version.of() is for IDE running without JAR
*/
public static final Version VERSION = Version.of(ApiVersion.class, "0.69");
public static final Version VERSION = Version.of(ApiVersion.class, "0.70");

public static void check() {
// Check version of hugegraph-core. Firstly do check from version 0.3
Expand Down
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

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L35-L36

Added lines #L35 - L36 were not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L42

Added line #L42 was not covered by tests
}
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

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L44-L51

Added lines #L44 - L51 were not covered by tests
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

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L53

Added line #L53 was not covered by tests
} 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

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L55

Added line #L55 was not covered by tests
}
return graph().edges(conditionQuery);

Check warning on line 57 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L57

Added line #L57 was not covered by tests
}

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

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/EdgeExistenceTraverser.java#L61-L62

Added lines #L61 - L62 were not covered by tests
}
}

0 comments on commit 89b34b3

Please sign in to comment.