Skip to content

Commit b02c2bd

Browse files
authored
fix(api): incorrect use of 'NO_LIMIT' variable (#2253)
* replace Query.NO_LIMIT with HugeTraverser.NO_LIMIT
1 parent 7927335 commit b02c2bd

File tree

4 files changed

+49
-47
lines changed

4 files changed

+49
-47
lines changed

hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KneighborAPI.java

+18-18
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,19 @@
1919

2020
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_ELEMENTS_LIMIT;
2121
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
22+
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
2223

2324
import java.util.HashSet;
2425
import java.util.Iterator;
2526
import java.util.List;
2627
import java.util.Set;
2728

28-
import io.swagger.v3.oas.annotations.tags.Tag;
29-
import jakarta.inject.Singleton;
30-
import jakarta.ws.rs.Consumes;
31-
import jakarta.ws.rs.DefaultValue;
32-
import jakarta.ws.rs.GET;
33-
import jakarta.ws.rs.POST;
34-
import jakarta.ws.rs.Path;
35-
import jakarta.ws.rs.PathParam;
36-
import jakarta.ws.rs.Produces;
37-
import jakarta.ws.rs.QueryParam;
38-
import jakarta.ws.rs.core.Context;
39-
40-
import org.apache.tinkerpop.gremlin.structure.Vertex;
41-
import org.apache.hugegraph.core.GraphManager;
42-
import org.slf4j.Logger;
43-
4429
import org.apache.hugegraph.HugeGraph;
4530
import org.apache.hugegraph.api.graph.EdgeAPI;
4631
import org.apache.hugegraph.api.graph.VertexAPI;
4732
import org.apache.hugegraph.backend.id.Id;
48-
import org.apache.hugegraph.backend.query.Query;
4933
import org.apache.hugegraph.backend.query.QueryResults;
34+
import org.apache.hugegraph.core.GraphManager;
5035
import org.apache.hugegraph.structure.HugeVertex;
5136
import org.apache.hugegraph.traversal.algorithm.HugeTraverser;
5237
import org.apache.hugegraph.traversal.algorithm.KneighborTraverser;
@@ -55,10 +40,25 @@
5540
import org.apache.hugegraph.type.define.Directions;
5641
import org.apache.hugegraph.util.E;
5742
import org.apache.hugegraph.util.Log;
43+
import org.apache.tinkerpop.gremlin.structure.Vertex;
44+
import org.slf4j.Logger;
45+
5846
import com.codahale.metrics.annotation.Timed;
5947
import com.fasterxml.jackson.annotation.JsonProperty;
6048
import com.google.common.collect.ImmutableList;
6149

50+
import io.swagger.v3.oas.annotations.tags.Tag;
51+
import jakarta.inject.Singleton;
52+
import jakarta.ws.rs.Consumes;
53+
import jakarta.ws.rs.DefaultValue;
54+
import jakarta.ws.rs.GET;
55+
import jakarta.ws.rs.POST;
56+
import jakarta.ws.rs.Path;
57+
import jakarta.ws.rs.PathParam;
58+
import jakarta.ws.rs.Produces;
59+
import jakarta.ws.rs.QueryParam;
60+
import jakarta.ws.rs.core.Context;
61+
6262
@Path("graphs/{graph}/traversers/kneighbor")
6363
@Singleton
6464
@Tag(name = "KneighborAPI")
@@ -134,7 +134,7 @@ public String post(@Context GraphManager manager,
134134
}
135135

136136
long size = results.size();
137-
if (request.limit != Query.NO_LIMIT && size > request.limit) {
137+
if (request.limit != NO_LIMIT && size > request.limit) {
138138
size = request.limit;
139139
}
140140
List<Id> neighbors = request.countOnly ?

hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KoutAPI.java

+19-19
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,19 @@
2020
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
2121
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_ELEMENTS_LIMIT;
2222
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
23+
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
2324

2425
import java.util.HashSet;
2526
import java.util.Iterator;
2627
import java.util.List;
2728
import java.util.Set;
2829

29-
import io.swagger.v3.oas.annotations.tags.Tag;
30-
import jakarta.inject.Singleton;
31-
import jakarta.ws.rs.Consumes;
32-
import jakarta.ws.rs.DefaultValue;
33-
import jakarta.ws.rs.GET;
34-
import jakarta.ws.rs.POST;
35-
import jakarta.ws.rs.Path;
36-
import jakarta.ws.rs.PathParam;
37-
import jakarta.ws.rs.Produces;
38-
import jakarta.ws.rs.QueryParam;
39-
import jakarta.ws.rs.core.Context;
40-
41-
import org.apache.tinkerpop.gremlin.structure.Vertex;
42-
import org.apache.hugegraph.core.GraphManager;
43-
import org.slf4j.Logger;
44-
4530
import org.apache.hugegraph.HugeGraph;
4631
import org.apache.hugegraph.api.graph.EdgeAPI;
4732
import org.apache.hugegraph.api.graph.VertexAPI;
4833
import org.apache.hugegraph.backend.id.Id;
49-
import org.apache.hugegraph.backend.query.Query;
5034
import org.apache.hugegraph.backend.query.QueryResults;
35+
import org.apache.hugegraph.core.GraphManager;
5136
import org.apache.hugegraph.structure.HugeVertex;
5237
import org.apache.hugegraph.traversal.algorithm.HugeTraverser;
5338
import org.apache.hugegraph.traversal.algorithm.KoutTraverser;
@@ -56,10 +41,25 @@
5641
import org.apache.hugegraph.type.define.Directions;
5742
import org.apache.hugegraph.util.E;
5843
import org.apache.hugegraph.util.Log;
44+
import org.apache.tinkerpop.gremlin.structure.Vertex;
45+
import org.slf4j.Logger;
46+
5947
import com.codahale.metrics.annotation.Timed;
6048
import com.fasterxml.jackson.annotation.JsonProperty;
6149
import com.google.common.collect.ImmutableList;
6250

51+
import io.swagger.v3.oas.annotations.tags.Tag;
52+
import jakarta.inject.Singleton;
53+
import jakarta.ws.rs.Consumes;
54+
import jakarta.ws.rs.DefaultValue;
55+
import jakarta.ws.rs.GET;
56+
import jakarta.ws.rs.POST;
57+
import jakarta.ws.rs.Path;
58+
import jakarta.ws.rs.PathParam;
59+
import jakarta.ws.rs.Produces;
60+
import jakarta.ws.rs.QueryParam;
61+
import jakarta.ws.rs.core.Context;
62+
6363
@Path("graphs/{graph}/traversers/kout")
6464
@Singleton
6565
@Tag(name = "KoutAPI")
@@ -77,7 +77,7 @@ public String get(@Context GraphManager manager,
7777
@QueryParam("label") String edgeLabel,
7878
@QueryParam("max_depth") int depth,
7979
@QueryParam("nearest")
80-
@DefaultValue("true") boolean nearest,
80+
@DefaultValue("true") boolean nearest,
8181
@QueryParam("max_degree")
8282
@DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree,
8383
@QueryParam("capacity")
@@ -143,7 +143,7 @@ public String post(@Context GraphManager manager,
143143
}
144144

145145
long size = results.size();
146-
if (request.limit != Query.NO_LIMIT && size > request.limit) {
146+
if (request.limit != NO_LIMIT && size > request.limit) {
147147
size = request.limit;
148148
}
149149
List<Id> neighbors = request.countOnly ?

hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/records/KneighborRecords.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717

1818
package org.apache.hugegraph.traversal.algorithm.records;
1919

20+
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
21+
2022
import java.util.List;
2123
import java.util.Stack;
2224

2325
import org.apache.hugegraph.backend.id.Id;
24-
import org.apache.hugegraph.backend.query.Query;
25-
import org.apache.hugegraph.type.define.CollectionType;
26-
import org.apache.hugegraph.util.collection.CollectionFactory;
27-
import org.apache.hugegraph.util.collection.IntIterator;
2826
import org.apache.hugegraph.traversal.algorithm.HugeTraverser.PathSet;
2927
import org.apache.hugegraph.traversal.algorithm.records.record.Record;
3028
import org.apache.hugegraph.traversal.algorithm.records.record.RecordType;
29+
import org.apache.hugegraph.type.define.CollectionType;
30+
import org.apache.hugegraph.util.collection.CollectionFactory;
31+
import org.apache.hugegraph.util.collection.IntIterator;
3132

3233
public class KneighborRecords extends SingleWayMultiPathsRecords {
3334

@@ -48,7 +49,7 @@ public List<Id> ids(long limit) {
4849
// Not include record(i=0) to ignore source vertex
4950
for (int i = 1; i < records.size(); i++) {
5051
IntIterator iterator = records.get(i).keys();
51-
while ((limit == Query.NO_LIMIT || limit > 0L) && iterator.hasNext()) {
52+
while ((limit == NO_LIMIT || limit > 0L) && iterator.hasNext()) {
5253
ids.add(this.id(iterator.next()));
5354
limit--;
5455
}
@@ -62,7 +63,7 @@ public PathSet paths(long limit) {
6263
Stack<Record> records = this.records();
6364
for (int i = 1; i < records.size(); i++) {
6465
IntIterator iterator = records.get(i).keys();
65-
while ((limit == Query.NO_LIMIT || limit > 0L) && iterator.hasNext()) {
66+
while ((limit == NO_LIMIT || limit > 0L) && iterator.hasNext()) {
6667
paths.add(this.linkPath(i, iterator.next()));
6768
limit--;
6869
}

hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/records/KoutRecords.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717

1818
package org.apache.hugegraph.traversal.algorithm.records;
1919

20+
import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
21+
2022
import java.util.List;
2123
import java.util.Stack;
2224

2325
import org.apache.hugegraph.backend.id.Id;
24-
import org.apache.hugegraph.backend.query.Query;
26+
import org.apache.hugegraph.traversal.algorithm.HugeTraverser.PathSet;
2527
import org.apache.hugegraph.traversal.algorithm.records.record.Record;
2628
import org.apache.hugegraph.traversal.algorithm.records.record.RecordType;
2729
import org.apache.hugegraph.type.define.CollectionType;
2830
import org.apache.hugegraph.util.collection.CollectionFactory;
2931
import org.apache.hugegraph.util.collection.IntIterator;
30-
import org.apache.hugegraph.traversal.algorithm.HugeTraverser.PathSet;
3132

3233
public class KoutRecords extends SingleWayMultiPathsRecords {
3334

@@ -44,7 +45,7 @@ public int size() {
4445
public List<Id> ids(long limit) {
4546
List<Id> ids = CollectionFactory.newList(CollectionType.EC);
4647
IntIterator iterator = this.records().peek().keys();
47-
while ((limit == Query.NO_LIMIT || limit-- > 0L) && iterator.hasNext()) {
48+
while ((limit == NO_LIMIT || limit-- > 0L) && iterator.hasNext()) {
4849
ids.add(this.id(iterator.next()));
4950
}
5051
return ids;
@@ -55,7 +56,7 @@ public PathSet paths(long limit) {
5556
PathSet paths = new PathSet();
5657
Stack<Record> records = this.records();
5758
IntIterator iterator = records.peek().keys();
58-
while ((limit == Query.NO_LIMIT || limit-- > 0L) && iterator.hasNext()) {
59+
while ((limit == NO_LIMIT || limit-- > 0L) && iterator.hasNext()) {
5960
paths.add(this.linkPath(records.size() - 1, iterator.next()));
6061
}
6162
return paths;

0 commit comments

Comments
 (0)