Skip to content

sum(...) may mishandle null inputs. #2385

@Silence6666668

Description

@Silence6666668

Describe the bug
sum(...) may mishandle null inputs.

In Apache AGE, sum(null) returns null instead of 0, and sum(x) over a list containing both numbers and null may fail with:

arguments must resolve to a number

On both Neo4j and Memgraph, sum ignores null inputs and returns a numeric result.

How are you accessing AGE (Command line, driver, etc.)?

  • PostgreSQL cypher(...) wrapper through the local Python differential-testing harness
  • Reproducible directly in psql inside the Docker container

What data setup do we need to do?
No graph data is required beyond creating an empty graph:

SELECT create_graph('fuzz_graph');

What is the necessary configuration info needed?

  • Plain Apache AGE Docker image was enough
  • Docker image in local repro: apache/age
  • AGE extension version: 1.7.0
  • PostgreSQL version: 18.1
  • Graph name used in repro: fuzz_graph
  • No extra extensions or special configuration were required

What is the command that caused the error?

SELECT * FROM cypher('fuzz_graph', $$
  RETURN sum(null) AS v
$$) AS (v agtype);

Returned result on AGE:

null

Expected behavior
The result should be:

0

Neo4j returns 0, and Memgraph also returns 0.

Environment (please complete the following information):

  • Version: Apache AGE 1.7.0
  • PostgreSQL: 18.1
  • Host OS: Windows
  • Architecture: x86_64
  • Deployment: Docker

Additional context
A second variant shows the same issue more strongly:

SELECT * FROM cypher('fuzz_graph', $$
  UNWIND [1,null,2] AS x
  RETURN sum(x) AS v
$$) AS (v agtype);

Apache AGE returns:

ERROR: arguments must resolve to a number

Expected result:

3

Neo4j returns 3, and Memgraph also returns 3.

Other nearby control cases behave as expected on the same AGE instance:

  1. Summing a non-null number works:
SELECT * FROM cypher('fuzz_graph', $$
  RETURN sum(1) AS v
$$) AS (v agtype);

Observed result:

1
  1. avg(null) still returns null, which is expected:
SELECT * FROM cypher('fuzz_graph', $$
  RETURN avg(null) AS v
$$) AS (v agtype);

Observed result:

null
  1. Even the single-null UNWIND case differs from Neo4j and Memgraph:
SELECT * FROM cypher('fuzz_graph', $$
  UNWIND [null] AS x
  RETURN sum(x) AS v
$$) AS (v agtype);

Apache AGE returns:

null

while Neo4j and Memgraph both return:

0

So the issue appears to be specifically in how Apache AGE's sum aggregate handles null-valued inputs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions