You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by ji...@apache.org on 2023/07/23 02:52:03 UTC
[incubator-hugegraph] branch master updated: fix(api): incorrect use of 'NO_LIMIT' variable (#2253)
This is an automated email from the ASF dual-hosted git repository.
jin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git
The following commit(s) were added to refs/heads/master by this push:
new b02c2bdaa fix(api): incorrect use of 'NO_LIMIT' variable (#2253)
b02c2bdaa is described below
commit b02c2bdaa7c88ee0dd3dd89f8e8beb386c24ed17
Author: DanGuge <77...@users.noreply.github.com>
AuthorDate: Sun Jul 23 10:51:58 2023 +0800
fix(api): incorrect use of 'NO_LIMIT' variable (#2253)
* replace Query.NO_LIMIT with HugeTraverser.NO_LIMIT
---
.../hugegraph/api/traversers/KneighborAPI.java | 36 ++++++++++----------
.../apache/hugegraph/api/traversers/KoutAPI.java | 38 +++++++++++-----------
.../algorithm/records/KneighborRecords.java | 13 ++++----
.../traversal/algorithm/records/KoutRecords.java | 9 ++---
4 files changed, 49 insertions(+), 47 deletions(-)
diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KneighborAPI.java b/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KneighborAPI.java
index 7deb4f29a..4a7c0a951 100644
--- a/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KneighborAPI.java
+++ b/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KneighborAPI.java
@@ -19,34 +19,19 @@ package org.apache.hugegraph.api.traversers;
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_ELEMENTS_LIMIT;
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
+import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-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;
-
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.hugegraph.core.GraphManager;
-import org.slf4j.Logger;
-
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.api.graph.EdgeAPI;
import org.apache.hugegraph.api.graph.VertexAPI;
import org.apache.hugegraph.backend.id.Id;
-import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.core.GraphManager;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.traversal.algorithm.HugeTraverser;
import org.apache.hugegraph.traversal.algorithm.KneighborTraverser;
@@ -55,10 +40,25 @@ import org.apache.hugegraph.traversal.algorithm.steps.EdgeStep;
import org.apache.hugegraph.type.define.Directions;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
import com.codahale.metrics.annotation.Timed;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.inject.Singleton;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.DefaultValue;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
+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/kneighbor")
@Singleton
@Tag(name = "KneighborAPI")
@@ -134,7 +134,7 @@ public class KneighborAPI extends TraverserAPI {
}
long size = results.size();
- if (request.limit != Query.NO_LIMIT && size > request.limit) {
+ if (request.limit != NO_LIMIT && size > request.limit) {
size = request.limit;
}
List<Id> neighbors = request.countOnly ?
diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KoutAPI.java b/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KoutAPI.java
index ca7728141..30282be9d 100644
--- a/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KoutAPI.java
+++ b/hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KoutAPI.java
@@ -20,34 +20,19 @@ package org.apache.hugegraph.api.traversers;
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_ELEMENTS_LIMIT;
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
+import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.inject.Singleton;
-import jakarta.ws.rs.Consumes;
-import jakarta.ws.rs.DefaultValue;
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.POST;
-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;
-
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.hugegraph.core.GraphManager;
-import org.slf4j.Logger;
-
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.api.graph.EdgeAPI;
import org.apache.hugegraph.api.graph.VertexAPI;
import org.apache.hugegraph.backend.id.Id;
-import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.core.GraphManager;
import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.traversal.algorithm.HugeTraverser;
import org.apache.hugegraph.traversal.algorithm.KoutTraverser;
@@ -56,10 +41,25 @@ import org.apache.hugegraph.traversal.algorithm.steps.EdgeStep;
import org.apache.hugegraph.type.define.Directions;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
import com.codahale.metrics.annotation.Timed;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.inject.Singleton;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.DefaultValue;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
+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/kout")
@Singleton
@Tag(name = "KoutAPI")
@@ -77,7 +77,7 @@ public class KoutAPI extends TraverserAPI {
@QueryParam("label") String edgeLabel,
@QueryParam("max_depth") int depth,
@QueryParam("nearest")
- @DefaultValue("true") boolean nearest,
+ @DefaultValue("true") boolean nearest,
@QueryParam("max_degree")
@DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree,
@QueryParam("capacity")
@@ -143,7 +143,7 @@ public class KoutAPI extends TraverserAPI {
}
long size = results.size();
- if (request.limit != Query.NO_LIMIT && size > request.limit) {
+ if (request.limit != NO_LIMIT && size > request.limit) {
size = request.limit;
}
List<Id> neighbors = request.countOnly ?
diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/records/KneighborRecords.java b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/records/KneighborRecords.java
index 1160afe33..7e04a286c 100644
--- a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/records/KneighborRecords.java
+++ b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/records/KneighborRecords.java
@@ -17,17 +17,18 @@
package org.apache.hugegraph.traversal.algorithm.records;
+import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
+
import java.util.List;
import java.util.Stack;
import org.apache.hugegraph.backend.id.Id;
-import org.apache.hugegraph.backend.query.Query;
-import org.apache.hugegraph.type.define.CollectionType;
-import org.apache.hugegraph.util.collection.CollectionFactory;
-import org.apache.hugegraph.util.collection.IntIterator;
import org.apache.hugegraph.traversal.algorithm.HugeTraverser.PathSet;
import org.apache.hugegraph.traversal.algorithm.records.record.Record;
import org.apache.hugegraph.traversal.algorithm.records.record.RecordType;
+import org.apache.hugegraph.type.define.CollectionType;
+import org.apache.hugegraph.util.collection.CollectionFactory;
+import org.apache.hugegraph.util.collection.IntIterator;
public class KneighborRecords extends SingleWayMultiPathsRecords {
@@ -48,7 +49,7 @@ public class KneighborRecords extends SingleWayMultiPathsRecords {
// Not include record(i=0) to ignore source vertex
for (int i = 1; i < records.size(); i++) {
IntIterator iterator = records.get(i).keys();
- while ((limit == Query.NO_LIMIT || limit > 0L) && iterator.hasNext()) {
+ while ((limit == NO_LIMIT || limit > 0L) && iterator.hasNext()) {
ids.add(this.id(iterator.next()));
limit--;
}
@@ -62,7 +63,7 @@ public class KneighborRecords extends SingleWayMultiPathsRecords {
Stack<Record> records = this.records();
for (int i = 1; i < records.size(); i++) {
IntIterator iterator = records.get(i).keys();
- while ((limit == Query.NO_LIMIT || limit > 0L) && iterator.hasNext()) {
+ while ((limit == NO_LIMIT || limit > 0L) && iterator.hasNext()) {
paths.add(this.linkPath(i, iterator.next()));
limit--;
}
diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/records/KoutRecords.java b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/records/KoutRecords.java
index 2ba5e19d4..5953e71e2 100644
--- a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/records/KoutRecords.java
+++ b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/records/KoutRecords.java
@@ -17,17 +17,18 @@
package org.apache.hugegraph.traversal.algorithm.records;
+import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
+
import java.util.List;
import java.util.Stack;
import org.apache.hugegraph.backend.id.Id;
-import org.apache.hugegraph.backend.query.Query;
+import org.apache.hugegraph.traversal.algorithm.HugeTraverser.PathSet;
import org.apache.hugegraph.traversal.algorithm.records.record.Record;
import org.apache.hugegraph.traversal.algorithm.records.record.RecordType;
import org.apache.hugegraph.type.define.CollectionType;
import org.apache.hugegraph.util.collection.CollectionFactory;
import org.apache.hugegraph.util.collection.IntIterator;
-import org.apache.hugegraph.traversal.algorithm.HugeTraverser.PathSet;
public class KoutRecords extends SingleWayMultiPathsRecords {
@@ -44,7 +45,7 @@ public class KoutRecords extends SingleWayMultiPathsRecords {
public List<Id> ids(long limit) {
List<Id> ids = CollectionFactory.newList(CollectionType.EC);
IntIterator iterator = this.records().peek().keys();
- while ((limit == Query.NO_LIMIT || limit-- > 0L) && iterator.hasNext()) {
+ while ((limit == NO_LIMIT || limit-- > 0L) && iterator.hasNext()) {
ids.add(this.id(iterator.next()));
}
return ids;
@@ -55,7 +56,7 @@ public class KoutRecords extends SingleWayMultiPathsRecords {
PathSet paths = new PathSet();
Stack<Record> records = this.records();
IntIterator iterator = records.peek().keys();
- while ((limit == Query.NO_LIMIT || limit-- > 0L) && iterator.hasNext()) {
+ while ((limit == NO_LIMIT || limit-- > 0L) && iterator.hasNext()) {
paths.add(this.linkPath(records.size() - 1, iterator.next()));
}
return paths;