opensearch-project / opensearch-project/sql
[BUG] Sum multiple `null` values should return `null` instead of `0`
Open
@LantaoJin is already working on this.
Since Jun 27, 2025.
breaking
bug
calcite
dependencies
- Dominant language
- Java
- Stars
- 176
- Forks
- 229
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 43
Description
What is the bug?
In most databases. Below query will return null
CREATE TABLE employees (
emp_id INT PRIMARY KEY,
name VARCHAR(50),
department VARCHAR(50),
salary INT
);
INSERT INTO employees VALUES
(1, 'John', 'IT', 60000),
(2, 'Alice', 'IT', 55000),
(3, 'Bob', 'IT', null),
(4, 'Sarah', 'HR', 52000),
(5, 'Mike', 'HR', 48000),
(6, 'Lisa', 'Sales', null),
(7, 'Tom', 'Sales', null);
select sum(salary) from employees where department = 'Sales';
Return
+-------------+
| sum(salary) |
+-------------+
| NULL |
+-------------+
But in PPL v2, it return 0. For example
@Test
public void testSumNull() {
String response =
execute(
String.format(
"source=%s | where department = 'Sales' | stats sum(salary)",
TEST_INDEX_BANK_WITH_NULL_VALUES));
assertEquals(
""
+ "{\n"
+ " \"schema\": [\n"
+ " {\n"
+ " \"name\": \"sum(salary)\",\n"
+ " \"type\": \"long\"\n"
+ " }\n"
+ " ],\n"
+ " \"datarows\": [\n"
+ " [\n"
+ " 0\n"
+ " ]\n"
+ " ],\n"
+ " \"total\": 1,\n"
+ " \"size\": 1\n"
+ "}",
response);
}
Current the v3 (Calcite) will return null as well. Should we change this behaviour align with other databases?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.