Skip to content

[ESQL] SUM(null) optimized incorrectly #144914

@jan-elastic

Description

@jan-elastic

Elasticsearch Version

main

Installed Plugins

No response

Java Version

bundled

OS Version

all

Problem Description

The query

ROW x=1 | STATS s=SUM(null) | EVAL s+1

results in a verification exception

line 1:11: Output has changed from [[s{r}#17, s+1{r}#19]] to [[s{r}#17, s+1{r}#19]]. """

I've poked around a bit. Some observations:

  • even though both outputs look the same, the type of s+1 of the left is DOUBLE, and on the right it's LONG
  • I think it has to do with the surrogate of Sum(foldable) -> MvSum(foldable) * Count(*), together with some optimizer rules that process nulls (FoldNull, PropagateEvalFoldables)

Steps to Reproduce

execute query

Logs (if relevant)

No response

Metadata

Metadata

Assignees

Labels

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