From 121953e41c239e7c2633ea3dcbecf755c835892b Mon Sep 17 00:00:00 2001 From: imbajin Date: Sun, 8 Nov 2026 13:12:18 +0800 Subject: [PATCH 1/2] fix(core): respect distinct customized crosspoint limits --- .../traversal/algorithm/CustomizedCrosspointsTraverser.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CustomizedCrosspointsTraverser.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CustomizedCrosspointsTraverser.java index 4c0ede0806..33126cecfd 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CustomizedCrosspointsTraverser.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CustomizedCrosspointsTraverser.java @@ -19,6 +19,7 @@ import java.util.Collection; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -71,7 +72,7 @@ private static CrosspointsPaths intersectionPaths(List sources, Collection intersection = null; for (List ends : endVertices.values()) { if (intersection == null) { - intersection = ends; + intersection = new LinkedHashSet<>(ends); } else { intersection = CollectionUtil.intersect(intersection, ends); } @@ -83,7 +84,8 @@ private static CrosspointsPaths intersectionPaths(List sources, // Limit intersection number to limit crosspoints vertices in result int size = intersection.size(); if (limit != NO_LIMIT && size > limit) { - intersection = newList(intersection).subList(0, size - 1); + intersection = new LinkedHashSet<>( + newList(intersection).subList(0, (int) limit)); } // Filter intersection paths From 8e7a271ed01758925964d70b0e48b5c01a707a92 Mon Sep 17 00:00:00 2001 From: imbajin Date: Sun, 8 Nov 2026 13:12:21 +0800 Subject: [PATCH 2/2] test(api): cover customized crosspoint limits --- .../CustomizedCrosspointsApiTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/CustomizedCrosspointsApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/CustomizedCrosspointsApiTest.java index 0762008803..a919dcf41e 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/CustomizedCrosspointsApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/CustomizedCrosspointsApiTest.java @@ -62,4 +62,26 @@ public void testPost() { List paths = assertJsonContains(content, "paths"); Assert.assertEquals(2, paths.size()); } + + @Test + public void testLimitCountsDistinctCrosspoints() { + String markoId = listAllVertexName2Ids().get("marko"); + int[] limits = {1, 2, 3, -1}; + int[] expected = {1, 2, 2, 2}; + for (int i = 0; i < limits.length; i++) { + String reqBody = String.format( + "{\"sources\":{\"ids\":[\"%s\"]}," + + "\"path_patterns\":[" + + "{\"steps\":[{\"direction\":\"BOTH\",\"labels\":[],\"degree\":-1}]}," + + "{\"steps\":[{\"direction\":\"BOTH\",\"labels\":[],\"degree\":-1}]}]," + + "\"with_path\":true,\"capacity\":-1,\"limit\":%d}", + markoId, limits[i]); + Response response = client().post(path, reqBody); + String content = assertResponseStatus(200, response); + List crosspoints = assertJsonContains(content, "crosspoints"); + List paths = assertJsonContains(content, "paths"); + Assert.assertEquals(expected[i], crosspoints.size()); + Assert.assertEquals(expected[i] * 2, paths.size()); + } + } }