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 2026/10/17 10:08:55 UTC

(hugegraph) branch master updated: test(api): cover ORDER BY on a nullable boolean grouping key (#3367)

This is an automated email from the ASF dual-hosted git repository.

imbajin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hugegraph.git


The following commit(s) were added to refs/heads/master by this push:
     new f5d9885a5 test(api): cover ORDER BY on a nullable boolean grouping key (#3367)
f5d9885a5 is described below

commit f5d9885a575f1b9250e5174afc473303454cd579
Author: Rabari Mihir <mi...@gmail.com>
AuthorDate: Sat Oct 17 15:38:51 2026 +0530

    test(api): cover ORDER BY on a nullable boolean grouping key (#3367)
    
    Grouping by a nullable boolean property produces rows whose key is
    true, false or the translator null marker, and ordering such rows once
    failed with a ClassCastException on TinkerPop 3.5.x because the marker
    compares as a string. With the TinkerPop versions built against now the
    same query orders all three keys with Cypher null semantics (null first
    descending, last ascending). Add an api-test that runs the issue's
    query shape through the Cypher endpoint in both directions.
    
    Co-authored-by: Rabari Mihir <16...@users.noreply.github.com>
---
 .../org/apache/hugegraph/api/CypherApiTest.java    | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/CypherApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/CypherApiTest.java
index cf05c7318..89074ecd0 100644
--- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/CypherApiTest.java
+++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/CypherApiTest.java
@@ -269,6 +269,41 @@ public class CypherApiTest extends BaseApiTest {
         Assert.assertEquals(30.0D, ((Number) row.get("avg")).doubleValue(), 0.0D);
     }
 
+    @Test
+    public void testOrderByNullableBooleanGroupingKey() {
+        // #3319: sorting a Boolean-or-null grouping key once crashed with a
+        // ClassCastException when the translator null marker met ordered values
+        createAndAssert(URL_PREFIX + "/graph/vertices", JsonUtil.toJson(ImmutableMap.of(
+                "label", "cypher_person",
+                "properties", ImmutableMap.of("name", "noactive", "age", 50,
+                                              "city", "Beijing"))));
+        String cypher = "MATCH (n:cypher_person) " +
+                        "OPTIONAL MATCH (n)-[r0:cypher_knows]->(n1 {city: 'Nowhere'}) " +
+                        "WITH n.active AS g, count(n1.name) AS c " +
+                        "RETURN g, c ORDER BY g ";
+        List<?> rows = query(cypher + "DESC");
+        Assert.assertEquals(3, rows.size());
+        assertGroupRow(rows.get(0), null);
+        assertGroupRow(rows.get(1), true);
+        assertGroupRow(rows.get(2), false);
+
+        rows = query(cypher + "ASC");
+        Assert.assertEquals(3, rows.size());
+        assertGroupRow(rows.get(0), false);
+        assertGroupRow(rows.get(1), true);
+        assertGroupRow(rows.get(2), null);
+
+        query("MATCH (n:cypher_person {name: 'noactive'}) DETACH DELETE n");
+        Assert.assertEquals(4, nativeVertices().size());
+    }
+
+    private static void assertGroupRow(Object row, Object groupKey) {
+        Map<?, ?> map = assertMapValue(Collections.singletonList(row), 0);
+        Assert.assertEquals(2, map.size());
+        Assert.assertEquals(groupKey, map.get("g"));
+        Assert.assertEquals(0L, ((Number) map.get("c")).longValue());
+    }
+
     @Test
     public void testParameters() {
         assertColumn(bound("MATCH (n:cypher_person) WHERE n.name = $name AND " +