Skip to content

[ESQL] Sum aggregation returns a 500 status code for overflow #110437

@not-napoleon

Description

@not-napoleon

Elasticsearch Version

main

Installed Plugins

No response

Java Version

bundled

OS Version

na

Problem Description

When scalar addition encounters an integer overflow, it sets the value to null and adds a warning. When the SUM aggregation encounters an integer overflow, it crashes the query and returns a 500. This is also the root cause of #99575, as the AVG surrogates to SUM and COUNT.

Steps to Reproduce

Create an index with a long field and to documents with MAX_LONG as their value:

PUT http://localhost:9200/test
content-type: application/json

{
  "mappings": {
    "properties": {
      "l": {
        "type": "long" 
      }
    }
  }
}

PUT http://localhost:9200/test/_doc/1
content-type: application/json

{ "l": "9223372036854775807"}

PUT http://localhost:9200/test/_doc/2
content-type: application/json

{ "l": "9223372036854775807"}

Attempt to aggregate the sum of those documents

POST http://localhost:9200/_query?format=txt
content-type: application/json

{
  "query": "FROM test | STATS SUM(l)"
}

Expected Response:

SUM(l)       
-------------------
null

Actual Response:

{
  "error": {
    "root_cause": [
      {
        "type": "arithmetic_exception",
        "reason": "long overflow"
      }
    ],
    "type": "arithmetic_exception",
    "reason": "long overflow"
  },
  "status": 500
}

Logs (if relevant)

No response

Metadata

Metadata

Assignees

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