Skip to content

[Bug] groupCount().by(missingProperty) creates an unserializable null map key #3446

Open

Description

@choeoe

Bug Type (问题类型)

other exception / error (其他异常报错)

Before submit

  • 我已经确认现有的 Issues 与 FAQ 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)

Environment (环境信息)

  • Server Version: Apache HugeGraph 1.7.0
  • Gremlin Version: 3.5.1
  • Backend: memory
  • Data Size: 1 vertex and 0 edges

Expected & Actual behavior (期望与实际表现)

Create a vertex without property d1, then execute a grouping traversal
through the Gremlin REST endpoint:

g.V('v1').groupCount().by('d1')

Expected: the endpoint should return a valid traversal result or a stable
validation error explaining that the grouping property is absent.

Actual: response serialization fails with:

org.apache.hugegraph.HugeException: Can't write json: Null key for a Map not allowed in JSON

The error identifies a HashMap["null"] in the response value. The server
therefore constructs an intermediate result that its REST serializer cannot
encode.

Vertex/Edge example (问题点 / 边数据举例)

Setup and failing traversal:


schema.vertexLabel('DocVertex').useCustomizeStringId().ifNotExist().create()
g.addV('DocVertex').property(T.id, 'v1').iterate()
g.V('v1').groupCount().by('d1')


The vertex is equivalent to:


{
  "id": "v1",
  "label": "DocVertex",
  "properties": {}
}

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

{
  "vertex_label": {
    "name": "DocVertex",
    "id_strategy": "CUSTOMIZE_STRING",
    "properties": []
  },
  "edge_labels": [],
  "index_labels": []
}


Reference behavior:

https://hugegraph.apache.org/docs/clients/restful-api/gremlin/

https://tinkerpop.apache.org/docs/3.5.1/reference/#groupcount-step

Activity

  1. dosubot commented on Nov 1, 2026

    @dosubot

    A workaround to try is to give missing values an explicit, non-null bucket:

    g.V('v1').groupCount().by(
        __.coalesce(__.values('d1'), __.constant('__missing__'))
    )

    TinkerPop 3.5.1 documents that coalesce() selects the first child traversal that emits a value, and groupCount().by(...) uses that projection as the grouping key. For your example, this should produce {"__missing__":1} rather than a null-keyed map. Choose a sentinel that cannot collide with real property values. I haven't executed this against 1.7.0. [1]

    The exception text also pinpoints the serialization boundary: HugeGraph's JsonUtil.toJson() calls Jackson's writeValueAsString() and wraps serialization failures as HugeException("Can't write json: ..."). This supports your distinction between constructing the traversal result and failing to encode it, though it does not establish where the null grouping key originates. [2]

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about hugegraph Share Dosu with your team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions